-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIPropertyPage.cpp
More file actions
587 lines (444 loc) · 18 KB
/
GUIPropertyPage.cpp
File metadata and controls
587 lines (444 loc) · 18 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
//////////////////////////////////////////////////////////////////////////////////////////
// File: GUIPropertyPage.cpp
//////////////////////////////////////////////////////////////////////////////////////////
// Description: GUIPropertyPage class
// Project: GUI Library
// Author(s): Jason Boettcher
// jackal@shplorb.com
// www.shplorb.com/~jackal
//////////////////////////////////////////////////////////////////////////////////////////
// Inclusions of header files
#include "GUI.h"
#include "GUIPropertyPage.h"
using namespace RTE;
//////////////////////////////////////////////////////////////////////////////////////////
// Constructor: GUIPropertyPage
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Constructor method used to instantiate a GUIPropertyPage object in
// system memory.
GUIPropertyPage::GUIPropertyPage(GUIManager *Manager, GUIControlManager *ControlManager)
: GUIPanel(Manager),
GUIControl()
{
m_ControlID = "PROPERTYPAGE";
m_DrawBitmap = 0;
m_ControlManager = ControlManager;
m_Font = 0;
m_VertScroll = 0;
m_FontColor = 0;
m_LineColor = 0;
m_PageValues.Clear();
m_TextPanelList.clear();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Create
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been created.
void GUIPropertyPage::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 = 50;
m_MinHeight = 50;
// Default size of the control
m_DefWidth = 80;
m_DefHeight = 100;
// 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 control isn't too small
m_Width = std::max(m_Width, m_MinWidth);
m_Height = std::max(m_Height, m_MinHeight);
// Create the vertical scrollbar
m_VertScroll = new GUIScrollPanel(m_Manager);
m_VertScroll->Create(m_Width-12, 0, 12, m_Height);
m_VertScroll->SetOrientation(GUIScrollPanel::Vertical);
m_VertScroll->_SetVisible(false);
m_VertScroll->SetValue(0);
m_VertScroll->SetSignalTarget(this);
GUIPanel::AddChild(m_VertScroll);
// Create the text panels
int H = 16;
int Spacer = 0;
int Size = m_Height/H;
for(int i=0; i<Size; i++) {
GUITextPanel *T = new GUITextPanel(m_Manager);
T->Create(m_Width/2, i*H+Spacer, m_Width/2, H);
T->_SetVisible(false);
T->SetSignalTarget(this);
GUIPanel::AddChild(T);
m_TextPanelList.push_back(T);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Create
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been created.
void GUIPropertyPage::Create(GUIProperties *Props)
{
GUIControl::Create(Props);
// Minimum size of the control
m_MinWidth = 50;
m_MinHeight = 50;
// Default size of the control
m_DefWidth = 80;
m_DefHeight = 100;
// Setup the panel
GUIPanel::LoadProperties(Props);
// Make sure the control isn't too small
m_Width = std::max(m_Width, m_MinWidth);
m_Height = std::max(m_Height, m_MinHeight);
// Create the vertical scrollbar
m_VertScroll = new GUIScrollPanel(m_Manager);
m_VertScroll->Create(m_Width-12, 0, 12, m_Height);
m_VertScroll->SetOrientation(GUIScrollPanel::Vertical);
m_VertScroll->_SetVisible(false);
m_VertScroll->SetValue(0);
m_VertScroll->SetSignalTarget(this);
GUIPanel::AddChild(m_VertScroll);
// Create the text panels
int H = 16;
int Spacer = 0;
int Size = m_Height/H;
for(int i=0; i<Size; i++) {
GUITextPanel *T = new GUITextPanel(m_Manager);
T->Create(m_Width/2, i*H+Spacer, m_Width/2, H);
T->_SetVisible(false);
T->SetSignalTarget(this);
GUIPanel::AddChild(T);
m_TextPanelList.push_back(T);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Destroy
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been destroyed.
void GUIPropertyPage::Destroy(void)
{
// Free the drawing bitmap
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = 0;
}
// Free the vertical scrollbar
if (m_VertScroll) {
m_VertScroll->Destroy();
delete m_VertScroll;
m_VertScroll = 0;
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ChangeSkin
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the skin has been changed.
void GUIPropertyPage::ChangeSkin(GUISkin *Skin)
{
GUIControl::ChangeSkin(Skin);
// Change the skin of the text panels
for(int i=0; i<m_TextPanelList.size(); i++) {
GUITextPanel *T = (GUITextPanel *)m_TextPanelList.at(i);
T->ChangeSkin(Skin);
}
// Build the control bitmap
BuildBitmap();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: BuildBitmap
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Create the control bitmap to draw.
void GUIPropertyPage::BuildBitmap(void)
{
// 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);
m_Skin->BuildStandardRect(m_DrawBitmap, "PropertyPage", 0, 0, m_Width, m_Height);
// Pre-cache the font
string Filename;
m_Skin->GetValue("PropertyPage", "Font", &Filename);
m_Skin->GetValue("PropertyPage", "FontShadow", &m_FontShadow);
m_Skin->GetValue("PropertyPage", "FontColor", &m_FontColor);
m_Skin->GetValue("PropertyPage", "FontKerning", &m_FontKerning);
m_FontColor = m_Skin->ConvertColor(m_FontColor, m_DrawBitmap->GetColorDepth());
m_Font = m_Skin->GetFont(Filename);
if (m_Font)
m_Font->CacheColor(m_FontColor);
m_Skin->GetValue("PropertyPage", "LineColor", &m_LineColor);
m_LineColor = m_Skin->ConvertColor(m_LineColor, m_DrawBitmap->GetColorDepth());
/* // Create the button image
m_Skin->BuildStandardRect(m_DrawBitmap, "Button_Up", 0, 0, m_Width, m_Height);
m_Skin->BuildStandardRect(m_DrawBitmap, "Button_Over", 0, m_Height, m_Width, m_Height);
m_Skin->BuildStandardRect(m_DrawBitmap, "Button_Down", 0, m_Height*2, m_Width, m_Height);
// Draw the text
// int y = m_Height/2-m_Font->CalculateHeight(m_Text)+2;
int y = (m_Height / 2) - (m_Font->GetFontHeight() / 2) - 1;
m_Font->SetColor(m_FontColor);
m_Font->SetKerning(m_FontKerning);
m_Font->DrawAligned(m_DrawBitmap, m_Width/2, y, m_Text, GUIFont::Centre, GUIFont::Top, m_Width, m_FontShadow);
m_Font->DrawAligned(m_DrawBitmap, m_Width/2, m_Height+y, m_Text, GUIFont::Centre, GUIFont::Top, m_Width, m_FontShadow);
m_Font->DrawAligned(m_DrawBitmap, m_Width/2+1, m_Height*2+y+1, m_Text, GUIFont::Centre, GUIFont::Top, m_Width, m_FontShadow);*/
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Draw
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Draws the panel
void GUIPropertyPage::Draw(GUIScreen *Screen)
{
if (m_DrawBitmap)
m_DrawBitmap->Draw(Screen->GetBitmap(), m_X, m_Y, 0);
// Check the font first
if (!m_Font)
return;
// Draw the properties
int Count = m_PageValues.GetCount();
int Spacer = 2;
int Y = m_Y+Spacer;
int Size = 16;
string Name, Value;
for(int i=0; i<Count; i++) {
m_PageValues.GetVariable(i, &Name, &Value);
m_Font->SetColor(m_FontColor);
m_Font->SetKerning(m_FontKerning);
m_Font->Draw(Screen->GetBitmap(), m_X+Spacer, Y, Name, m_FontShadow);
Screen->GetBitmap()->DrawRectangle(m_X+1, Y+Size + (m_Font->GetFontHeight()/2 - Size/2),
m_Width-2, 0, m_LineColor, false);
Y += Size;
}
Screen->GetBitmap()->DrawRectangle(m_X+m_Width/2, m_Y+1, 0, Y-m_Y-Spacer*2, m_LineColor, false);
GUIPanel::Draw(Screen);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: OnMouseDown
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the mouse goes down on the panel
void GUIPropertyPage::OnMouseDown(int X, int Y, int Buttons, int Modifier)
{
if (Buttons & MOUSE_LEFT) {
// Push the button down
//m_Pushed = true;
//CaptureMouse();
//AddEvent(GUIEvent::Notification, Pushed, 0);
}
SetFocus();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: OnMouseUp
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the mouse goes up on the panel
void GUIPropertyPage::OnMouseUp(int X, int Y, int Buttons, int Modifier)
{
/*if (PointInside(X, Y))
AddEvent(GUIEvent::Notification, Clicked, Buttons);
if (!IsCaptured())
return;
m_Pushed = false;
ReleaseMouse();
// If the mouse is over the button, add the command to the event queue
if (PointInside(X, Y))
AddEvent(GUIEvent::Command, 0, 0);
AddEvent(GUIEvent::Notification, UnPushed, 0);*/
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: OnMouseEnter
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the mouse enters the panel.
void GUIPropertyPage::OnMouseEnter(int X, int Y, int Buttons, int Modifier)
{
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: OnMouseLeave
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the mouse leaves the panel.
void GUIPropertyPage::OnMouseLeave(int X, int Y, int Buttons, int Modifier)
{
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: OnMouseMove
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the mouse moves (over the panel, or when captured).
void GUIPropertyPage::OnMouseMove(int X, int Y, int Buttons, int Modifier)
{
if (!(Buttons & MOUSE_LEFT) || !IsCaptured())
return;
// If the mouse goes outside of the button, un-push the button
/*if (!PointInside(X, Y)) {
if (m_Pushed) {
AddEvent(GUIEvent::Notification, UnPushed, 0);
m_Pushed = false;
}
} else {
if (!m_Pushed) {
AddEvent(GUIEvent::Notification, Pushed, 0);
m_Pushed = true;
}
}*/
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetPanel
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Returns the panel of the control.
GUIPanel *GUIPropertyPage::GetPanel(void)
{
return this;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetControlRect
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the rectangle of the control.
void GUIPropertyPage::GetControlRect(int *X, int *Y, int *Width, int *Height)
{
GUIPanel::GetRect(X, Y, Width, Height);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Move
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control needs to be moved.
void GUIPropertyPage::Move(int X, int Y)
{
GUIPanel::SetPositionAbs(X, Y);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Resize
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control needs to be resized.
void GUIPropertyPage::Resize(int Width, int Height)
{
// Make sure the control isn't too small
Width = std::max(Width, m_MinWidth);
Height = std::max(Height, m_MinHeight);
GUIPanel::SetSize(Width, Height);
// TODO: Alter text panels
BuildBitmap();
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: StoreProperties
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the control to store the values into properties.
void GUIPropertyPage::StoreProperties(void)
{
// Note: This is for saving the control, not related directly to our control type
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetPropertyValues
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Refreshes the page with new variables & values.
void GUIPropertyPage::SetPropertyValues(GUIProperties *Props)
{
m_PageValues.Clear();
m_PageValues.Update(Props, true);
// Sort
m_PageValues.Sort(true);
// Update the text panels
for(int i=0; i<m_TextPanelList.size(); i++) {
GUITextPanel *T = (GUITextPanel *)m_TextPanelList.at(i);
T->_SetVisible(false);
T->SetText("");
if (i < m_PageValues.GetCount()) {
T->_SetVisible(true);
string Name, Value;
if (m_PageValues.GetVariable(i, &Name, &Value))
T->SetText(Value);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetPropertyValues
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the properties in the page.
GUIProperties *GUIPropertyPage::GetPropertyValues(void)
{
return &m_PageValues;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ReceiveSignal
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when receiving a signal.
void GUIPropertyPage::ReceiveSignal(GUIPanel *Source, int Code, int Data)
{
assert(Source);
bool TextSignal = false;
// Is this a text panel?
vector<GUITextPanel *>::iterator it;
for(it = m_TextPanelList.begin(); it != m_TextPanelList.end(); it++) {
GUITextPanel *T = *it;
if (Source->GetPanelID() == T->GetPanelID()) {
TextSignal = true;
// Change event. Do not update properties
if (Code == GUITextPanel::Changed) {
AddEvent(GUIEvent::Notification, GUIPropertyPage::Changed, 0);
return;
}
break;
}
}
// Update the properties.
// If any of the values are different, fire a 'changed' notification event
if (TextSignal) {
// Update the text panels
if (InvokeUpdate()) {
// Fire the enter event
AddEvent(GUIEvent::Notification, GUIPropertyPage::Enter, 0);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: InvokeUpdate
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Invokes an explicit update on text panels to property page.
bool GUIPropertyPage::InvokeUpdate(void)
{
bool Changed = false;
for(int i=0; i<m_TextPanelList.size(); i++) {
GUITextPanel *T = (GUITextPanel *)m_TextPanelList.at(i);
if (i < m_PageValues.GetCount()) {
string Name, Value;
if (m_PageValues.GetVariable(i, &Name, &Value)) {
if (T->GetText().compare(Value) != 0)
Changed = true;
// Set the value
m_PageValues.SetVariable(i, Name, T->GetText());
}
}
}
return Changed;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ClearValues
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Clears the property page values.
void GUIPropertyPage::ClearValues(void)
{
m_PageValues.Clear();
// Hide the text panels
vector<GUITextPanel *>::iterator it;
for(it = m_TextPanelList.begin(); it != m_TextPanelList.end(); it++) {
GUITextPanel *T = *it;
T->_SetVisible(false);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: HasTextFocus
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Checks if any of the visible text panels have focus.
bool GUIPropertyPage::HasTextFocus(void)
{
vector<GUITextPanel *>::iterator it;
for(it = m_TextPanelList.begin(); it != m_TextPanelList.end(); it++) {
GUITextPanel *T = *it;
// Visible & has focus??
if (T->_GetVisible() && T->HasFocus())
return true;
}
return false;
}