aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp654
1 files changed, 327 insertions, 327 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp
index b440699..24d1aee 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUISpinBox.cpp
@@ -1,327 +1,327 @@
1// Copyright (C) 2006-2012 Michael Zeilfelder 1// Copyright (C) 2006-2012 Michael Zeilfelder
2// This file uses the licence of the Irrlicht Engine. 2// This file uses the licence of the Irrlicht Engine.
3 3
4#include "CGUISpinBox.h" 4#include "CGUISpinBox.h"
5#ifdef _IRR_COMPILE_WITH_GUI_ 5#ifdef _IRR_COMPILE_WITH_GUI_
6 6
7#include "CGUIEditBox.h" 7#include "CGUIEditBox.h"
8#include "CGUIButton.h" 8#include "CGUIButton.h"
9#include "IGUIEnvironment.h" 9#include "IGUIEnvironment.h"
10#include "IEventReceiver.h" 10#include "IEventReceiver.h"
11#include "fast_atof.h" 11#include "fast_atof.h"
12#include <wchar.h> 12#include <wchar.h>
13 13
14 14
15namespace irr 15namespace irr
16{ 16{
17namespace gui 17namespace gui
18{ 18{
19 19
20//! constructor 20//! constructor
21CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* environment, 21CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* environment,
22 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle) 22 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle)
23: IGUISpinBox(environment, parent, id, rectangle), 23: IGUISpinBox(environment, parent, id, rectangle),
24 EditBox(0), ButtonSpinUp(0), ButtonSpinDown(0), StepSize(1.f), 24 EditBox(0), ButtonSpinUp(0), ButtonSpinDown(0), StepSize(1.f),
25 RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"), 25 RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"),
26 DecimalPlaces(-1) 26 DecimalPlaces(-1)
27{ 27{
28 #ifdef _DEBUG 28 #ifdef _DEBUG
29 setDebugName("CGUISpinBox"); 29 setDebugName("CGUISpinBox");
30 #endif 30 #endif
31 31
32 CurrentIconColor = video::SColor(255,255,255,255); 32 CurrentIconColor = video::SColor(255,255,255,255);
33 s32 ButtonWidth = 16; 33 s32 ButtonWidth = 16;
34 34
35 ButtonSpinDown = Environment->addButton( 35 ButtonSpinDown = Environment->addButton(
36 core::rect<s32>(rectangle.getWidth() - ButtonWidth, rectangle.getHeight()/2 +1, 36 core::rect<s32>(rectangle.getWidth() - ButtonWidth, rectangle.getHeight()/2 +1,
37 rectangle.getWidth(), rectangle.getHeight()), this); 37 rectangle.getWidth(), rectangle.getHeight()), this);
38 ButtonSpinDown->grab(); 38 ButtonSpinDown->grab();
39 ButtonSpinDown->setSubElement(true); 39 ButtonSpinDown->setSubElement(true);
40 ButtonSpinDown->setTabStop(false); 40 ButtonSpinDown->setTabStop(false);
41 ButtonSpinDown->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_CENTER, EGUIA_LOWERRIGHT); 41 ButtonSpinDown->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_CENTER, EGUIA_LOWERRIGHT);
42 42
43 ButtonSpinUp = Environment->addButton( 43 ButtonSpinUp = Environment->addButton(
44 core::rect<s32>(rectangle.getWidth() - ButtonWidth, 0, 44 core::rect<s32>(rectangle.getWidth() - ButtonWidth, 0,
45 rectangle.getWidth(), rectangle.getHeight()/2), this); 45 rectangle.getWidth(), rectangle.getHeight()/2), this);
46 ButtonSpinUp->grab(); 46 ButtonSpinUp->grab();
47 ButtonSpinUp->setSubElement(true); 47 ButtonSpinUp->setSubElement(true);
48 ButtonSpinUp->setTabStop(false); 48 ButtonSpinUp->setTabStop(false);
49 ButtonSpinUp->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER); 49 ButtonSpinUp->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER);
50 50
51 const core::rect<s32> rectEdit(0, 0, rectangle.getWidth() - ButtonWidth - 1, rectangle.getHeight()); 51 const core::rect<s32> rectEdit(0, 0, rectangle.getWidth() - ButtonWidth - 1, rectangle.getHeight());
52 EditBox = Environment->addEditBox(text, rectEdit, border, this, -1); 52 EditBox = Environment->addEditBox(text, rectEdit, border, this, -1);
53 EditBox->grab(); 53 EditBox->grab();
54 EditBox->setSubElement(true); 54 EditBox->setSubElement(true);
55 EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); 55 EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
56 56
57 refreshSprites(); 57 refreshSprites();
58} 58}
59 59
60 60
61//! destructor 61//! destructor
62CGUISpinBox::~CGUISpinBox() 62CGUISpinBox::~CGUISpinBox()
63{ 63{
64 if (ButtonSpinUp) 64 if (ButtonSpinUp)
65 ButtonSpinUp->drop(); 65 ButtonSpinUp->drop();
66 if (ButtonSpinDown) 66 if (ButtonSpinDown)
67 ButtonSpinDown->drop(); 67 ButtonSpinDown->drop();
68 if (EditBox) 68 if (EditBox)
69 EditBox->drop(); 69 EditBox->drop();
70} 70}
71 71
72void CGUISpinBox::refreshSprites() 72void CGUISpinBox::refreshSprites()
73{ 73{
74 IGUISpriteBank *sb = 0; 74 IGUISpriteBank *sb = 0;
75 if (Environment && Environment->getSkin()) 75 if (Environment && Environment->getSkin())
76 { 76 {
77 sb = Environment->getSkin()->getSpriteBank(); 77 sb = Environment->getSkin()->getSpriteBank();
78 } 78 }
79 79
80 if (sb) 80 if (sb)
81 { 81 {
82 IGUISkin * skin = Environment->getSkin(); 82 IGUISkin * skin = Environment->getSkin();
83 CurrentIconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL); 83 CurrentIconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
84 ButtonSpinDown->setSpriteBank(sb); 84 ButtonSpinDown->setSpriteBank(sb);
85 ButtonSpinDown->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_SMALL_CURSOR_DOWN), CurrentIconColor); 85 ButtonSpinDown->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_SMALL_CURSOR_DOWN), CurrentIconColor);
86 ButtonSpinDown->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_SMALL_CURSOR_DOWN), CurrentIconColor); 86 ButtonSpinDown->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_SMALL_CURSOR_DOWN), CurrentIconColor);
87 ButtonSpinUp->setSpriteBank(sb); 87 ButtonSpinUp->setSpriteBank(sb);
88 ButtonSpinUp->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_SMALL_CURSOR_UP), CurrentIconColor); 88 ButtonSpinUp->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_SMALL_CURSOR_UP), CurrentIconColor);
89 ButtonSpinUp->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_SMALL_CURSOR_UP), CurrentIconColor); 89 ButtonSpinUp->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_SMALL_CURSOR_UP), CurrentIconColor);
90 } 90 }
91 else 91 else
92 { 92 {
93 ButtonSpinDown->setText(L"-"); 93 ButtonSpinDown->setText(L"-");
94 ButtonSpinUp->setText(L"+"); 94 ButtonSpinUp->setText(L"+");
95 } 95 }
96} 96}
97 97
98IGUIEditBox* CGUISpinBox::getEditBox() const 98IGUIEditBox* CGUISpinBox::getEditBox() const
99{ 99{
100 return EditBox; 100 return EditBox;
101} 101}
102 102
103 103
104void CGUISpinBox::setValue(f32 val) 104void CGUISpinBox::setValue(f32 val)
105{ 105{
106 wchar_t str[100]; 106 wchar_t str[100];
107 107
108 swprintf(str, 99, FormatString.c_str(), val); 108 swprintf(str, 99, FormatString.c_str(), val);
109 EditBox->setText(str); 109 EditBox->setText(str);
110 verifyValueRange(); 110 verifyValueRange();
111} 111}
112 112
113 113
114f32 CGUISpinBox::getValue() const 114f32 CGUISpinBox::getValue() const
115{ 115{
116 const wchar_t* val = EditBox->getText(); 116 const wchar_t* val = EditBox->getText();
117 if ( !val ) 117 if ( !val )
118 return 0.f; 118 return 0.f;
119 core::stringc tmp(val); 119 core::stringc tmp(val);
120 return core::fast_atof(tmp.c_str()); 120 return core::fast_atof(tmp.c_str());
121} 121}
122 122
123 123
124void CGUISpinBox::setRange(f32 min, f32 max) 124void CGUISpinBox::setRange(f32 min, f32 max)
125{ 125{
126 if (max<min) 126 if (max<min)
127 core::swap(min, max); 127 core::swap(min, max);
128 RangeMin = min; 128 RangeMin = min;
129 RangeMax = max; 129 RangeMax = max;
130 130
131 // we have to round the range - otherwise we can get into an infinte setValue/verifyValueRange cycle. 131 // we have to round the range - otherwise we can get into an infinte setValue/verifyValueRange cycle.
132 wchar_t str[100]; 132 wchar_t str[100];
133 swprintf(str, 99, FormatString.c_str(), RangeMin); 133 swprintf(str, 99, FormatString.c_str(), RangeMin);
134 RangeMin = core::fast_atof(core::stringc(str).c_str()); 134 RangeMin = core::fast_atof(core::stringc(str).c_str());
135 swprintf(str, 99, FormatString.c_str(), RangeMax); 135 swprintf(str, 99, FormatString.c_str(), RangeMax);
136 RangeMax = core::fast_atof(core::stringc(str).c_str()); 136 RangeMax = core::fast_atof(core::stringc(str).c_str());
137 137
138 verifyValueRange(); 138 verifyValueRange();
139} 139}
140 140
141 141
142f32 CGUISpinBox::getMin() const 142f32 CGUISpinBox::getMin() const
143{ 143{
144 return RangeMin; 144 return RangeMin;
145} 145}
146 146
147 147
148f32 CGUISpinBox::getMax() const 148f32 CGUISpinBox::getMax() const
149{ 149{
150 return RangeMax; 150 return RangeMax;
151} 151}
152 152
153 153
154f32 CGUISpinBox::getStepSize() const 154f32 CGUISpinBox::getStepSize() const
155{ 155{
156 return StepSize; 156 return StepSize;
157} 157}
158 158
159 159
160void CGUISpinBox::setStepSize(f32 step) 160void CGUISpinBox::setStepSize(f32 step)
161{ 161{
162 StepSize = step; 162 StepSize = step;
163} 163}
164 164
165 165
166//! Sets the number of decimal places to display. 166//! Sets the number of decimal places to display.
167void CGUISpinBox::setDecimalPlaces(s32 places) 167void CGUISpinBox::setDecimalPlaces(s32 places)
168{ 168{
169 DecimalPlaces = places; 169 DecimalPlaces = places;
170 if (places == -1) 170 if (places == -1)
171 FormatString = "%f"; 171 FormatString = "%f";
172 else 172 else
173 { 173 {
174 FormatString = "%."; 174 FormatString = "%.";
175 FormatString += places; 175 FormatString += places;
176 FormatString += "f"; 176 FormatString += "f";
177 } 177 }
178 setRange( RangeMin, RangeMax ); 178 setRange( RangeMin, RangeMax );
179 setValue(getValue()); 179 setValue(getValue());
180} 180}
181 181
182 182
183bool CGUISpinBox::OnEvent(const SEvent& event) 183bool CGUISpinBox::OnEvent(const SEvent& event)
184{ 184{
185 if (IsEnabled) 185 if (IsEnabled)
186 { 186 {
187 bool changeEvent = false; 187 bool changeEvent = false;
188 switch(event.EventType) 188 switch(event.EventType)
189 { 189 {
190 case EET_MOUSE_INPUT_EVENT: 190 case EET_MOUSE_INPUT_EVENT:
191 switch(event.MouseInput.Event) 191 switch(event.MouseInput.Event)
192 { 192 {
193 case EMIE_MOUSE_WHEEL: 193 case EMIE_MOUSE_WHEEL:
194 { 194 {
195 f32 val = getValue() + (StepSize * (event.MouseInput.Wheel < 0 ? -1.f : 1.f)); 195 f32 val = getValue() + (StepSize * (event.MouseInput.Wheel < 0 ? -1.f : 1.f));
196 setValue(val); 196 setValue(val);
197 changeEvent = true; 197 changeEvent = true;
198 } 198 }
199 break; 199 break;
200 default: 200 default:
201 break; 201 break;
202 } 202 }
203 break; 203 break;
204 204
205 case EET_GUI_EVENT: 205 case EET_GUI_EVENT:
206 if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) 206 if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
207 { 207 {
208 if (event.GUIEvent.Caller == ButtonSpinUp) 208 if (event.GUIEvent.Caller == ButtonSpinUp)
209 { 209 {
210 f32 val = getValue(); 210 f32 val = getValue();
211 val += StepSize; 211 val += StepSize;
212 setValue(val); 212 setValue(val);
213 changeEvent = true; 213 changeEvent = true;
214 } 214 }
215 else if ( event.GUIEvent.Caller == ButtonSpinDown) 215 else if ( event.GUIEvent.Caller == ButtonSpinDown)
216 { 216 {
217 f32 val = getValue(); 217 f32 val = getValue();
218 val -= StepSize; 218 val -= StepSize;
219 setValue(val); 219 setValue(val);
220 changeEvent = true; 220 changeEvent = true;
221 } 221 }
222 } 222 }
223 if (event.GUIEvent.EventType == EGET_EDITBOX_CHANGED || event.GUIEvent.EventType == EGET_EDITBOX_ENTER) 223 if (event.GUIEvent.EventType == EGET_EDITBOX_CHANGED || event.GUIEvent.EventType == EGET_EDITBOX_ENTER)
224 { 224 {
225 if (event.GUIEvent.Caller == EditBox) 225 if (event.GUIEvent.Caller == EditBox)
226 { 226 {
227 verifyValueRange(); 227 verifyValueRange();
228 changeEvent = true; 228 changeEvent = true;
229 } 229 }
230 } 230 }
231 break; 231 break;
232 default: 232 default:
233 break; 233 break;
234 } 234 }
235 235
236 if ( changeEvent ) 236 if ( changeEvent )
237 { 237 {
238 SEvent e; 238 SEvent e;
239 e.EventType = EET_GUI_EVENT; 239 e.EventType = EET_GUI_EVENT;
240 e.GUIEvent.Caller = this; 240 e.GUIEvent.Caller = this;
241 e.GUIEvent.Element = 0; 241 e.GUIEvent.Element = 0;
242 242
243 e.GUIEvent.EventType = EGET_SPINBOX_CHANGED; 243 e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
244 if ( Parent ) 244 if ( Parent )
245 Parent->OnEvent(e); 245 Parent->OnEvent(e);
246 return true; 246 return true;
247 } 247 }
248 } 248 }
249 249
250 return IGUIElement::OnEvent(event); 250 return IGUIElement::OnEvent(event);
251} 251}
252 252
253 253
254void CGUISpinBox::draw() 254void CGUISpinBox::draw()
255{ 255{
256 if ( !isVisible() ) 256 if ( !isVisible() )
257 return; 257 return;
258 258
259 IGUISkin* skin = Environment->getSkin(); 259 IGUISkin* skin = Environment->getSkin();
260 if (!skin) 260 if (!skin)
261 return; 261 return;
262 262
263 video::SColor iconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL); 263 video::SColor iconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
264 if ( iconColor != CurrentIconColor ) 264 if ( iconColor != CurrentIconColor )
265 { 265 {
266 refreshSprites(); 266 refreshSprites();
267 } 267 }
268 268
269 IGUISpinBox::draw(); 269 IGUISpinBox::draw();
270} 270}
271 271
272void CGUISpinBox::verifyValueRange() 272void CGUISpinBox::verifyValueRange()
273{ 273{
274 f32 val = getValue(); 274 f32 val = getValue();
275 if ( val+core::ROUNDING_ERROR_f32 < RangeMin ) 275 if ( val+core::ROUNDING_ERROR_f32 < RangeMin )
276 val = RangeMin; 276 val = RangeMin;
277 else if ( val-core::ROUNDING_ERROR_f32 > RangeMax ) 277 else if ( val-core::ROUNDING_ERROR_f32 > RangeMax )
278 val = RangeMax; 278 val = RangeMax;
279 else 279 else
280 return; 280 return;
281 281
282 setValue(val); 282 setValue(val);
283} 283}
284 284
285 285
286//! Sets the new caption of the element 286//! Sets the new caption of the element
287void CGUISpinBox::setText(const wchar_t* text) 287void CGUISpinBox::setText(const wchar_t* text)
288{ 288{
289 EditBox->setText(text); 289 EditBox->setText(text);
290 setValue(getValue()); 290 setValue(getValue());
291 verifyValueRange(); 291 verifyValueRange();
292} 292}
293 293
294 294
295//! Returns caption of this element. 295//! Returns caption of this element.
296const wchar_t* CGUISpinBox::getText() const 296const wchar_t* CGUISpinBox::getText() const
297{ 297{
298 return EditBox->getText(); 298 return EditBox->getText();
299} 299}
300 300
301 301
302//! Writes attributes of the element. 302//! Writes attributes of the element.
303void CGUISpinBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const 303void CGUISpinBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
304{ 304{
305 IGUIElement::serializeAttributes(out, options); 305 IGUIElement::serializeAttributes(out, options);
306 out->addFloat("Min", getMin()); 306 out->addFloat("Min", getMin());
307 out->addFloat("Max", getMax()); 307 out->addFloat("Max", getMax());
308 out->addFloat("Step", getStepSize()); 308 out->addFloat("Step", getStepSize());
309 out->addInt("DecimalPlaces", DecimalPlaces); 309 out->addInt("DecimalPlaces", DecimalPlaces);
310} 310}
311 311
312 312
313//! Reads attributes of the element 313//! Reads attributes of the element
314void CGUISpinBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) 314void CGUISpinBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
315{ 315{
316 IGUIElement::deserializeAttributes(in, options); 316 IGUIElement::deserializeAttributes(in, options);
317 setRange(in->getAttributeAsFloat("Min"), in->getAttributeAsFloat("Max")); 317 setRange(in->getAttributeAsFloat("Min"), in->getAttributeAsFloat("Max"));
318 setStepSize(in->getAttributeAsFloat("Step")); 318 setStepSize(in->getAttributeAsFloat("Step"));
319 setDecimalPlaces(in->getAttributeAsInt("DecimalPlaces")); 319 setDecimalPlaces(in->getAttributeAsInt("DecimalPlaces"));
320} 320}
321 321
322 322
323} // end namespace gui 323} // end namespace gui
324} // end namespace irr 324} // end namespace irr
325 325
326#endif // _IRR_COMPILE_WITH_GUI_ 326#endif // _IRR_COMPILE_WITH_GUI_
327 327