-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathGUITextBox.cpp
More file actions
254 lines (193 loc) · 7.76 KB
/
GUITextBox.cpp
File metadata and controls
254 lines (193 loc) · 7.76 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
//////////////////////////////////////////////////////////////////////////////////////////
// File: GUITextBox.cpp
//////////////////////////////////////////////////////////////////////////////////////////
// Description: GUITextBox class
// Project: GUI Library
// Author(s): Jason Boettcher
// jackal@shplorb.com
// www.shplorb.com/~jackal
//////////////////////////////////////////////////////////////////////////////////////////
// Inclusions of header files
#include "GUI.h"
#include "GUITextBox.h"
using namespace std;
using namespace RTE;
//////////////////////////////////////////////////////////////////////////////////////////
// Constructor: GUITextBox
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Constructor method used to instantiate a GUITextBox object in
// system memory.
GUITextBox::GUITextBox(GUIManager *Manager, GUIControlManager *ControlManager)
: GUITextPanel(Manager),
GUIControl()
{
m_ControlID = "TEXTBOX";
m_ControlManager = ControlManager;
m_DrawBitmap = 0;
m_HAlignment = GUIFont::Left;
m_VAlignment = GUIFont::Top;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Create
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been created.
void GUITextBox::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 = 16;
// Create the ListPanel
int w = m_DefWidth;
int h = m_DefHeight;
if (Width != -1)
w = Width;
if (Height != -1)
h = Height;
GUITextPanel::Create(X, Y, w, h);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Create
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been created.
void GUITextBox::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 = 16;
// Setup the panel
GUIPanel::LoadProperties(Props);
GUITextPanel::Create(m_X, m_Y, m_Width, m_Height);
// Make sure the textbox isn't too small
m_Width = GUI_MAX(m_Width, m_MinWidth);
m_Height = GUI_MAX(m_Height, m_MinHeight);
// Alignment values - these don't affect anyhting as of yet
string alignString;
Props->GetValue("HAlignment", &alignString);
if (DDTstricmp(alignString.c_str(), "left") == 0)
m_HAlignment = GUIFont::Left;
if (DDTstricmp(alignString.c_str(), "centre") == 0 || DDTstricmp(alignString.c_str(), "center") == 0)
m_HAlignment = GUIFont::Centre;
if (DDTstricmp(alignString.c_str(), "right") == 0)
m_HAlignment = GUIFont::Right;
Props->GetValue("VAlignment", &alignString);
if (DDTstricmp(alignString.c_str(), "top") == 0)
m_VAlignment = GUIFont::Top;
if (DDTstricmp(alignString.c_str(), "middle") == 0)
m_VAlignment = GUIFont::Middle;
if (DDTstricmp(alignString.c_str(), "bottom") == 0)
m_VAlignment = GUIFont::Bottom;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Destroy
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control has been destroyed.
void GUITextBox::Destroy(void)
{
// Destroy the draw bitmap
if (m_DrawBitmap) {
m_DrawBitmap->Destroy();
delete m_DrawBitmap;
m_DrawBitmap = 0;
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ChangeSkin
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the skin has been changed.
void GUITextBox::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 panel too
GUITextPanel::ChangeSkin(Skin);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Draw
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Draws the panel
void GUITextBox::Draw(GUIScreen *Screen)
{
// Draw the background
m_DrawBitmap->Draw(Screen->GetBitmap(), m_X, m_Y, 0);
GUITextPanel::Draw(Screen);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetPanel
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Returns the panel of the control.
GUIPanel *GUITextBox::GetPanel(void)
{
return this;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Move
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control needs to be moved.
void GUITextBox::Move(int X, int Y)
{
GUITextPanel::SetPositionAbs(X, Y);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: Resize
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when the control needs to be resized.
void GUITextBox::Resize(int Width, int Height)
{
// Make sure the control isn't too small
Width = GUI_MAX(Width, m_MinWidth);
Height = GUI_MAX(Height, m_MinHeight);
GUITextPanel::SetSize(Width, Height);
// Force a rebuild
ChangeSkin(m_Skin);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetControlRect
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the rectangle of the control.
void GUITextBox::GetControlRect(int *X, int *Y, int *Width, int *Height)
{
GUITextPanel::GetRect(X, Y, Width, Height);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ReceiveSignal
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Called when receiving a signal.
void GUITextBox::ReceiveSignal(GUIPanel *Source, int Code, int Data)
{
// Clicked
if (Code == GUITextPanel::Clicked)
AddEvent(GUIEvent::Notification, Clicked, Data);
// Changed
if (Code == GUITextPanel::Changed)
AddEvent(GUIEvent::Notification, Changed, 0);
// Enter
if (Code == GUITextPanel::Enter)
AddEvent(GUIEvent::Notification, Enter, 0);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: ApplyProperties
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Applies new properties to the control.
void GUITextBox::ApplyProperties(GUIProperties *Props)
{
GUIControl::ApplyProperties(Props);
// Force a rebuild of the bitmap
ChangeSkin(m_Skin);
}