-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIComboBox.cpp
More file actions
890 lines (681 loc) · 27.4 KB
/
GUIComboBox.cpp
File metadata and controls
890 lines (681 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
//////////////////////////////////////////////////////////////////////////////////////////
// File: GUIComboBox.cpp
//////////////////////////////////////////////////////////////////////////////////////////
// Description: GUIComboBox class
// Project: GUI Library
// Author(s): Jason Boettcher
// jackal@shplorb.com
// www.shplorb.com/~jackal
//////////////////////////////////////////////////////////////////////////////////////////
// Inclusions of header files
#include "GUI.h"
#include "GUIComboBox.h"
using namespace RTE;
//////////////////////////////////////////////////////////////////////////////////////////
// Constructor: GUIComboBox
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Constructor method used to instantiate a GUIComboBox object in
// system memory.
GUIComboBox::GUIComboBox(GUIManager *Manager, GUIControlManager *ControlManager)
: GUIPanel(Manager),
GUIControl()
{
m_ControlID = "COMBOBOX";
m_ControlManager = ControlManager;
m_DrawBitmap = 0;
m_OldSelection = 0;
m_CreatedList = false;
m_DropHeight = 80;
m_DropDownStyle = DropDownList;
// Create the listpanel
m_ListPanel = new GUIListPanel(Manager);
// Create the textpanel
m_TextPanel = new GUITextPanel(Manager);
// Create the button
m_Button = new GUIComboBoxButton(Manager);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Create
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been created.
void GUIComboBox::Create(const std::string Name, int X, int Y, int Width, int Height)
{
GUIControl::Create(Name, X, Y, Width, Height);
// Minimum size of the control
m_MinWidth = 30;
m_MinHeight = 10;
// Default size of the control
m_DefWidth = 60;
m_DefHeight = 20;
// Setup the panel
m_X = X;
m_Y = Y;
m_Width = m_DefWidth;
m_Height = m_DefHeight;
if (Width != -1)
m_Width = Width;
if (Height != -1)
m_Height = Height;
// Make sure the textbox isn't too small
m_Width = std::max(m_Width, m_MinWidth);
m_Height = std::max(m_Height, m_MinHeight);
m_TextPanel->Create(0, 0, m_Width-12, m_Height);
m_TextPanel->_SetVisible(true);
m_TextPanel->SetLocked((m_DropDownStyle == DropDownList));
m_TextPanel->SetSignalTarget(this);
GUIPanel::AddChild(m_TextPanel);
// Create the listpanel
m_ListPanel->_SetVisible(false);
m_ListPanel->SetSignalTarget(this);
m_ListPanel->SetMultiSelect(false);
m_ListPanel->SetHotTracking(true);
m_ListPanel->EnableScrollbars(false, true);
// Create the button
m_Button->Create(m_Width-17, 0, 17, m_Height);
m_Button->SetSignalTarget(this);
GUIPanel::AddChild(m_Button);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Create
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been created.
void GUIComboBox::Create(GUIProperties *Props)
{
GUIControl::Create(Props);
// Minimum size of the control
m_MinWidth = 30;
m_MinHeight = 10;
// Default size of the control
m_DefWidth = 60;
m_DefHeight = 20;
GUIPanel::LoadProperties(Props);
// Make sure the textbox isn't too small
m_Width = std::max(m_Width, m_MinWidth);
m_Height = std::max(m_Height, m_MinHeight);
m_TextPanel->Create(0, 0, m_Width-12, m_Height);
m_TextPanel->_SetVisible(true);
m_TextPanel->SetSignalTarget(this);
GUIPanel::AddChild(m_TextPanel);
// Create the listpanel
m_ListPanel->_SetVisible(false);
m_ListPanel->SetSignalTarget(this);
m_ListPanel->SetMultiSelect(false);
m_ListPanel->SetHotTracking(true);
m_ListPanel->EnableScrollbars(false, true);
m_ListPanel->SetMouseScrolling(true);
// Create the button
m_Button->Create(m_Width-17, 0, 17, m_Height);
m_Button->SetSignalTarget(this);
GUIPanel::AddChild(m_Button);
// Load the info
Props->GetValue("Dropheight", &m_DropHeight);
m_DropHeight = std::max(m_DropHeight, 20);
string Val;
Props->GetValue("DropDownStyle", &Val);
if (stricmp(Val.c_str(), "DropDownList") == 0)
m_DropDownStyle = DropDownList;
else if (stricmp(Val.c_str(), "DropDown") == 0)
m_DropDownStyle = DropDown;
m_TextPanel->SetLocked((m_DropDownStyle == DropDownList));
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Destroy
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been destroyed.
void GUIComboBox::Destroy(void)
{
// Free the panels
if (m_ListPanel) {
m_ListPanel->Destroy();
delete m_ListPanel;
m_ListPanel = 0;
}
if (m_TextPanel) {
delete m_TextPanel;
m_TextPanel = 0;
}
if (m_Button) {
m_Button->Destroy();
delete m_Button;
m_Button = 0;
}
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = 0;
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Activate
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control is activated and ready for use.
void GUIComboBox::Activate(void)
{
m_TextPanel->SetPositionAbs(m_X, m_Y);
if (!m_ListPanel->GetParentPanel() && m_Parent) {
m_Parent->AddChild(m_ListPanel);
m_ListPanel->Create(m_X, m_Y+m_Height, m_Width, m_DropHeight);
m_ListPanel->ChangeSkin(m_Skin);
m_CreatedList = true;
m_Button->Create(m_X+m_Width-17, m_Y, 17, m_Height);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ChangeSkin
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the skin has been changed.
void GUIComboBox::ChangeSkin(GUISkin *Skin)
{
GUIControl::ChangeSkin(Skin);
// Free any old bitmap
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = 0;
}
// Create a new bitmap
m_DrawBitmap = m_Skin->CreateBitmap(m_Width, m_Height);
// Build the background
m_Skin->BuildStandardRect(m_DrawBitmap, "TextBox", 0, 0, m_Width, m_Height);
// Setup the skin in the panels too
m_TextPanel->ChangeSkin(Skin);
if (m_CreatedList)
m_ListPanel->ChangeSkin(Skin);
m_Button->ChangeSkin(Skin);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Draw
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Draws the panel
void GUIComboBox::Draw(GUIScreen *Screen)
{
// Draw the background
m_DrawBitmap->Draw(Screen->GetBitmap(), m_X, m_Y, 0);
// KLUDGE
// If selected item has a bitmap AND no text to show, just show the bitmap as the selected thing
if (m_ListPanel->GetSelected() && m_ListPanel->GetSelected()->m_Name.empty() && m_ListPanel->GetSelected()->m_pBitmap)
m_ListPanel->GetSelected()->m_pBitmap->DrawTrans(Screen->GetBitmap(), m_X + 4, m_Y + 4, 0);
GUIPanel::Draw(Screen);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetPanel
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Returns the panel of the control.
GUIPanel *GUIComboBox::GetPanel(void)
{
return this;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ReceiveSignal
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when receiving a signal.
void GUIComboBox::ReceiveSignal(GUIPanel* Source, int Code, int Data)
{
assert(Source);
int sourcePanelID = Source->GetPanelID();
// ComboBoxButton
if (sourcePanelID == m_Button->GetPanelID())
{
// Clicked and list panel is not visible. open the list panel.
if (Code == GUIComboBoxButton::Clicked && !m_ListPanel->_GetVisible()) {
m_ListPanel->_SetVisible(true);
m_ListPanel->SetFocus();
m_ListPanel->CaptureMouse();
// Force a redraw
m_ListPanel->EndUpdate();
// Make this panel go above the rest
m_ListPanel->ChangeZPosition(TopMost);
// Save the current selection
if (m_ListPanel->GetSelectedIndex() >= 0 && m_ListPanel->GetSelectedIndex() < m_ListPanel->GetItemList()->size())
m_OldSelection = m_ListPanel->GetSelectedIndex();
AddEvent(GUIEvent::Notification, Dropped, 0);
}
}
// Textbox
else if (sourcePanelID == m_TextPanel->GetPanelID()) {
// MouseDown
if (Code == GUITextPanel::MouseDown && m_DropDownStyle == DropDownList && Data & MOUSE_LEFT) {
// Drop
m_ListPanel->_SetVisible(true);
m_ListPanel->SetFocus();
m_ListPanel->CaptureMouse();
// Force a redraw
m_ListPanel->EndUpdate();
// Make this panel go above the rest
m_ListPanel->ChangeZPosition(TopMost);
// Save the current selection
if (m_ListPanel->GetSelectedIndex() >= 0 && m_ListPanel->GetSelectedIndex() < m_ListPanel->GetItemList()->size())
m_OldSelection = m_ListPanel->GetSelectedIndex();
AddEvent(GUIEvent::Notification, Dropped, 0);
}
}
// ListPanel
else if (sourcePanelID == m_ListPanel->GetPanelID()) {
// MouseMove
if (Code == GUIListPanel::MouseMove)// || Code == GUIListPanel::MouseUp)
{
m_Button->SetPushed(false);
return;
}
int mouseX = 0;
int mouseY = 0;
m_Manager->GetInputController()->GetMousePosition(&mouseX, &mouseY);
// Mouse down anywhere outside the list panel.
if (Code == GUIListPanel::Click)
{
// Hide the list panel
m_ListPanel->_SetVisible(false);
m_ListPanel->ReleaseMouse();
m_Manager->SetFocus(0);
m_Button->SetPushed(false);
// Restore the old selection
m_ListPanel->SetSelectedIndex(m_OldSelection);
AddEvent(GUIEvent::Notification, Closed, 0);
}
// Select on mouseup instead of down so we don't accidentally click stuff behind the disappearing listbox immediately after
// Also only work if inside the actual list, and not its scrollbars
else if (Code == GUIListPanel::MouseUp && m_ListPanel->PointInsideList(mouseX, mouseY)) {
// Hide the list panel
m_ListPanel->_SetVisible(false);
m_ListPanel->ReleaseMouse();
m_Manager->SetFocus(0);
m_Button->SetPushed(false);
AddEvent(GUIEvent::Notification, Closed, 0);
// Set the text to the item in the list panel
GUIListPanel::Item* Item = m_ListPanel->GetSelected();
if (Item)
{
m_TextPanel->SetText(Item->m_Name);
// Save the current selection - NO, don't, we want to keep this so we can still roll back to previous selection later
// m_OldSelection = m_ListPanel->GetSelectedIndex();
}
else
{
// Restore the old selection
m_ListPanel->SetSelectedIndex(m_OldSelection);
}
}
if (m_DropDownStyle == DropDownList) {
// Set the text to the item in the list panel
GUIListPanel::Item* Item = m_ListPanel->GetSelected();
if (Item)
m_TextPanel->SetText(Item->m_Name);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: BeginUpdate
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Locks the control from updating every time a new item is added.
void GUIComboBox::BeginUpdate(void)
{
m_ListPanel->BeginUpdate();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: EndUpdate
//////////////////////////////////////////////////////////////////////////////////////////
// Description: UnLocks the control from updating every time a new item is added.
// Will automatically update the control.
void GUIComboBox::EndUpdate(void)
{
m_ListPanel->EndUpdate();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: AddItem
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Add an item to the list.
void GUIComboBox::AddItem(string Name, string ExtraText, GUIBitmap *pBitmap, const Entity *pEntity)
{
m_ListPanel->AddItem(Name, ExtraText, pBitmap, pEntity);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ClearList
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Clears the liost.
void GUIComboBox::ClearList(void)
{
m_TextPanel->SetText("");
m_ListPanel->ClearList();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Move
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control needs to be moved.
void GUIComboBox::Move(int X, int Y)
{
GUIPanel::SetPositionAbs(X, Y);
m_ListPanel->SetPositionAbs(m_X, m_Y+m_Height);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Resize
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control needs to be resized.
void GUIComboBox::Resize(int Width, int Height)
{
// Make sure the textbox isn't too small
Width = std::max(Width, m_MinWidth);
Height = std::max(Height, m_MinHeight);
Height = std::min(Height, 20);
GUIPanel::SetSize(Width, Height);
m_TextPanel->SetSize(m_Width-12, m_Height);
m_TextPanel->SetPositionAbs(m_X, m_Y);
m_Button->SetPositionAbs(m_X+m_Width-13, m_Y+1);
m_Button->SetSize(12, m_Height-2);
m_ListPanel->SetSize(m_Width, m_DropHeight);
m_ListPanel->SetPositionAbs(m_X, m_Y+m_Height);
// Force a bitmap rebuild
ChangeSkin(m_Skin);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetControlRect
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the rectangle of the control.
void GUIComboBox::GetControlRect(int *X, int *Y, int *Width, int *Height)
{
GUIPanel::GetRect(X, Y, Width, Height);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: DeleteItem
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Delete an item from the list.
void GUIComboBox::DeleteItem(int Index)
{
m_ListPanel->DeleteItem(Index);
// Update the selection
GUIListPanel::Item *Item = m_ListPanel->GetSelected();
if (!Item) {
m_ListPanel->SetSelectedIndex(0);
Item = m_ListPanel->GetSelected();
}
if (Item)
m_TextPanel->SetText(Item->m_Name);
else
m_TextPanel->SetText("");
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetCount
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Get the item count.
int GUIComboBox::GetCount(void)
{
return m_ListPanel->GetItemList()->size();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetSelectedIndex
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Get the index of the selected item.
int GUIComboBox::GetSelectedIndex(void)
{
return m_ListPanel->GetSelectedIndex();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetSelectedIndex
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets the index of the selected item.
void GUIComboBox::SetSelectedIndex(int Index)
{
m_ListPanel->SetSelectedIndex(Index);
m_OldSelection = Index;
// Set the text to the item in the list panel
GUIListPanel::Item *Item = m_ListPanel->GetSelected();
if (Item)
m_TextPanel->SetText(Item->m_Name);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: RollbackSelection
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Rolls back the selection to the previous selected item.
bool GUIComboBox::RollbackSelection()
{
// Restore the previous selection
if (m_OldSelection >= 0 && m_OldSelection < m_ListPanel->GetItemList()->size() && m_OldSelection != m_ListPanel->GetSelectedIndex())
{
m_ListPanel->SetSelectedIndex(m_OldSelection);
// Set the text to the item in the list panel
GUIListPanel::Item *Item = m_ListPanel->GetSelected();
if (Item)
{
m_TextPanel->SetText(Item->m_Name);
return true;
}
}
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetItem
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Returns the Item structure at the index.
GUIListPanel::Item *GUIComboBox::GetItem(int Index)
{
return m_ListPanel->GetItem(Index);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetDropHeight
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets the drop height of the list.
void GUIComboBox::SetDropHeight(int Drop)
{
m_DropHeight = Drop;
m_DropHeight = std::max(m_DropHeight, 20);
// Change the list panel
m_ListPanel->SetSize(m_Width, m_DropHeight);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: StoreProperties
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the control to store the values into properties.
void GUIComboBox::StoreProperties(void)
{
m_Properties.AddVariable("DropHeight", m_DropHeight);
if (m_DropDownStyle == DropDownList)
m_Properties.AddVariable("DropDownStyle", "DropDownList");
else if (m_DropDownStyle == DropDown)
m_Properties.AddVariable("DropDownStyle", "DropDown");
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetDropDownStyle
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets the drop down style of the combo box.
void GUIComboBox::SetDropDownStyle(int Style)
{
if (Style == DropDown || Style == DropDownList)
m_DropDownStyle = Style;
m_TextPanel->SetLocked((m_DropDownStyle == DropDownList));
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetDropDownStyle
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the drop down style of the combo box.
int GUIComboBox::GetDropDownStyle(void)
{
return m_DropDownStyle;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetVisible
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets the visibility of the control.
void GUIComboBox::SetVisible(bool Visible)
{
_SetVisible(Visible);
if (!Visible && m_ListPanel)
m_ListPanel->_SetVisible(false);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetVisible
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the visibility of the control.
bool GUIComboBox::GetVisible(void)
{
return _GetVisible();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetEnabled
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets the enabled state of the control.
void GUIComboBox::SetEnabled(bool Enabled)
{
_SetEnabled(Enabled);
if (m_ListPanel)
m_ListPanel->_SetEnabled(Enabled);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetEnabled
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the enabled state of the control.
bool GUIComboBox::GetEnabled(void)
{
return _GetEnabled();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetText
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets text (only if style is DropDown).
string GUIComboBox::GetText(void)
{
if (m_DropDownStyle != DropDown)
return "";
if (m_TextPanel)
return m_TextPanel->GetText();
return "";
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetText
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets text (only if style is DropDown).
void GUIComboBox::SetText(const string Text)
{
if (m_DropDownStyle == DropDown && m_TextPanel)
m_TextPanel->SetText(Text);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ApplyProperties
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Applies new properties to the control.
void GUIComboBox::ApplyProperties(GUIProperties *Props)
{
GUIControl::ApplyProperties(Props);
m_Properties.GetValue("Dropheight", &m_DropHeight);
m_DropHeight = std::max(m_DropHeight, 20);
string Val;
m_Properties.GetValue("DropDownStyle", &Val);
if (stricmp(Val.c_str(), "DropDownList") == 0)
m_DropDownStyle = DropDownList;
else if (stricmp(Val.c_str(), "DropDown") == 0)
m_DropDownStyle = DropDown;
m_TextPanel->SetLocked((m_DropDownStyle == DropDownList));
// Force a rebuild of the bitmap
ChangeSkin(m_Skin);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Constructor: GUIComboBoxButton
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Constructor method used to instantiate a GUIComboBoxButton object in
// system memory.
GUIComboBoxButton::GUIComboBoxButton(GUIManager *Manager)
: GUIPanel(Manager)
{
m_DrawBitmap = 0;
m_Pushed = false;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ChangeSkin
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the skin has been changed.
void GUIComboBoxButton::ChangeSkin(GUISkin *Skin)
{
// Free any old bitmap
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = 0;
}
// Create a new bitmap. Same width, but double the height to allow for both up
// AND down states
m_DrawBitmap = Skin->CreateBitmap(m_Width, m_Height*2);
// Create the button image
Skin->BuildStandardRect(m_DrawBitmap, "ComboBox_ButtonUp", 0, 0, m_Width, m_Height);
Skin->BuildStandardRect(m_DrawBitmap, "ComboBox_ButtonDown", 0, m_Height, m_Width, m_Height);
// Draw the arrow
string Filename;
Skin->GetValue("ComboBox_Arrow", "Filename", &Filename);
GUIBitmap *Arrow = Skin->CreateBitmap(Filename);
if (!Arrow)
return;
unsigned long ColorKey;
Skin->GetValue("ComboBox_Arrow", "ColorKeyIndex", &ColorKey);
ColorKey = Skin->ConvertColor(ColorKey, m_DrawBitmap->GetColorDepth());
Arrow->SetColorKey(ColorKey);
int Values[4];
GUIRect Rect;
Skin->GetValue("ComboBox_Arrow", "Rect", Values, 4);
SetRect(&Rect, Values[0], Values[1], Values[0]+Values[2], Values[1]+Values[3]);
Arrow->DrawTrans(m_DrawBitmap,
(m_Width/2)-(Values[2]/2),
(m_Height/2)-(Values[3]/2),
&Rect);
Arrow->DrawTrans(m_DrawBitmap,
(m_Width/2)-(Values[2]/2)+1,
m_Height+(m_Height/2)-(Values[3]/2)+1,
&Rect);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Draw
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Draws the panel
void GUIComboBoxButton::Draw(GUIScreen *Screen)
{
GUIRect Rect;
SetRect(&Rect, 0, m_Pushed ? m_Height : 0, m_Width, m_Pushed ? m_Height*2 : m_Height);
m_DrawBitmap->Draw(Screen->GetBitmap(), m_X, m_Y, &Rect);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Create
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Create the panel.
void GUIComboBoxButton::Create(int X, int Y, int Width, int Height)
{
m_X = X;
m_Y = Y;
m_Width = Width;
m_Height = Height;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: OnMouseDown
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the mouse goes down on the panel
void GUIComboBoxButton::OnMouseDown(int X, int Y, int Buttons, int Modifier)
{
if (Buttons & MOUSE_LEFT) {
m_Pushed = true;
SendSignal(Clicked, Buttons);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: OnMouseUp
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the mouse goes up on the panel
void GUIComboBoxButton::OnMouseUp(int X, int Y, int Buttons, int Modifier)
{
m_Pushed = false;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetPushed
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets the pushed state of the button.
void GUIComboBoxButton::SetPushed(bool Pushed)
{
m_Pushed = Pushed;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Destroy
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Destroys the button.
void GUIComboBoxButton::Destroy(void)
{
// Free the drawing bitmap
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = 0;
}
}