-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIPropertyPage.cpp
More file actions
363 lines (288 loc) · 8.59 KB
/
Copy pathGUIPropertyPage.cpp
File metadata and controls
363 lines (288 loc) · 8.59 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
#include "GUI.h"
#include "GUIPropertyPage.h"
#include <cassert>
using namespace RTE;
GUIPropertyPage::GUIPropertyPage(GUIManager* Manager, GUIControlManager* ControlManager) :
GUIControl(), GUIPanel(Manager) {
m_ControlID = "PROPERTYPAGE";
m_DrawBitmap = nullptr;
m_ControlManager = ControlManager;
m_Font = nullptr;
m_VertScroll = nullptr;
m_FontColor = 0;
m_LineColor = 0;
m_PageValues.Clear();
m_TextPanelList.clear();
}
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);
}
}
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);
}
}
void GUIPropertyPage::Destroy() {
// Free the drawing bitmap
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = nullptr;
}
// Free the vertical scrollbar
if (m_VertScroll) {
m_VertScroll->Destroy();
delete m_VertScroll;
m_VertScroll = nullptr;
}
}
void GUIPropertyPage::ChangeSkin(GUISkin* Skin) {
GUIControl::ChangeSkin(Skin);
// Change the skin of the text panels
for (GUITextPanel* textPanel: m_TextPanelList) {
textPanel->ChangeSkin(Skin);
}
// Build the control bitmap
BuildBitmap();
}
void GUIPropertyPage::BuildBitmap() {
// Free any old bitmap
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = nullptr;
}
// 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
std::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());
}
void GUIPropertyPage::Draw(GUIScreen* Screen) {
if (m_DrawBitmap) {
m_DrawBitmap->Draw(Screen->GetBitmap(), m_X, m_Y, nullptr);
}
// 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;
std::string Name;
std::string 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);
}
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();
}
void GUIPropertyPage::OnMouseUp(int X, int Y, int Buttons, int Modifier) {}
void GUIPropertyPage::OnMouseEnter(int X, int Y, int Buttons, int Modifier) {
}
void GUIPropertyPage::OnMouseLeave(int X, int Y, int Buttons, int Modifier) {
}
void GUIPropertyPage::OnMouseMove(int X, int Y, int Buttons, int Modifier) {
if (!(Buttons & MOUSE_LEFT) || !IsCaptured()) {
return;
}
}
GUIPanel* GUIPropertyPage::GetPanel() {
return this;
}
void GUIPropertyPage::GetControlRect(int* X, int* Y, int* Width, int* Height) {
GUIPanel::GetRect(X, Y, Width, Height);
}
void GUIPropertyPage::Move(int X, int Y) {
GUIPanel::SetPositionAbs(X, Y);
}
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();
}
void GUIPropertyPage::StoreProperties() {
// Note: This is for saving the control, not related directly to our control type
}
void GUIPropertyPage::SetPropertyValues(GUIProperties* Props) {
m_PageValues.Clear();
m_PageValues.Update(Props, true);
// Update the text panels
for (int i = 0; i < m_TextPanelList.size(); i++) {
GUITextPanel* T = m_TextPanelList.at(i);
T->_SetVisible(false);
T->SetText("");
if (i < m_PageValues.GetCount()) {
T->_SetVisible(true);
std::string Name;
std::string Value;
if (m_PageValues.GetVariable(i, &Name, &Value)) {
T->SetText(Value);
}
}
}
}
GUIProperties* GUIPropertyPage::GetPropertyValues() {
return &m_PageValues;
}
void GUIPropertyPage::ReceiveSignal(GUIPanel* Source, int Code, int Data) {
assert(Source);
bool TextSignal = false;
// Is this a text panel?
std::vector<GUITextPanel*>::iterator it;
for (it = m_TextPanelList.begin(); it != m_TextPanelList.end(); it++) {
const 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 && InvokeUpdate()) {
// Fire the enter event
AddEvent(GUIEvent::Notification, GUIPropertyPage::Enter, 0);
}
}
bool GUIPropertyPage::InvokeUpdate() {
bool Changed = false;
for (int i = 0; i < m_TextPanelList.size(); i++) {
const GUITextPanel* T = m_TextPanelList.at(i);
if (i < m_PageValues.GetCount()) {
std::string Name;
std::string 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;
}
void GUIPropertyPage::ClearValues() {
m_PageValues.Clear();
// Hide the text panels
std::vector<GUITextPanel*>::iterator it;
for (it = m_TextPanelList.begin(); it != m_TextPanelList.end(); it++) {
GUITextPanel* T = *it;
T->_SetVisible(false);
}
}
bool GUIPropertyPage::HasTextFocus() {
std::vector<GUITextPanel*>::iterator it;
for (it = m_TextPanelList.begin(); it != m_TextPanelList.end(); it++) {
const GUITextPanel* T = *it;
// Visible & has focus??
if (T->_GetVisible() && T->HasFocus()) {
return true;
}
}
return false;
}