aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CGUIEnvironment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CGUIEnvironment.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CGUIEnvironment.cpp3316
1 files changed, 1658 insertions, 1658 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUIEnvironment.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUIEnvironment.cpp
index bf3fa86..aad2d19 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CGUIEnvironment.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUIEnvironment.cpp
@@ -1,1658 +1,1658 @@
1 1
2// Copyright (C) 2002-2012 Nikolaus Gebhardt 2// Copyright (C) 2002-2012 Nikolaus Gebhardt
3// This file is part of the "Irrlicht Engine". 3// This file is part of the "Irrlicht Engine".
4// For conditions of distribution and use, see copyright notice in irrlicht.h 4// For conditions of distribution and use, see copyright notice in irrlicht.h
5 5
6#include "CGUIEnvironment.h" 6#include "CGUIEnvironment.h"
7 7
8#ifdef _IRR_COMPILE_WITH_GUI_ 8#ifdef _IRR_COMPILE_WITH_GUI_
9 9
10#include "IVideoDriver.h" 10#include "IVideoDriver.h"
11 11
12#include "CGUISkin.h" 12#include "CGUISkin.h"
13#include "CGUIButton.h" 13#include "CGUIButton.h"
14#include "CGUIWindow.h" 14#include "CGUIWindow.h"
15#include "CGUIScrollBar.h" 15#include "CGUIScrollBar.h"
16#include "CGUIFont.h" 16#include "CGUIFont.h"
17#include "CGUISpriteBank.h" 17#include "CGUISpriteBank.h"
18#include "CGUIImage.h" 18#include "CGUIImage.h"
19#include "CGUIMeshViewer.h" 19#include "CGUIMeshViewer.h"
20#include "CGUICheckBox.h" 20#include "CGUICheckBox.h"
21#include "CGUIListBox.h" 21#include "CGUIListBox.h"
22#include "CGUITreeView.h" 22#include "CGUITreeView.h"
23#include "CGUIImageList.h" 23#include "CGUIImageList.h"
24#include "CGUIFileOpenDialog.h" 24#include "CGUIFileOpenDialog.h"
25#include "CGUIColorSelectDialog.h" 25#include "CGUIColorSelectDialog.h"
26#include "CGUIStaticText.h" 26#include "CGUIStaticText.h"
27#include "CGUIEditBox.h" 27#include "CGUIEditBox.h"
28#include "CGUISpinBox.h" 28#include "CGUISpinBox.h"
29#include "CGUIInOutFader.h" 29#include "CGUIInOutFader.h"
30#include "CGUIMessageBox.h" 30#include "CGUIMessageBox.h"
31#include "CGUIModalScreen.h" 31#include "CGUIModalScreen.h"
32#include "CGUITabControl.h" 32#include "CGUITabControl.h"
33#include "CGUIContextMenu.h" 33#include "CGUIContextMenu.h"
34#include "CGUIComboBox.h" 34#include "CGUIComboBox.h"
35#include "CGUIMenu.h" 35#include "CGUIMenu.h"
36#include "CGUIToolBar.h" 36#include "CGUIToolBar.h"
37#include "CGUITable.h" 37#include "CGUITable.h"
38 38
39#include "CDefaultGUIElementFactory.h" 39#include "CDefaultGUIElementFactory.h"
40#include "IWriteFile.h" 40#include "IWriteFile.h"
41#include "IXMLWriter.h" 41#include "IXMLWriter.h"
42 42
43#include "BuiltInFont.h" 43#include "BuiltInFont.h"
44#include "os.h" 44#include "os.h"
45 45
46namespace irr 46namespace irr
47{ 47{
48namespace gui 48namespace gui
49{ 49{
50 50
51const wchar_t* IRR_XML_FORMAT_GUI_ENV = L"irr_gui"; 51const wchar_t* IRR_XML_FORMAT_GUI_ENV = L"irr_gui";
52const wchar_t* IRR_XML_FORMAT_GUI_ELEMENT = L"element"; 52const wchar_t* IRR_XML_FORMAT_GUI_ELEMENT = L"element";
53const wchar_t* IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE = L"type"; 53const wchar_t* IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE = L"type";
54 54
55const io::path CGUIEnvironment::DefaultFontName = "#DefaultFont"; 55const io::path CGUIEnvironment::DefaultFontName = "#DefaultFont";
56 56
57//! constructor 57//! constructor
58CGUIEnvironment::CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op) 58CGUIEnvironment::CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op)
59: IGUIElement(EGUIET_ROOT, 0, 0, 0, core::rect<s32>(core::position2d<s32>(0,0), driver ? core::dimension2d<s32>(driver->getScreenSize()) : core::dimension2d<s32>(0,0))), 59: IGUIElement(EGUIET_ROOT, 0, 0, 0, core::rect<s32>(core::position2d<s32>(0,0), driver ? core::dimension2d<s32>(driver->getScreenSize()) : core::dimension2d<s32>(0,0))),
60 Driver(driver), Hovered(0), HoveredNoSubelement(0), Focus(0), LastHoveredMousePos(0,0), CurrentSkin(0), 60 Driver(driver), Hovered(0), HoveredNoSubelement(0), Focus(0), LastHoveredMousePos(0,0), CurrentSkin(0),
61 FileSystem(fs), UserReceiver(0), Operator(op) 61 FileSystem(fs), UserReceiver(0), Operator(op)
62{ 62{
63 if (Driver) 63 if (Driver)
64 Driver->grab(); 64 Driver->grab();
65 65
66 if (FileSystem) 66 if (FileSystem)
67 FileSystem->grab(); 67 FileSystem->grab();
68 68
69 if (Operator) 69 if (Operator)
70 Operator->grab(); 70 Operator->grab();
71 71
72 #ifdef _DEBUG 72 #ifdef _DEBUG
73 IGUIEnvironment::setDebugName("CGUIEnvironment"); 73 IGUIEnvironment::setDebugName("CGUIEnvironment");
74 #endif 74 #endif
75 75
76 // gui factory 76 // gui factory
77 IGUIElementFactory* factory = new CDefaultGUIElementFactory(this); 77 IGUIElementFactory* factory = new CDefaultGUIElementFactory(this);
78 registerGUIElementFactory(factory); 78 registerGUIElementFactory(factory);
79 factory->drop(); 79 factory->drop();
80 80
81 loadBuiltInFont(); 81 loadBuiltInFont();
82 82
83 IGUISkin* skin = createSkin( gui::EGST_WINDOWS_METALLIC ); 83 IGUISkin* skin = createSkin( gui::EGST_WINDOWS_METALLIC );
84 setSkin(skin); 84 setSkin(skin);
85 skin->drop(); 85 skin->drop();
86 86
87 //set tooltip default 87 //set tooltip default
88 ToolTip.LastTime = 0; 88 ToolTip.LastTime = 0;
89 ToolTip.EnterTime = 0; 89 ToolTip.EnterTime = 0;
90 ToolTip.LaunchTime = 1000; 90 ToolTip.LaunchTime = 1000;
91 ToolTip.RelaunchTime = 500; 91 ToolTip.RelaunchTime = 500;
92 ToolTip.Element = 0; 92 ToolTip.Element = 0;
93 93
94 // environment is root tab group 94 // environment is root tab group
95 Environment = this; 95 Environment = this;
96 setTabGroup(true); 96 setTabGroup(true);
97} 97}
98 98
99 99
100//! destructor 100//! destructor
101CGUIEnvironment::~CGUIEnvironment() 101CGUIEnvironment::~CGUIEnvironment()
102{ 102{
103 if ( HoveredNoSubelement && HoveredNoSubelement != this ) 103 if ( HoveredNoSubelement && HoveredNoSubelement != this )
104 { 104 {
105 HoveredNoSubelement->drop(); 105 HoveredNoSubelement->drop();
106 HoveredNoSubelement = 0; 106 HoveredNoSubelement = 0;
107 } 107 }
108 108
109 if (Hovered && Hovered != this) 109 if (Hovered && Hovered != this)
110 { 110 {
111 Hovered->drop(); 111 Hovered->drop();
112 Hovered = 0; 112 Hovered = 0;
113 } 113 }
114 114
115 if (Focus) 115 if (Focus)
116 { 116 {
117 Focus->drop(); 117 Focus->drop();
118 Focus = 0; 118 Focus = 0;
119 } 119 }
120 120
121 if (ToolTip.Element) 121 if (ToolTip.Element)
122 { 122 {
123 ToolTip.Element->drop(); 123 ToolTip.Element->drop();
124 ToolTip.Element = 0; 124 ToolTip.Element = 0;
125 } 125 }
126 126
127 // drop skin 127 // drop skin
128 if (CurrentSkin) 128 if (CurrentSkin)
129 { 129 {
130 CurrentSkin->drop(); 130 CurrentSkin->drop();
131 CurrentSkin = 0; 131 CurrentSkin = 0;
132 } 132 }
133 133
134 u32 i; 134 u32 i;
135 135
136 // delete all sprite banks 136 // delete all sprite banks
137 for (i=0; i<Banks.size(); ++i) 137 for (i=0; i<Banks.size(); ++i)
138 if (Banks[i].Bank) 138 if (Banks[i].Bank)
139 Banks[i].Bank->drop(); 139 Banks[i].Bank->drop();
140 140
141 // delete all fonts 141 // delete all fonts
142 for (i=0; i<Fonts.size(); ++i) 142 for (i=0; i<Fonts.size(); ++i)
143 Fonts[i].Font->drop(); 143 Fonts[i].Font->drop();
144 144
145 // remove all factories 145 // remove all factories
146 for (i=0; i<GUIElementFactoryList.size(); ++i) 146 for (i=0; i<GUIElementFactoryList.size(); ++i)
147 GUIElementFactoryList[i]->drop(); 147 GUIElementFactoryList[i]->drop();
148 148
149 if (Operator) 149 if (Operator)
150 { 150 {
151 Operator->drop(); 151 Operator->drop();
152 Operator = 0; 152 Operator = 0;
153 } 153 }
154 154
155 if (FileSystem) 155 if (FileSystem)
156 { 156 {
157 FileSystem->drop(); 157 FileSystem->drop();
158 FileSystem = 0; 158 FileSystem = 0;
159 } 159 }
160 160
161 if (Driver) 161 if (Driver)
162 { 162 {
163 Driver->drop(); 163 Driver->drop();
164 Driver = 0; 164 Driver = 0;
165 } 165 }
166} 166}
167 167
168 168
169void CGUIEnvironment::loadBuiltInFont() 169void CGUIEnvironment::loadBuiltInFont()
170{ 170{
171 io::IReadFile* file = io::createMemoryReadFile(BuiltInFontData, BuiltInFontDataSize, DefaultFontName, false); 171 io::IReadFile* file = io::createMemoryReadFile(BuiltInFontData, BuiltInFontDataSize, DefaultFontName, false);
172 172
173 CGUIFont* font = new CGUIFont(this, DefaultFontName ); 173 CGUIFont* font = new CGUIFont(this, DefaultFontName );
174 if (!font->load(file)) 174 if (!font->load(file))
175 { 175 {
176 os::Printer::log("Error: Could not load built-in Font. Did you compile without the BMP loader?", ELL_ERROR); 176 os::Printer::log("Error: Could not load built-in Font. Did you compile without the BMP loader?", ELL_ERROR);
177 font->drop(); 177 font->drop();
178 file->drop(); 178 file->drop();
179 return; 179 return;
180 } 180 }
181 181
182 SFont f; 182 SFont f;
183 f.NamedPath.setPath(DefaultFontName); 183 f.NamedPath.setPath(DefaultFontName);
184 f.Font = font; 184 f.Font = font;
185 Fonts.push_back(f); 185 Fonts.push_back(f);
186 186
187 file->drop(); 187 file->drop();
188} 188}
189 189
190 190
191//! draws all gui elements 191//! draws all gui elements
192void CGUIEnvironment::drawAll() 192void CGUIEnvironment::drawAll()
193{ 193{
194 if (Driver) 194 if (Driver)
195 { 195 {
196 core::dimension2d<s32> dim(Driver->getScreenSize()); 196 core::dimension2d<s32> dim(Driver->getScreenSize());
197 if (AbsoluteRect.LowerRightCorner.X != dim.Width || 197 if (AbsoluteRect.LowerRightCorner.X != dim.Width ||
198 AbsoluteRect.LowerRightCorner.Y != dim.Height) 198 AbsoluteRect.LowerRightCorner.Y != dim.Height)
199 { 199 {
200 // resize gui environment 200 // resize gui environment
201 DesiredRect.LowerRightCorner = dim; 201 DesiredRect.LowerRightCorner = dim;
202 AbsoluteClippingRect = DesiredRect; 202 AbsoluteClippingRect = DesiredRect;
203 AbsoluteRect = DesiredRect; 203 AbsoluteRect = DesiredRect;
204 updateAbsolutePosition(); 204 updateAbsolutePosition();
205 } 205 }
206 } 206 }
207 207
208 // make sure tooltip is always on top 208 // make sure tooltip is always on top
209 if (ToolTip.Element) 209 if (ToolTip.Element)
210 bringToFront(ToolTip.Element); 210 bringToFront(ToolTip.Element);
211 211
212 draw(); 212 draw();
213 OnPostRender ( os::Timer::getTime () ); 213 OnPostRender ( os::Timer::getTime () );
214} 214}
215 215
216 216
217//! sets the focus to an element 217//! sets the focus to an element
218bool CGUIEnvironment::setFocus(IGUIElement* element) 218bool CGUIEnvironment::setFocus(IGUIElement* element)
219{ 219{
220 if (Focus == element) 220 if (Focus == element)
221 { 221 {
222 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 222 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
223 return false; 223 return false;
224 } 224 }
225 225
226 // GUI Environment should not get the focus 226 // GUI Environment should not get the focus
227 if (element == this) 227 if (element == this)
228 element = 0; 228 element = 0;
229 229
230 // stop element from being deleted 230 // stop element from being deleted
231 if (element) 231 if (element)
232 element->grab(); 232 element->grab();
233 233
234 // focus may change or be removed in this call 234 // focus may change or be removed in this call
235 IGUIElement *currentFocus = 0; 235 IGUIElement *currentFocus = 0;
236 if (Focus) 236 if (Focus)
237 { 237 {
238 currentFocus = Focus; 238 currentFocus = Focus;
239 currentFocus->grab(); 239 currentFocus->grab();
240 SEvent e; 240 SEvent e;
241 e.EventType = EET_GUI_EVENT; 241 e.EventType = EET_GUI_EVENT;
242 e.GUIEvent.Caller = Focus; 242 e.GUIEvent.Caller = Focus;
243 e.GUIEvent.Element = element; 243 e.GUIEvent.Element = element;
244 e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST; 244 e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST;
245 if (Focus->OnEvent(e)) 245 if (Focus->OnEvent(e))
246 { 246 {
247 if (element) 247 if (element)
248 element->drop(); 248 element->drop();
249 currentFocus->drop(); 249 currentFocus->drop();
250 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 250 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
251 return false; 251 return false;
252 } 252 }
253 currentFocus->drop(); 253 currentFocus->drop();
254 currentFocus = 0; 254 currentFocus = 0;
255 } 255 }
256 256
257 if (element) 257 if (element)
258 { 258 {
259 currentFocus = Focus; 259 currentFocus = Focus;
260 if (currentFocus) 260 if (currentFocus)
261 currentFocus->grab(); 261 currentFocus->grab();
262 262
263 // send focused event 263 // send focused event
264 SEvent e; 264 SEvent e;
265 e.EventType = EET_GUI_EVENT; 265 e.EventType = EET_GUI_EVENT;
266 e.GUIEvent.Caller = element; 266 e.GUIEvent.Caller = element;
267 e.GUIEvent.Element = Focus; 267 e.GUIEvent.Element = Focus;
268 e.GUIEvent.EventType = EGET_ELEMENT_FOCUSED; 268 e.GUIEvent.EventType = EGET_ELEMENT_FOCUSED;
269 if (element->OnEvent(e)) 269 if (element->OnEvent(e))
270 { 270 {
271 if (element) 271 if (element)
272 element->drop(); 272 element->drop();
273 if (currentFocus) 273 if (currentFocus)
274 currentFocus->drop(); 274 currentFocus->drop();
275 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 275 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
276 return false; 276 return false;
277 } 277 }
278 } 278 }
279 279
280 if (currentFocus) 280 if (currentFocus)
281 currentFocus->drop(); 281 currentFocus->drop();
282 282
283 if (Focus) 283 if (Focus)
284 Focus->drop(); 284 Focus->drop();
285 285
286 // element is the new focus so it doesn't have to be dropped 286 // element is the new focus so it doesn't have to be dropped
287 Focus = element; 287 Focus = element;
288 288
289 return true; 289 return true;
290} 290}
291 291
292 292
293//! returns the element with the focus 293//! returns the element with the focus
294IGUIElement* CGUIEnvironment::getFocus() const 294IGUIElement* CGUIEnvironment::getFocus() const
295{ 295{
296 return Focus; 296 return Focus;
297} 297}
298 298
299//! returns the element last known to be under the mouse cursor 299//! returns the element last known to be under the mouse cursor
300IGUIElement* CGUIEnvironment::getHovered() const 300IGUIElement* CGUIEnvironment::getHovered() const
301{ 301{
302 return Hovered; 302 return Hovered;
303} 303}
304 304
305 305
306//! removes the focus from an element 306//! removes the focus from an element
307bool CGUIEnvironment::removeFocus(IGUIElement* element) 307bool CGUIEnvironment::removeFocus(IGUIElement* element)
308{ 308{
309 if (Focus && Focus==element) 309 if (Focus && Focus==element)
310 { 310 {
311 SEvent e; 311 SEvent e;
312 e.EventType = EET_GUI_EVENT; 312 e.EventType = EET_GUI_EVENT;
313 e.GUIEvent.Caller = Focus; 313 e.GUIEvent.Caller = Focus;
314 e.GUIEvent.Element = 0; 314 e.GUIEvent.Element = 0;
315 e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST; 315 e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST;
316 if (Focus->OnEvent(e)) 316 if (Focus->OnEvent(e))
317 { 317 {
318 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 318 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
319 return false; 319 return false;
320 } 320 }
321 } 321 }
322 if (Focus) 322 if (Focus)
323 { 323 {
324 Focus->drop(); 324 Focus->drop();
325 Focus = 0; 325 Focus = 0;
326 } 326 }
327 327
328 return true; 328 return true;
329} 329}
330 330
331 331
332//! Returns if the element has focus 332//! Returns if the element has focus
333bool CGUIEnvironment::hasFocus(IGUIElement* element) const 333bool CGUIEnvironment::hasFocus(IGUIElement* element) const
334{ 334{
335 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 335 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
336 return (element == Focus); 336 return (element == Focus);
337} 337}
338 338
339 339
340//! returns the current video driver 340//! returns the current video driver
341video::IVideoDriver* CGUIEnvironment::getVideoDriver() const 341video::IVideoDriver* CGUIEnvironment::getVideoDriver() const
342{ 342{
343 return Driver; 343 return Driver;
344} 344}
345 345
346 346
347//! returns the current file system 347//! returns the current file system
348io::IFileSystem* CGUIEnvironment::getFileSystem() const 348io::IFileSystem* CGUIEnvironment::getFileSystem() const
349{ 349{
350 return FileSystem; 350 return FileSystem;
351} 351}
352 352
353 353
354//! returns a pointer to the OS operator 354//! returns a pointer to the OS operator
355IOSOperator* CGUIEnvironment::getOSOperator() const 355IOSOperator* CGUIEnvironment::getOSOperator() const
356{ 356{
357 return Operator; 357 return Operator;
358} 358}
359 359
360 360
361//! clear all GUI elements 361//! clear all GUI elements
362void CGUIEnvironment::clear() 362void CGUIEnvironment::clear()
363{ 363{
364 // Remove the focus 364 // Remove the focus
365 if (Focus) 365 if (Focus)
366 { 366 {
367 Focus->drop(); 367 Focus->drop();
368 Focus = 0; 368 Focus = 0;
369 } 369 }
370 370
371 if (Hovered && Hovered != this) 371 if (Hovered && Hovered != this)
372 { 372 {
373 Hovered->drop(); 373 Hovered->drop();
374 Hovered = 0; 374 Hovered = 0;
375 } 375 }
376 if ( HoveredNoSubelement && HoveredNoSubelement != this) 376 if ( HoveredNoSubelement && HoveredNoSubelement != this)
377 { 377 {
378 HoveredNoSubelement->drop(); 378 HoveredNoSubelement->drop();
379 HoveredNoSubelement = 0; 379 HoveredNoSubelement = 0;
380 } 380 }
381 381
382 // get the root's children in case the root changes in future 382 // get the root's children in case the root changes in future
383 const core::list<IGUIElement*>& children = getRootGUIElement()->getChildren(); 383 const core::list<IGUIElement*>& children = getRootGUIElement()->getChildren();
384 384
385 while (!children.empty()) 385 while (!children.empty())
386 (*children.getLast())->remove(); 386 (*children.getLast())->remove();
387} 387}
388 388
389 389
390//! called by ui if an event happened. 390//! called by ui if an event happened.
391bool CGUIEnvironment::OnEvent(const SEvent& event) 391bool CGUIEnvironment::OnEvent(const SEvent& event)
392{ 392{
393 bool ret = false; 393 bool ret = false;
394 if (UserReceiver 394 if (UserReceiver
395 && (event.EventType != EET_MOUSE_INPUT_EVENT) 395 && (event.EventType != EET_MOUSE_INPUT_EVENT)
396 && (event.EventType != EET_KEY_INPUT_EVENT) 396 && (event.EventType != EET_KEY_INPUT_EVENT)
397 && (event.EventType != EET_GUI_EVENT || event.GUIEvent.Caller != this)) 397 && (event.EventType != EET_GUI_EVENT || event.GUIEvent.Caller != this))
398 { 398 {
399 ret = UserReceiver->OnEvent(event); 399 ret = UserReceiver->OnEvent(event);
400 } 400 }
401 401
402 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 402 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
403 return ret; 403 return ret;
404} 404}
405 405
406// 406//
407void CGUIEnvironment::OnPostRender( u32 time ) 407void CGUIEnvironment::OnPostRender( u32 time )
408{ 408{
409 // launch tooltip 409 // launch tooltip
410 if ( ToolTip.Element == 0 && 410 if ( ToolTip.Element == 0 &&
411 HoveredNoSubelement && HoveredNoSubelement != this && 411 HoveredNoSubelement && HoveredNoSubelement != this &&
412 (time - ToolTip.EnterTime >= ToolTip.LaunchTime 412 (time - ToolTip.EnterTime >= ToolTip.LaunchTime
413 || (time - ToolTip.LastTime >= ToolTip.RelaunchTime && time - ToolTip.LastTime < ToolTip.LaunchTime)) && 413 || (time - ToolTip.LastTime >= ToolTip.RelaunchTime && time - ToolTip.LastTime < ToolTip.LaunchTime)) &&
414 HoveredNoSubelement->getToolTipText().size() && 414 HoveredNoSubelement->getToolTipText().size() &&
415 getSkin() && 415 getSkin() &&
416 getSkin()->getFont(EGDF_TOOLTIP) 416 getSkin()->getFont(EGDF_TOOLTIP)
417 ) 417 )
418 { 418 {
419 core::rect<s32> pos; 419 core::rect<s32> pos;
420 420
421 pos.UpperLeftCorner = LastHoveredMousePos; 421 pos.UpperLeftCorner = LastHoveredMousePos;
422 core::dimension2du dim = getSkin()->getFont(EGDF_TOOLTIP)->getDimension(HoveredNoSubelement->getToolTipText().c_str()); 422 core::dimension2du dim = getSkin()->getFont(EGDF_TOOLTIP)->getDimension(HoveredNoSubelement->getToolTipText().c_str());
423 dim.Width += getSkin()->getSize(EGDS_TEXT_DISTANCE_X)*2; 423 dim.Width += getSkin()->getSize(EGDS_TEXT_DISTANCE_X)*2;
424 dim.Height += getSkin()->getSize(EGDS_TEXT_DISTANCE_Y)*2; 424 dim.Height += getSkin()->getSize(EGDS_TEXT_DISTANCE_Y)*2;
425 425
426 pos.UpperLeftCorner.Y -= dim.Height+1; 426 pos.UpperLeftCorner.Y -= dim.Height+1;
427 pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + dim.Height-1; 427 pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + dim.Height-1;
428 pos.LowerRightCorner.X = pos.UpperLeftCorner.X + dim.Width; 428 pos.LowerRightCorner.X = pos.UpperLeftCorner.X + dim.Width;
429 429
430 pos.constrainTo(getAbsolutePosition()); 430 pos.constrainTo(getAbsolutePosition());
431 431
432 ToolTip.Element = addStaticText(HoveredNoSubelement->getToolTipText().c_str(), pos, true, true, this, -1, true); 432 ToolTip.Element = addStaticText(HoveredNoSubelement->getToolTipText().c_str(), pos, true, true, this, -1, true);
433 ToolTip.Element->setOverrideColor(getSkin()->getColor(EGDC_TOOLTIP)); 433 ToolTip.Element->setOverrideColor(getSkin()->getColor(EGDC_TOOLTIP));
434 ToolTip.Element->setBackgroundColor(getSkin()->getColor(EGDC_TOOLTIP_BACKGROUND)); 434 ToolTip.Element->setBackgroundColor(getSkin()->getColor(EGDC_TOOLTIP_BACKGROUND));
435 ToolTip.Element->setOverrideFont(getSkin()->getFont(EGDF_TOOLTIP)); 435 ToolTip.Element->setOverrideFont(getSkin()->getFont(EGDF_TOOLTIP));
436 ToolTip.Element->setSubElement(true); 436 ToolTip.Element->setSubElement(true);
437 ToolTip.Element->grab(); 437 ToolTip.Element->grab();
438 438
439 s32 textHeight = ToolTip.Element->getTextHeight(); 439 s32 textHeight = ToolTip.Element->getTextHeight();
440 pos = ToolTip.Element->getRelativePosition(); 440 pos = ToolTip.Element->getRelativePosition();
441 pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + textHeight; 441 pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + textHeight;
442 ToolTip.Element->setRelativePosition(pos); 442 ToolTip.Element->setRelativePosition(pos);
443 } 443 }
444 444
445 if (ToolTip.Element && ToolTip.Element->isVisible() ) // (isVisible() check only because we might use visibility for ToolTip one day) 445 if (ToolTip.Element && ToolTip.Element->isVisible() ) // (isVisible() check only because we might use visibility for ToolTip one day)
446 { 446 {
447 ToolTip.LastTime = time; 447 ToolTip.LastTime = time;
448 448
449 // got invisible or removed in the meantime? 449 // got invisible or removed in the meantime?
450 if ( !HoveredNoSubelement || 450 if ( !HoveredNoSubelement ||
451 !HoveredNoSubelement->isVisible() || 451 !HoveredNoSubelement->isVisible() ||
452 !HoveredNoSubelement->getParent() 452 !HoveredNoSubelement->getParent()
453 ) // got invisible or removed in the meantime? 453 ) // got invisible or removed in the meantime?
454 { 454 {
455 ToolTip.Element->remove(); 455 ToolTip.Element->remove();
456 ToolTip.Element->drop(); 456 ToolTip.Element->drop();
457 ToolTip.Element = 0; 457 ToolTip.Element = 0;
458 } 458 }
459 } 459 }
460 460
461 IGUIElement::OnPostRender ( time ); 461 IGUIElement::OnPostRender ( time );
462} 462}
463 463
464 464
465// 465//
466void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos) 466void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos)
467{ 467{
468 IGUIElement* lastHovered = Hovered; 468 IGUIElement* lastHovered = Hovered;
469 IGUIElement* lastHoveredNoSubelement = HoveredNoSubelement; 469 IGUIElement* lastHoveredNoSubelement = HoveredNoSubelement;
470 LastHoveredMousePos = mousePos; 470 LastHoveredMousePos = mousePos;
471 471
472 Hovered = getElementFromPoint(mousePos); 472 Hovered = getElementFromPoint(mousePos);
473 473
474 if ( ToolTip.Element && Hovered == ToolTip.Element ) 474 if ( ToolTip.Element && Hovered == ToolTip.Element )
475 { 475 {
476 // When the mouse is over the ToolTip we remove that so it will be re-created at a new position. 476 // When the mouse is over the ToolTip we remove that so it will be re-created at a new position.
477 // Note that ToolTip.EnterTime does not get changed here, so it will be re-created at once. 477 // Note that ToolTip.EnterTime does not get changed here, so it will be re-created at once.
478 ToolTip.Element->remove(); 478 ToolTip.Element->remove();
479 ToolTip.Element->drop(); 479 ToolTip.Element->drop();
480 ToolTip.Element = 0; 480 ToolTip.Element = 0;
481 481
482 // Get the real Hovered 482 // Get the real Hovered
483 Hovered = getElementFromPoint(mousePos); 483 Hovered = getElementFromPoint(mousePos);
484 } 484 }
485 485
486 // for tooltips we want the element itself and not some of it's subelements 486 // for tooltips we want the element itself and not some of it's subelements
487 HoveredNoSubelement = Hovered; 487 HoveredNoSubelement = Hovered;
488 while ( HoveredNoSubelement && HoveredNoSubelement->isSubElement() ) 488 while ( HoveredNoSubelement && HoveredNoSubelement->isSubElement() )
489 { 489 {
490 HoveredNoSubelement = HoveredNoSubelement->getParent(); 490 HoveredNoSubelement = HoveredNoSubelement->getParent();
491 } 491 }
492 492
493 if (Hovered && Hovered != this) 493 if (Hovered && Hovered != this)
494 Hovered->grab(); 494 Hovered->grab();
495 if ( HoveredNoSubelement && HoveredNoSubelement != this) 495 if ( HoveredNoSubelement && HoveredNoSubelement != this)
496 HoveredNoSubelement->grab(); 496 HoveredNoSubelement->grab();
497 497
498 if (Hovered != lastHovered) 498 if (Hovered != lastHovered)
499 { 499 {
500 SEvent event; 500 SEvent event;
501 event.EventType = EET_GUI_EVENT; 501 event.EventType = EET_GUI_EVENT;
502 502
503 if (lastHovered) 503 if (lastHovered)
504 { 504 {
505 event.GUIEvent.Caller = lastHovered; 505 event.GUIEvent.Caller = lastHovered;
506 event.GUIEvent.Element = 0; 506 event.GUIEvent.Element = 0;
507 event.GUIEvent.EventType = EGET_ELEMENT_LEFT; 507 event.GUIEvent.EventType = EGET_ELEMENT_LEFT;
508 lastHovered->OnEvent(event); 508 lastHovered->OnEvent(event);
509 } 509 }
510 510
511 if ( Hovered ) 511 if ( Hovered )
512 { 512 {
513 event.GUIEvent.Caller = Hovered; 513 event.GUIEvent.Caller = Hovered;
514 event.GUIEvent.Element = Hovered; 514 event.GUIEvent.Element = Hovered;
515 event.GUIEvent.EventType = EGET_ELEMENT_HOVERED; 515 event.GUIEvent.EventType = EGET_ELEMENT_HOVERED;
516 Hovered->OnEvent(event); 516 Hovered->OnEvent(event);
517 } 517 }
518 } 518 }
519 519
520 if ( lastHoveredNoSubelement != HoveredNoSubelement ) 520 if ( lastHoveredNoSubelement != HoveredNoSubelement )
521 { 521 {
522 if (ToolTip.Element) 522 if (ToolTip.Element)
523 { 523 {
524 ToolTip.Element->remove(); 524 ToolTip.Element->remove();
525 ToolTip.Element->drop(); 525 ToolTip.Element->drop();
526 ToolTip.Element = 0; 526 ToolTip.Element = 0;
527 } 527 }
528 528
529 if ( HoveredNoSubelement ) 529 if ( HoveredNoSubelement )
530 { 530 {
531 u32 now = os::Timer::getTime(); 531 u32 now = os::Timer::getTime();
532 ToolTip.EnterTime = now; 532 ToolTip.EnterTime = now;
533 } 533 }
534 } 534 }
535 535
536 if (lastHovered && lastHovered != this) 536 if (lastHovered && lastHovered != this)
537 lastHovered->drop(); 537 lastHovered->drop();
538 if (lastHoveredNoSubelement && lastHoveredNoSubelement != this) 538 if (lastHoveredNoSubelement && lastHoveredNoSubelement != this)
539 lastHoveredNoSubelement->drop(); 539 lastHoveredNoSubelement->drop();
540} 540}
541 541
542 542
543//! This sets a new event receiver for gui events. Usually you do not have to 543//! This sets a new event receiver for gui events. Usually you do not have to
544//! use this method, it is used by the internal engine. 544//! use this method, it is used by the internal engine.
545void CGUIEnvironment::setUserEventReceiver(IEventReceiver* evr) 545void CGUIEnvironment::setUserEventReceiver(IEventReceiver* evr)
546{ 546{
547 UserReceiver = evr; 547 UserReceiver = evr;
548} 548}
549 549
550 550
551//! posts an input event to the environment 551//! posts an input event to the environment
552bool CGUIEnvironment::postEventFromUser(const SEvent& event) 552bool CGUIEnvironment::postEventFromUser(const SEvent& event)
553{ 553{
554 switch(event.EventType) 554 switch(event.EventType)
555 { 555 {
556 case EET_GUI_EVENT: 556 case EET_GUI_EVENT:
557 // hey, why is the user sending gui events..? 557 // hey, why is the user sending gui events..?
558 break; 558 break;
559 case EET_MOUSE_INPUT_EVENT: 559 case EET_MOUSE_INPUT_EVENT:
560 560
561 updateHoveredElement(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)); 561 updateHoveredElement(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
562 562
563 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) 563 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
564 if ( (Hovered && Hovered != Focus) || !Focus ) 564 if ( (Hovered && Hovered != Focus) || !Focus )
565 { 565 {
566 setFocus(Hovered); 566 setFocus(Hovered);
567 } 567 }
568 568
569 // sending input to focus 569 // sending input to focus
570 if (Focus && Focus->OnEvent(event)) 570 if (Focus && Focus->OnEvent(event))
571 return true; 571 return true;
572 572
573 // focus could have died in last call 573 // focus could have died in last call
574 if (!Focus && Hovered) 574 if (!Focus && Hovered)
575 { 575 {
576 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 576 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
577 return Hovered->OnEvent(event); 577 return Hovered->OnEvent(event);
578 } 578 }
579 579
580 break; 580 break;
581 case EET_KEY_INPUT_EVENT: 581 case EET_KEY_INPUT_EVENT:
582 { 582 {
583 if (Focus && Focus->OnEvent(event)) 583 if (Focus && Focus->OnEvent(event))
584 return true; 584 return true;
585 585
586 // For keys we handle the event before changing focus to give elements the chance for catching the TAB 586 // For keys we handle the event before changing focus to give elements the chance for catching the TAB
587 // Send focus changing event 587 // Send focus changing event
588 if (event.EventType == EET_KEY_INPUT_EVENT && 588 if (event.EventType == EET_KEY_INPUT_EVENT &&
589 event.KeyInput.PressedDown && 589 event.KeyInput.PressedDown &&
590 event.KeyInput.Key == KEY_TAB) 590 event.KeyInput.Key == KEY_TAB)
591 { 591 {
592 IGUIElement *next = getNextElement(event.KeyInput.Shift, event.KeyInput.Control); 592 IGUIElement *next = getNextElement(event.KeyInput.Shift, event.KeyInput.Control);
593 if (next && next != Focus) 593 if (next && next != Focus)
594 { 594 {
595 if (setFocus(next)) 595 if (setFocus(next))
596 return true; 596 return true;
597 } 597 }
598 } 598 }
599 599
600 } 600 }
601 break; 601 break;
602 default: 602 default:
603 break; 603 break;
604 } // end switch 604 } // end switch
605 605
606 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 606 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
607 return false; 607 return false;
608} 608}
609 609
610 610
611//! returns the current gui skin 611//! returns the current gui skin
612IGUISkin* CGUIEnvironment::getSkin() const 612IGUISkin* CGUIEnvironment::getSkin() const
613{ 613{
614 return CurrentSkin; 614 return CurrentSkin;
615} 615}
616 616
617 617
618//! Sets a new GUI Skin 618//! Sets a new GUI Skin
619void CGUIEnvironment::setSkin(IGUISkin* skin) 619void CGUIEnvironment::setSkin(IGUISkin* skin)
620{ 620{
621 if (CurrentSkin==skin) 621 if (CurrentSkin==skin)
622 return; 622 return;
623 623
624 if (CurrentSkin) 624 if (CurrentSkin)
625 CurrentSkin->drop(); 625 CurrentSkin->drop();
626 626
627 CurrentSkin = skin; 627 CurrentSkin = skin;
628 628
629 if (CurrentSkin) 629 if (CurrentSkin)
630 CurrentSkin->grab(); 630 CurrentSkin->grab();
631} 631}
632 632
633 633
634//! Creates a new GUI Skin based on a template. 634//! Creates a new GUI Skin based on a template.
635/** \return Returns a pointer to the created skin. 635/** \return Returns a pointer to the created skin.
636If you no longer need the skin, you should call IGUISkin::drop(). 636If you no longer need the skin, you should call IGUISkin::drop().
637See IReferenceCounted::drop() for more information. */ 637See IReferenceCounted::drop() for more information. */
638IGUISkin* CGUIEnvironment::createSkin(EGUI_SKIN_TYPE type) 638IGUISkin* CGUIEnvironment::createSkin(EGUI_SKIN_TYPE type)
639{ 639{
640 IGUISkin* skin = new CGUISkin(type, Driver); 640 IGUISkin* skin = new CGUISkin(type, Driver);
641 641
642 IGUIFont* builtinfont = getBuiltInFont(); 642 IGUIFont* builtinfont = getBuiltInFont();
643 IGUIFontBitmap* bitfont = 0; 643 IGUIFontBitmap* bitfont = 0;
644 if (builtinfont && builtinfont->getType() == EGFT_BITMAP) 644 if (builtinfont && builtinfont->getType() == EGFT_BITMAP)
645 bitfont = (IGUIFontBitmap*)builtinfont; 645 bitfont = (IGUIFontBitmap*)builtinfont;
646 646
647 IGUISpriteBank* bank = 0; 647 IGUISpriteBank* bank = 0;
648 skin->setFont(builtinfont); 648 skin->setFont(builtinfont);
649 649
650 if (bitfont) 650 if (bitfont)
651 bank = bitfont->getSpriteBank(); 651 bank = bitfont->getSpriteBank();
652 652
653 skin->setSpriteBank(bank); 653 skin->setSpriteBank(bank);
654 654
655 return skin; 655 return skin;
656} 656}
657 657
658 658
659//! Returns the default element factory which can create all built in elements 659//! Returns the default element factory which can create all built in elements
660IGUIElementFactory* CGUIEnvironment::getDefaultGUIElementFactory() const 660IGUIElementFactory* CGUIEnvironment::getDefaultGUIElementFactory() const
661{ 661{
662 return getGUIElementFactory(0); 662 return getGUIElementFactory(0);
663} 663}
664 664
665 665
666//! Adds an element factory to the gui environment. 666//! Adds an element factory to the gui environment.
667/** Use this to extend the gui environment with new element types which it should be 667/** Use this to extend the gui environment with new element types which it should be
668able to create automaticly, for example when loading data from xml files. */ 668able to create automaticly, for example when loading data from xml files. */
669void CGUIEnvironment::registerGUIElementFactory(IGUIElementFactory* factoryToAdd) 669void CGUIEnvironment::registerGUIElementFactory(IGUIElementFactory* factoryToAdd)
670{ 670{
671 if (factoryToAdd) 671 if (factoryToAdd)
672 { 672 {
673 factoryToAdd->grab(); 673 factoryToAdd->grab();
674 GUIElementFactoryList.push_back(factoryToAdd); 674 GUIElementFactoryList.push_back(factoryToAdd);
675 } 675 }
676} 676}
677 677
678 678
679//! Returns amount of registered scene node factories. 679//! Returns amount of registered scene node factories.
680u32 CGUIEnvironment::getRegisteredGUIElementFactoryCount() const 680u32 CGUIEnvironment::getRegisteredGUIElementFactoryCount() const
681{ 681{
682 return GUIElementFactoryList.size(); 682 return GUIElementFactoryList.size();
683} 683}
684 684
685 685
686//! Returns a scene node factory by index 686//! Returns a scene node factory by index
687IGUIElementFactory* CGUIEnvironment::getGUIElementFactory(u32 index) const 687IGUIElementFactory* CGUIEnvironment::getGUIElementFactory(u32 index) const
688{ 688{
689 if (index < GUIElementFactoryList.size()) 689 if (index < GUIElementFactoryList.size())
690 return GUIElementFactoryList[index]; 690 return GUIElementFactoryList[index];
691 else 691 else
692 return 0; 692 return 0;
693} 693}
694 694
695 695
696//! adds a GUI Element using its name 696//! adds a GUI Element using its name
697IGUIElement* CGUIEnvironment::addGUIElement(const c8* elementName, IGUIElement* parent) 697IGUIElement* CGUIEnvironment::addGUIElement(const c8* elementName, IGUIElement* parent)
698{ 698{
699 IGUIElement* node=0; 699 IGUIElement* node=0;
700 700
701 if (!parent) 701 if (!parent)
702 parent = this; 702 parent = this;
703 703
704 for (s32 i=GUIElementFactoryList.size()-1; i>=0 && !node; --i) 704 for (s32 i=GUIElementFactoryList.size()-1; i>=0 && !node; --i)
705 node = GUIElementFactoryList[i]->addGUIElement(elementName, parent); 705 node = GUIElementFactoryList[i]->addGUIElement(elementName, parent);
706 706
707 707
708 return node; 708 return node;
709} 709}
710 710
711 711
712//! Saves the current gui into a file. 712//! Saves the current gui into a file.
713//! \param filename: Name of the file . 713//! \param filename: Name of the file .
714bool CGUIEnvironment::saveGUI(const io::path& filename, IGUIElement* start) 714bool CGUIEnvironment::saveGUI(const io::path& filename, IGUIElement* start)
715{ 715{
716 io::IWriteFile* file = FileSystem->createAndWriteFile(filename); 716 io::IWriteFile* file = FileSystem->createAndWriteFile(filename);
717 if (!file) 717 if (!file)
718 { 718 {
719 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 719 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
720 return false; 720 return false;
721 } 721 }
722 722
723 bool ret = saveGUI(file, start); 723 bool ret = saveGUI(file, start);
724 file->drop(); 724 file->drop();
725 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 725 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
726 return ret; 726 return ret;
727} 727}
728 728
729 729
730//! Saves the current gui into a file. 730//! Saves the current gui into a file.
731bool CGUIEnvironment::saveGUI(io::IWriteFile* file, IGUIElement* start) 731bool CGUIEnvironment::saveGUI(io::IWriteFile* file, IGUIElement* start)
732{ 732{
733 if (!file) 733 if (!file)
734 { 734 {
735 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 735 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
736 return false; 736 return false;
737 } 737 }
738 738
739 io::IXMLWriter* writer = FileSystem->createXMLWriter(file); 739 io::IXMLWriter* writer = FileSystem->createXMLWriter(file);
740 if (!writer) 740 if (!writer)
741 { 741 {
742 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 742 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
743 return false; 743 return false;
744 } 744 }
745 745
746 writer->writeXMLHeader(); 746 writer->writeXMLHeader();
747 writeGUIElement(writer, start ? start : this); 747 writeGUIElement(writer, start ? start : this);
748 writer->drop(); 748 writer->drop();
749 749
750 return true; 750 return true;
751} 751}
752 752
753 753
754//! Loads the gui. Note that the current gui is not cleared before. 754//! Loads the gui. Note that the current gui is not cleared before.
755//! \param filename: Name of the file. 755//! \param filename: Name of the file.
756bool CGUIEnvironment::loadGUI(const io::path& filename, IGUIElement* parent) 756bool CGUIEnvironment::loadGUI(const io::path& filename, IGUIElement* parent)
757{ 757{
758 io::IReadFile* read = FileSystem->createAndOpenFile(filename); 758 io::IReadFile* read = FileSystem->createAndOpenFile(filename);
759 if (!read) 759 if (!read)
760 { 760 {
761 os::Printer::log("Unable to open gui file", filename, ELL_ERROR); 761 os::Printer::log("Unable to open gui file", filename, ELL_ERROR);
762 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 762 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
763 return false; 763 return false;
764 } 764 }
765 765
766 bool ret = loadGUI(read, parent); 766 bool ret = loadGUI(read, parent);
767 read->drop(); 767 read->drop();
768 768
769 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 769 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
770 return ret; 770 return ret;
771} 771}
772 772
773 773
774//! Loads the gui. Note that the current gui is not cleared before. 774//! Loads the gui. Note that the current gui is not cleared before.
775bool CGUIEnvironment::loadGUI(io::IReadFile* file, IGUIElement* parent) 775bool CGUIEnvironment::loadGUI(io::IReadFile* file, IGUIElement* parent)
776{ 776{
777 if (!file) 777 if (!file)
778 { 778 {
779 os::Printer::log("Unable to open GUI file", ELL_ERROR); 779 os::Printer::log("Unable to open GUI file", ELL_ERROR);
780 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 780 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
781 return false; 781 return false;
782 } 782 }
783 783
784 io::IXMLReader* reader = FileSystem->createXMLReader(file); 784 io::IXMLReader* reader = FileSystem->createXMLReader(file);
785 if (!reader) 785 if (!reader)
786 { 786 {
787 os::Printer::log("GUI is not a valid XML file", file->getFileName(), ELL_ERROR); 787 os::Printer::log("GUI is not a valid XML file", file->getFileName(), ELL_ERROR);
788 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 788 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
789 return false; 789 return false;
790 } 790 }
791 791
792 // read file 792 // read file
793 while(reader->read()) 793 while(reader->read())
794 { 794 {
795 readGUIElement(reader, parent); 795 readGUIElement(reader, parent);
796 } 796 }
797 797
798 // finish up 798 // finish up
799 799
800 reader->drop(); 800 reader->drop();
801 return true; 801 return true;
802} 802}
803 803
804 804
805//! reads an element 805//! reads an element
806void CGUIEnvironment::readGUIElement(io::IXMLReader* reader, IGUIElement* node) 806void CGUIEnvironment::readGUIElement(io::IXMLReader* reader, IGUIElement* node)
807{ 807{
808 if (!reader) 808 if (!reader)
809 return; 809 return;
810 810
811 io::EXML_NODE nodeType = reader->getNodeType(); 811 io::EXML_NODE nodeType = reader->getNodeType();
812 812
813 if (nodeType == io::EXN_NONE || nodeType == io::EXN_UNKNOWN || nodeType == io::EXN_ELEMENT_END) 813 if (nodeType == io::EXN_NONE || nodeType == io::EXN_UNKNOWN || nodeType == io::EXN_ELEMENT_END)
814 return; 814 return;
815 815
816 IGUIElement* deferedNode = 0; 816 IGUIElement* deferedNode = 0;
817 if (!wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName())) 817 if (!wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName()))
818 { 818 {
819 // GuiEnvironment always must be this as it would serialize into a wrong element otherwise. 819 // GuiEnvironment always must be this as it would serialize into a wrong element otherwise.
820 // So we use the given node next time 820 // So we use the given node next time
821 if ( node && node != this ) 821 if ( node && node != this )
822 deferedNode = node; 822 deferedNode = node;
823 node = this; // root 823 node = this; // root
824 } 824 }
825 else if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName())) 825 else if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName()))
826 { 826 {
827 // find node type and create it 827 // find node type and create it
828 const core::stringc attrName = reader->getAttributeValue(IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE); 828 const core::stringc attrName = reader->getAttributeValue(IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE);
829 829
830 node = addGUIElement(attrName.c_str(), node); 830 node = addGUIElement(attrName.c_str(), node);
831 831
832 if (!node) 832 if (!node)
833 os::Printer::log("Could not create GUI element of unknown type", attrName.c_str()); 833 os::Printer::log("Could not create GUI element of unknown type", attrName.c_str());
834 } 834 }
835 835
836 // read attributes 836 // read attributes
837 837
838 while(reader->read()) 838 while(reader->read())
839 { 839 {
840 bool endreached = false; 840 bool endreached = false;
841 841
842 switch (reader->getNodeType()) 842 switch (reader->getNodeType())
843 { 843 {
844 case io::EXN_ELEMENT_END: 844 case io::EXN_ELEMENT_END:
845 if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName()) || 845 if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName()) ||
846 !wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName())) 846 !wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName()))
847 { 847 {
848 endreached = true; 848 endreached = true;
849 } 849 }
850 break; 850 break;
851 case io::EXN_ELEMENT: 851 case io::EXN_ELEMENT:
852 if (!wcscmp(L"attributes", reader->getNodeName())) 852 if (!wcscmp(L"attributes", reader->getNodeName()))
853 { 853 {
854 // read attributes 854 // read attributes
855 io::IAttributes* attr = FileSystem->createEmptyAttributes(Driver); 855 io::IAttributes* attr = FileSystem->createEmptyAttributes(Driver);
856 attr->read(reader, true); 856 attr->read(reader, true);
857 857
858 if (node) 858 if (node)
859 node->deserializeAttributes(attr); 859 node->deserializeAttributes(attr);
860 860
861 attr->drop(); 861 attr->drop();
862 } 862 }
863 else 863 else
864 if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName()) || 864 if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName()) ||
865 !wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName())) 865 !wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName()))
866 { 866 {
867 if ( deferedNode ) 867 if ( deferedNode )
868 readGUIElement(reader, deferedNode); 868 readGUIElement(reader, deferedNode);
869 else 869 else
870 readGUIElement(reader, node); 870 readGUIElement(reader, node);
871 } 871 }
872 else 872 else
873 { 873 {
874 os::Printer::log("Found unknown element in irrlicht GUI file", 874 os::Printer::log("Found unknown element in irrlicht GUI file",
875 core::stringc(reader->getNodeName()).c_str()); 875 core::stringc(reader->getNodeName()).c_str());
876 } 876 }
877 877
878 break; 878 break;
879 default: 879 default:
880 break; 880 break;
881 } 881 }
882 882
883 if (endreached) 883 if (endreached)
884 break; 884 break;
885 } 885 }
886} 886}
887 887
888 888
889//! writes an element 889//! writes an element
890void CGUIEnvironment::writeGUIElement(io::IXMLWriter* writer, IGUIElement* node) 890void CGUIEnvironment::writeGUIElement(io::IXMLWriter* writer, IGUIElement* node)
891{ 891{
892 if (!writer || !node ) 892 if (!writer || !node )
893 return; 893 return;
894 894
895 const wchar_t* name = 0; 895 const wchar_t* name = 0;
896 896
897 // write properties 897 // write properties
898 898
899 io::IAttributes* attr = FileSystem->createEmptyAttributes(); 899 io::IAttributes* attr = FileSystem->createEmptyAttributes();
900 node->serializeAttributes(attr); 900 node->serializeAttributes(attr);
901 901
902 // all gui elements must have at least one attribute 902 // all gui elements must have at least one attribute
903 // if they have nothing then we ignore them. 903 // if they have nothing then we ignore them.
904 if (attr->getAttributeCount() != 0) 904 if (attr->getAttributeCount() != 0)
905 { 905 {
906 if (node == this) 906 if (node == this)
907 { 907 {
908 name = IRR_XML_FORMAT_GUI_ENV; 908 name = IRR_XML_FORMAT_GUI_ENV;
909 writer->writeElement(name, false); 909 writer->writeElement(name, false);
910 } 910 }
911 else 911 else
912 { 912 {
913 name = IRR_XML_FORMAT_GUI_ELEMENT; 913 name = IRR_XML_FORMAT_GUI_ELEMENT;
914 writer->writeElement(name, false, IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE, 914 writer->writeElement(name, false, IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE,
915 core::stringw(node->getTypeName()).c_str()); 915 core::stringw(node->getTypeName()).c_str());
916 } 916 }
917 917
918 writer->writeLineBreak(); 918 writer->writeLineBreak();
919 writer->writeLineBreak(); 919 writer->writeLineBreak();
920 920
921 attr->write(writer); 921 attr->write(writer);
922 writer->writeLineBreak(); 922 writer->writeLineBreak();
923 } 923 }
924 924
925 // write children 925 // write children
926 926
927 core::list<IGUIElement*>::ConstIterator it = node->getChildren().begin(); 927 core::list<IGUIElement*>::ConstIterator it = node->getChildren().begin();
928 for (; it != node->getChildren().end(); ++it) 928 for (; it != node->getChildren().end(); ++it)
929 { 929 {
930 if (!(*it)->isSubElement()) 930 if (!(*it)->isSubElement())
931 writeGUIElement(writer, (*it)); 931 writeGUIElement(writer, (*it));
932 } 932 }
933 933
934 // write closing brace if required 934 // write closing brace if required
935 if (attr->getAttributeCount() != 0) 935 if (attr->getAttributeCount() != 0)
936 { 936 {
937 writer->writeClosingTag(name); 937 writer->writeClosingTag(name);
938 writer->writeLineBreak(); 938 writer->writeLineBreak();
939 writer->writeLineBreak(); 939 writer->writeLineBreak();
940 } 940 }
941 941
942 attr->drop(); 942 attr->drop();
943} 943}
944 944
945 945
946//! Writes attributes of the environment 946//! Writes attributes of the environment
947void CGUIEnvironment::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const 947void CGUIEnvironment::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
948{ 948{
949 IGUISkin* skin = getSkin(); 949 IGUISkin* skin = getSkin();
950 950
951 if (skin) 951 if (skin)
952 { 952 {
953 out->addEnum("Skin", getSkin()->getType(), GUISkinTypeNames); 953 out->addEnum("Skin", getSkin()->getType(), GUISkinTypeNames);
954 skin->serializeAttributes(out, options); 954 skin->serializeAttributes(out, options);
955 } 955 }
956} 956}
957 957
958 958
959//! Reads attributes of the environment 959//! Reads attributes of the environment
960void CGUIEnvironment::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) 960void CGUIEnvironment::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
961{ 961{
962 if (in->existsAttribute("Skin")) 962 if (in->existsAttribute("Skin"))
963 { 963 {
964 IGUISkin *skin = getSkin(); 964 IGUISkin *skin = getSkin();
965 965
966 EGUI_SKIN_TYPE t = (EGUI_SKIN_TYPE) in->getAttributeAsEnumeration("Skin",GUISkinTypeNames); 966 EGUI_SKIN_TYPE t = (EGUI_SKIN_TYPE) in->getAttributeAsEnumeration("Skin",GUISkinTypeNames);
967 if ( !skin || t != skin->getType()) 967 if ( !skin || t != skin->getType())
968 { 968 {
969 skin = createSkin(t); 969 skin = createSkin(t);
970 setSkin(skin); 970 setSkin(skin);
971 skin->drop(); 971 skin->drop();
972 } 972 }
973 973
974 skin = getSkin(); 974 skin = getSkin();
975 975
976 if (skin) 976 if (skin)
977 { 977 {
978 skin->deserializeAttributes(in, options); 978 skin->deserializeAttributes(in, options);
979 } 979 }
980 980
981 } 981 }
982 982
983 RelativeRect = AbsoluteRect = 983 RelativeRect = AbsoluteRect =
984 core::rect<s32>(core::position2d<s32>(0,0), 984 core::rect<s32>(core::position2d<s32>(0,0),
985 Driver ? core::dimension2di(Driver->getScreenSize()) : core::dimension2d<s32>(0,0)); 985 Driver ? core::dimension2di(Driver->getScreenSize()) : core::dimension2d<s32>(0,0));
986} 986}
987 987
988 988
989//! adds a button. The returned pointer must not be dropped. 989//! adds a button. The returned pointer must not be dropped.
990IGUIButton* CGUIEnvironment::addButton(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text, const wchar_t *tooltiptext) 990IGUIButton* CGUIEnvironment::addButton(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text, const wchar_t *tooltiptext)
991{ 991{
992 IGUIButton* button = new CGUIButton(this, parent ? parent : this, id, rectangle); 992 IGUIButton* button = new CGUIButton(this, parent ? parent : this, id, rectangle);
993 if (text) 993 if (text)
994 button->setText(text); 994 button->setText(text);
995 995
996 if ( tooltiptext ) 996 if ( tooltiptext )
997 button->setToolTipText ( tooltiptext ); 997 button->setToolTipText ( tooltiptext );
998 998
999 button->drop(); 999 button->drop();
1000 return button; 1000 return button;
1001} 1001}
1002 1002
1003 1003
1004//! adds a window. The returned pointer must not be dropped. 1004//! adds a window. The returned pointer must not be dropped.
1005IGUIWindow* CGUIEnvironment::addWindow(const core::rect<s32>& rectangle, bool modal, 1005IGUIWindow* CGUIEnvironment::addWindow(const core::rect<s32>& rectangle, bool modal,
1006 const wchar_t* text, IGUIElement* parent, s32 id) 1006 const wchar_t* text, IGUIElement* parent, s32 id)
1007{ 1007{
1008 parent = parent ? parent : this; 1008 parent = parent ? parent : this;
1009 1009
1010 IGUIWindow* win = new CGUIWindow(this, parent, id, rectangle); 1010 IGUIWindow* win = new CGUIWindow(this, parent, id, rectangle);
1011 if (text) 1011 if (text)
1012 win->setText(text); 1012 win->setText(text);
1013 win->drop(); 1013 win->drop();
1014 1014
1015 if (modal) 1015 if (modal)
1016 { 1016 {
1017 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very 1017 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very
1018 // careful not to get virtual function call, like OnEvent, in the window. 1018 // careful not to get virtual function call, like OnEvent, in the window.
1019 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1); 1019 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1);
1020 modalScreen->drop(); 1020 modalScreen->drop();
1021 modalScreen->addChild(win); 1021 modalScreen->addChild(win);
1022 } 1022 }
1023 1023
1024 return win; 1024 return win;
1025} 1025}
1026 1026
1027 1027
1028//! adds a modal screen. The returned pointer must not be dropped. 1028//! adds a modal screen. The returned pointer must not be dropped.
1029IGUIElement* CGUIEnvironment::addModalScreen(IGUIElement* parent) 1029IGUIElement* CGUIEnvironment::addModalScreen(IGUIElement* parent)
1030{ 1030{
1031 parent = parent ? parent : this; 1031 parent = parent ? parent : this;
1032 1032
1033 IGUIElement *win = new CGUIModalScreen(this, parent, -1); 1033 IGUIElement *win = new CGUIModalScreen(this, parent, -1);
1034 win->drop(); 1034 win->drop();
1035 1035
1036 return win; 1036 return win;
1037} 1037}
1038 1038
1039 1039
1040//! Adds a message box. 1040//! Adds a message box.
1041IGUIWindow* CGUIEnvironment::addMessageBox(const wchar_t* caption, const wchar_t* text, 1041IGUIWindow* CGUIEnvironment::addMessageBox(const wchar_t* caption, const wchar_t* text,
1042 bool modal, s32 flag, IGUIElement* parent, s32 id, video::ITexture* image) 1042 bool modal, s32 flag, IGUIElement* parent, s32 id, video::ITexture* image)
1043{ 1043{
1044 if (!CurrentSkin) 1044 if (!CurrentSkin)
1045 return 0; 1045 return 0;
1046 1046
1047 parent = parent ? parent : this; 1047 parent = parent ? parent : this;
1048 1048
1049 core::rect<s32> rect; 1049 core::rect<s32> rect;
1050 core::dimension2d<u32> screenDim, msgBoxDim; 1050 core::dimension2d<u32> screenDim, msgBoxDim;
1051 1051
1052 screenDim.Width = parent->getAbsolutePosition().getWidth(); 1052 screenDim.Width = parent->getAbsolutePosition().getWidth();
1053 screenDim.Height = parent->getAbsolutePosition().getHeight(); 1053 screenDim.Height = parent->getAbsolutePosition().getHeight();
1054 msgBoxDim.Width = 2; 1054 msgBoxDim.Width = 2;
1055 msgBoxDim.Height = 2; 1055 msgBoxDim.Height = 2;
1056 1056
1057 rect.UpperLeftCorner.X = (screenDim.Width - msgBoxDim.Width) / 2; 1057 rect.UpperLeftCorner.X = (screenDim.Width - msgBoxDim.Width) / 2;
1058 rect.UpperLeftCorner.Y = (screenDim.Height - msgBoxDim.Height) / 2; 1058 rect.UpperLeftCorner.Y = (screenDim.Height - msgBoxDim.Height) / 2;
1059 rect.LowerRightCorner.X = rect.UpperLeftCorner.X + msgBoxDim.Width; 1059 rect.LowerRightCorner.X = rect.UpperLeftCorner.X + msgBoxDim.Width;
1060 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + msgBoxDim.Height; 1060 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + msgBoxDim.Height;
1061 1061
1062 IGUIWindow* win = new CGUIMessageBox(this, caption, text, flag, 1062 IGUIWindow* win = new CGUIMessageBox(this, caption, text, flag,
1063 parent, id, rect, image); 1063 parent, id, rect, image);
1064 win->drop(); 1064 win->drop();
1065 1065
1066 if (modal) 1066 if (modal)
1067 { 1067 {
1068 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very 1068 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very
1069 // careful not to get virtual function call, like OnEvent, in the CGUIMessageBox. 1069 // careful not to get virtual function call, like OnEvent, in the CGUIMessageBox.
1070 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1); 1070 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1);
1071 modalScreen->drop(); 1071 modalScreen->drop();
1072 modalScreen->addChild( win ); 1072 modalScreen->addChild( win );
1073 } 1073 }
1074 1074
1075 1075
1076 return win; 1076 return win;
1077} 1077}
1078 1078
1079 1079
1080//! adds a scrollbar. The returned pointer must not be dropped. 1080//! adds a scrollbar. The returned pointer must not be dropped.
1081IGUIScrollBar* CGUIEnvironment::addScrollBar(bool horizontal, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id) 1081IGUIScrollBar* CGUIEnvironment::addScrollBar(bool horizontal, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id)
1082{ 1082{
1083 IGUIScrollBar* bar = new CGUIScrollBar(horizontal, this, parent ? parent : this, id, rectangle); 1083 IGUIScrollBar* bar = new CGUIScrollBar(horizontal, this, parent ? parent : this, id, rectangle);
1084 bar->drop(); 1084 bar->drop();
1085 return bar; 1085 return bar;
1086} 1086}
1087 1087
1088//! Adds a table to the environment 1088//! Adds a table to the environment
1089IGUITable* CGUIEnvironment::addTable(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, bool drawBackground) 1089IGUITable* CGUIEnvironment::addTable(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, bool drawBackground)
1090{ 1090{
1091 CGUITable* b = new CGUITable(this, parent ? parent : this, id, rectangle, true, drawBackground, false); 1091 CGUITable* b = new CGUITable(this, parent ? parent : this, id, rectangle, true, drawBackground, false);
1092 b->drop(); 1092 b->drop();
1093 return b; 1093 return b;
1094} 1094}
1095 1095
1096 1096
1097//! Adds an image element. 1097//! Adds an image element.
1098IGUIImage* CGUIEnvironment::addImage(video::ITexture* image, core::position2d<s32> pos, 1098IGUIImage* CGUIEnvironment::addImage(video::ITexture* image, core::position2d<s32> pos,
1099 bool useAlphaChannel, IGUIElement* parent, s32 id, const wchar_t* text) 1099 bool useAlphaChannel, IGUIElement* parent, s32 id, const wchar_t* text)
1100{ 1100{
1101 core::dimension2d<s32> sz(0,0); 1101 core::dimension2d<s32> sz(0,0);
1102 if (image) 1102 if (image)
1103 sz = core::dimension2d<s32>(image->getOriginalSize()); 1103 sz = core::dimension2d<s32>(image->getOriginalSize());
1104 1104
1105 IGUIImage* img = new CGUIImage(this, parent ? parent : this, 1105 IGUIImage* img = new CGUIImage(this, parent ? parent : this,
1106 id, core::rect<s32>(pos, sz)); 1106 id, core::rect<s32>(pos, sz));
1107 1107
1108 if (text) 1108 if (text)
1109 img->setText(text); 1109 img->setText(text);
1110 1110
1111 if (useAlphaChannel) 1111 if (useAlphaChannel)
1112 img->setUseAlphaChannel(true); 1112 img->setUseAlphaChannel(true);
1113 1113
1114 if (image) 1114 if (image)
1115 img->setImage(image); 1115 img->setImage(image);
1116 1116
1117 img->drop(); 1117 img->drop();
1118 return img; 1118 return img;
1119} 1119}
1120 1120
1121 1121
1122//! adds an image. The returned pointer must not be dropped. 1122//! adds an image. The returned pointer must not be dropped.
1123IGUIImage* CGUIEnvironment::addImage(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text, bool useAlphaChannel) 1123IGUIImage* CGUIEnvironment::addImage(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text, bool useAlphaChannel)
1124{ 1124{
1125 IGUIImage* img = new CGUIImage(this, parent ? parent : this, 1125 IGUIImage* img = new CGUIImage(this, parent ? parent : this,
1126 id, rectangle); 1126 id, rectangle);
1127 1127
1128 if (text) 1128 if (text)
1129 img->setText(text); 1129 img->setText(text);
1130 1130
1131 if ( useAlphaChannel ) 1131 if ( useAlphaChannel )
1132 img->setUseAlphaChannel(true); 1132 img->setUseAlphaChannel(true);
1133 1133
1134 img->drop(); 1134 img->drop();
1135 return img; 1135 return img;
1136} 1136}
1137 1137
1138 1138
1139//! adds an mesh viewer. The returned pointer must not be dropped. 1139//! adds an mesh viewer. The returned pointer must not be dropped.
1140IGUIMeshViewer* CGUIEnvironment::addMeshViewer(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text) 1140IGUIMeshViewer* CGUIEnvironment::addMeshViewer(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text)
1141{ 1141{
1142 IGUIMeshViewer* v = new CGUIMeshViewer(this, parent ? parent : this, 1142 IGUIMeshViewer* v = new CGUIMeshViewer(this, parent ? parent : this,
1143 id, rectangle); 1143 id, rectangle);
1144 1144
1145 if (text) 1145 if (text)
1146 v->setText(text); 1146 v->setText(text);
1147 1147
1148 v->drop(); 1148 v->drop();
1149 return v; 1149 return v;
1150} 1150}
1151 1151
1152 1152
1153//! adds a checkbox 1153//! adds a checkbox
1154IGUICheckBox* CGUIEnvironment::addCheckBox(bool checked, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text) 1154IGUICheckBox* CGUIEnvironment::addCheckBox(bool checked, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text)
1155{ 1155{
1156 IGUICheckBox* b = new CGUICheckBox(checked, this, 1156 IGUICheckBox* b = new CGUICheckBox(checked, this,
1157 parent ? parent : this , id , rectangle); 1157 parent ? parent : this , id , rectangle);
1158 1158
1159 if (text) 1159 if (text)
1160 b->setText(text); 1160 b->setText(text);
1161 1161
1162 b->drop(); 1162 b->drop();
1163 return b; 1163 return b;
1164} 1164}
1165 1165
1166 1166
1167//! adds a list box 1167//! adds a list box
1168IGUIListBox* CGUIEnvironment::addListBox(const core::rect<s32>& rectangle, 1168IGUIListBox* CGUIEnvironment::addListBox(const core::rect<s32>& rectangle,
1169 IGUIElement* parent, s32 id, bool drawBackground) 1169 IGUIElement* parent, s32 id, bool drawBackground)
1170{ 1170{
1171 IGUIListBox* b = new CGUIListBox(this, parent ? parent : this, id, rectangle, 1171 IGUIListBox* b = new CGUIListBox(this, parent ? parent : this, id, rectangle,
1172 true, drawBackground, false); 1172 true, drawBackground, false);
1173 1173
1174 if (CurrentSkin && CurrentSkin->getSpriteBank()) 1174 if (CurrentSkin && CurrentSkin->getSpriteBank())
1175 { 1175 {
1176 b->setSpriteBank(CurrentSkin->getSpriteBank()); 1176 b->setSpriteBank(CurrentSkin->getSpriteBank());
1177 } 1177 }
1178 else if (getBuiltInFont() && getBuiltInFont()->getType() == EGFT_BITMAP) 1178 else if (getBuiltInFont() && getBuiltInFont()->getType() == EGFT_BITMAP)
1179 { 1179 {
1180 b->setSpriteBank( ((IGUIFontBitmap*)getBuiltInFont())->getSpriteBank()); 1180 b->setSpriteBank( ((IGUIFontBitmap*)getBuiltInFont())->getSpriteBank());
1181 } 1181 }
1182 1182
1183 b->drop(); 1183 b->drop();
1184 return b; 1184 return b;
1185} 1185}
1186 1186
1187//! adds a tree view 1187//! adds a tree view
1188IGUITreeView* CGUIEnvironment::addTreeView(const core::rect<s32>& rectangle, 1188IGUITreeView* CGUIEnvironment::addTreeView(const core::rect<s32>& rectangle,
1189 IGUIElement* parent, s32 id, 1189 IGUIElement* parent, s32 id,
1190 bool drawBackground, 1190 bool drawBackground,
1191 bool scrollBarVertical, bool scrollBarHorizontal) 1191 bool scrollBarVertical, bool scrollBarHorizontal)
1192{ 1192{
1193 IGUITreeView* b = new CGUITreeView(this, parent ? parent : this, id, rectangle, 1193 IGUITreeView* b = new CGUITreeView(this, parent ? parent : this, id, rectangle,
1194 true, drawBackground, scrollBarVertical, scrollBarHorizontal); 1194 true, drawBackground, scrollBarVertical, scrollBarHorizontal);
1195 1195
1196 b->setIconFont ( getBuiltInFont () ); 1196 b->setIconFont ( getBuiltInFont () );
1197 b->drop(); 1197 b->drop();
1198 return b; 1198 return b;
1199} 1199}
1200 1200
1201//! adds a file open dialog. The returned pointer must not be dropped. 1201//! adds a file open dialog. The returned pointer must not be dropped.
1202IGUIFileOpenDialog* CGUIEnvironment::addFileOpenDialog(const wchar_t* title, 1202IGUIFileOpenDialog* CGUIEnvironment::addFileOpenDialog(const wchar_t* title,
1203 bool modal, IGUIElement* parent, s32 id, 1203 bool modal, IGUIElement* parent, s32 id,
1204 bool restoreCWD, io::path::char_type* startDir) 1204 bool restoreCWD, io::path::char_type* startDir)
1205{ 1205{
1206 parent = parent ? parent : this; 1206 parent = parent ? parent : this;
1207 1207
1208 IGUIFileOpenDialog* d = new CGUIFileOpenDialog(title, this, parent, id, 1208 IGUIFileOpenDialog* d = new CGUIFileOpenDialog(title, this, parent, id,
1209 restoreCWD, startDir); 1209 restoreCWD, startDir);
1210 d->drop(); 1210 d->drop();
1211 1211
1212 if (modal) 1212 if (modal)
1213 { 1213 {
1214 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very 1214 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very
1215 // careful not to get virtual function call, like OnEvent, in the window. 1215 // careful not to get virtual function call, like OnEvent, in the window.
1216 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1); 1216 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1);
1217 modalScreen->drop(); 1217 modalScreen->drop();
1218 modalScreen->addChild(d); 1218 modalScreen->addChild(d);
1219 } 1219 }
1220 1220
1221 return d; 1221 return d;
1222} 1222}
1223 1223
1224 1224
1225//! adds a color select dialog. The returned pointer must not be dropped. 1225//! adds a color select dialog. The returned pointer must not be dropped.
1226IGUIColorSelectDialog* CGUIEnvironment::addColorSelectDialog(const wchar_t* title, 1226IGUIColorSelectDialog* CGUIEnvironment::addColorSelectDialog(const wchar_t* title,
1227 bool modal, IGUIElement* parent, s32 id) 1227 bool modal, IGUIElement* parent, s32 id)
1228{ 1228{
1229 parent = parent ? parent : this; 1229 parent = parent ? parent : this;
1230 1230
1231 IGUIColorSelectDialog* d = new CGUIColorSelectDialog( title, 1231 IGUIColorSelectDialog* d = new CGUIColorSelectDialog( title,
1232 this, parent, id); 1232 this, parent, id);
1233 d->drop(); 1233 d->drop();
1234 1234
1235 if (modal) 1235 if (modal)
1236 { 1236 {
1237 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very 1237 // Careful, don't just set the modal as parent above. That will mess up the focus (and is hard to change because we have to be very
1238 // careful not to get virtual function call, like OnEvent, in the window. 1238 // careful not to get virtual function call, like OnEvent, in the window.
1239 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1); 1239 CGUIModalScreen * modalScreen = new CGUIModalScreen(this, parent, -1);
1240 modalScreen->drop(); 1240 modalScreen->drop();
1241 modalScreen->addChild(d); 1241 modalScreen->addChild(d);
1242 } 1242 }
1243 1243
1244 return d; 1244 return d;
1245} 1245}
1246 1246
1247 1247
1248//! adds a static text. The returned pointer must not be dropped. 1248//! adds a static text. The returned pointer must not be dropped.
1249IGUIStaticText* CGUIEnvironment::addStaticText(const wchar_t* text, 1249IGUIStaticText* CGUIEnvironment::addStaticText(const wchar_t* text,
1250 const core::rect<s32>& rectangle, 1250 const core::rect<s32>& rectangle,
1251 bool border, bool wordWrap, 1251 bool border, bool wordWrap,
1252 IGUIElement* parent, s32 id, bool background) 1252 IGUIElement* parent, s32 id, bool background)
1253{ 1253{
1254 IGUIStaticText* d = new CGUIStaticText(text, border, this, 1254 IGUIStaticText* d = new CGUIStaticText(text, border, this,
1255 parent ? parent : this, id, rectangle, background); 1255 parent ? parent : this, id, rectangle, background);
1256 1256
1257 d->setWordWrap(wordWrap); 1257 d->setWordWrap(wordWrap);
1258 d->drop(); 1258 d->drop();
1259 1259
1260 return d; 1260 return d;
1261} 1261}
1262 1262
1263 1263
1264//! Adds an edit box. The returned pointer must not be dropped. 1264//! Adds an edit box. The returned pointer must not be dropped.
1265IGUIEditBox* CGUIEnvironment::addEditBox(const wchar_t* text, 1265IGUIEditBox* CGUIEnvironment::addEditBox(const wchar_t* text,
1266 const core::rect<s32>& rectangle, bool border, 1266 const core::rect<s32>& rectangle, bool border,
1267 IGUIElement* parent, s32 id) 1267 IGUIElement* parent, s32 id)
1268{ 1268{
1269 IGUIEditBox* d = new CGUIEditBox(text, border, this, 1269 IGUIEditBox* d = new CGUIEditBox(text, border, this,
1270 parent ? parent : this, id, rectangle); 1270 parent ? parent : this, id, rectangle);
1271 1271
1272 d->drop(); 1272 d->drop();
1273 return d; 1273 return d;
1274} 1274}
1275 1275
1276 1276
1277//! Adds a spin box to the environment 1277//! Adds a spin box to the environment
1278IGUISpinBox* CGUIEnvironment::addSpinBox(const wchar_t* text, 1278IGUISpinBox* CGUIEnvironment::addSpinBox(const wchar_t* text,
1279 const core::rect<s32> &rectangle, 1279 const core::rect<s32> &rectangle,
1280 bool border,IGUIElement* parent, s32 id) 1280 bool border,IGUIElement* parent, s32 id)
1281{ 1281{
1282 IGUISpinBox* d = new CGUISpinBox(text, border,this, 1282 IGUISpinBox* d = new CGUISpinBox(text, border,this,
1283 parent ? parent : this, id, rectangle); 1283 parent ? parent : this, id, rectangle);
1284 1284
1285 d->drop(); 1285 d->drop();
1286 return d; 1286 return d;
1287} 1287}
1288 1288
1289 1289
1290//! Adds a tab control to the environment. 1290//! Adds a tab control to the environment.
1291IGUITabControl* CGUIEnvironment::addTabControl(const core::rect<s32>& rectangle, 1291IGUITabControl* CGUIEnvironment::addTabControl(const core::rect<s32>& rectangle,
1292 IGUIElement* parent, bool fillbackground, bool border, s32 id) 1292 IGUIElement* parent, bool fillbackground, bool border, s32 id)
1293{ 1293{
1294 IGUITabControl* t = new CGUITabControl(this, parent ? parent : this, 1294 IGUITabControl* t = new CGUITabControl(this, parent ? parent : this,
1295 rectangle, fillbackground, border, id); 1295 rectangle, fillbackground, border, id);
1296 t->drop(); 1296 t->drop();
1297 return t; 1297 return t;
1298} 1298}
1299 1299
1300 1300
1301//! Adds tab to the environment. 1301//! Adds tab to the environment.
1302IGUITab* CGUIEnvironment::addTab(const core::rect<s32>& rectangle, 1302IGUITab* CGUIEnvironment::addTab(const core::rect<s32>& rectangle,
1303 IGUIElement* parent, s32 id) 1303 IGUIElement* parent, s32 id)
1304{ 1304{
1305 IGUITab* t = new CGUITab(-1, this, parent ? parent : this, 1305 IGUITab* t = new CGUITab(-1, this, parent ? parent : this,
1306 rectangle, id); 1306 rectangle, id);
1307 t->drop(); 1307 t->drop();
1308 return t; 1308 return t;
1309} 1309}
1310 1310
1311 1311
1312//! Adds a context menu to the environment. 1312//! Adds a context menu to the environment.
1313IGUIContextMenu* CGUIEnvironment::addContextMenu(const core::rect<s32>& rectangle, 1313IGUIContextMenu* CGUIEnvironment::addContextMenu(const core::rect<s32>& rectangle,
1314 IGUIElement* parent, s32 id) 1314 IGUIElement* parent, s32 id)
1315{ 1315{
1316 IGUIContextMenu* c = new CGUIContextMenu(this, 1316 IGUIContextMenu* c = new CGUIContextMenu(this,
1317 parent ? parent : this, id, rectangle, true); 1317 parent ? parent : this, id, rectangle, true);
1318 c->drop(); 1318 c->drop();
1319 return c; 1319 return c;
1320} 1320}
1321 1321
1322 1322
1323//! Adds a menu to the environment. 1323//! Adds a menu to the environment.
1324IGUIContextMenu* CGUIEnvironment::addMenu(IGUIElement* parent, s32 id) 1324IGUIContextMenu* CGUIEnvironment::addMenu(IGUIElement* parent, s32 id)
1325{ 1325{
1326 if (!parent) 1326 if (!parent)
1327 parent = this; 1327 parent = this;
1328 1328
1329 IGUIContextMenu* c = new CGUIMenu(this, 1329 IGUIContextMenu* c = new CGUIMenu(this,
1330 parent, id, core::rect<s32>(0,0, 1330 parent, id, core::rect<s32>(0,0,
1331 parent->getAbsolutePosition().getWidth(), 1331 parent->getAbsolutePosition().getWidth(),
1332 parent->getAbsolutePosition().getHeight())); 1332 parent->getAbsolutePosition().getHeight()));
1333 1333
1334 c->drop(); 1334 c->drop();
1335 return c; 1335 return c;
1336} 1336}
1337 1337
1338 1338
1339//! Adds a toolbar to the environment. It is like a menu is always placed on top 1339//! Adds a toolbar to the environment. It is like a menu is always placed on top
1340//! in its parent, and contains buttons. 1340//! in its parent, and contains buttons.
1341IGUIToolBar* CGUIEnvironment::addToolBar(IGUIElement* parent, s32 id) 1341IGUIToolBar* CGUIEnvironment::addToolBar(IGUIElement* parent, s32 id)
1342{ 1342{
1343 if (!parent) 1343 if (!parent)
1344 parent = this; 1344 parent = this;
1345 1345
1346 IGUIToolBar* b = new CGUIToolBar(this, parent, id, core::rect<s32>(0,0,10,10)); 1346 IGUIToolBar* b = new CGUIToolBar(this, parent, id, core::rect<s32>(0,0,10,10));
1347 b->drop(); 1347 b->drop();
1348 return b; 1348 return b;
1349} 1349}
1350 1350
1351 1351
1352//! Adds an element for fading in or out. 1352//! Adds an element for fading in or out.
1353IGUIInOutFader* CGUIEnvironment::addInOutFader(const core::rect<s32>* rectangle, IGUIElement* parent, s32 id) 1353IGUIInOutFader* CGUIEnvironment::addInOutFader(const core::rect<s32>* rectangle, IGUIElement* parent, s32 id)
1354{ 1354{
1355 core::rect<s32> rect; 1355 core::rect<s32> rect;
1356 1356
1357 if (rectangle) 1357 if (rectangle)
1358 rect = *rectangle; 1358 rect = *rectangle;
1359 else if (Driver) 1359 else if (Driver)
1360 rect = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Driver->getScreenSize())); 1360 rect = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Driver->getScreenSize()));
1361 1361
1362 if (!parent) 1362 if (!parent)
1363 parent = this; 1363 parent = this;
1364 1364
1365 IGUIInOutFader* fader = new CGUIInOutFader(this, parent, id, rect); 1365 IGUIInOutFader* fader = new CGUIInOutFader(this, parent, id, rect);
1366 fader->drop(); 1366 fader->drop();
1367 return fader; 1367 return fader;
1368} 1368}
1369 1369
1370 1370
1371//! Adds a combo box to the environment. 1371//! Adds a combo box to the environment.
1372IGUIComboBox* CGUIEnvironment::addComboBox(const core::rect<s32>& rectangle, 1372IGUIComboBox* CGUIEnvironment::addComboBox(const core::rect<s32>& rectangle,
1373 IGUIElement* parent, s32 id) 1373 IGUIElement* parent, s32 id)
1374{ 1374{
1375 IGUIComboBox* t = new CGUIComboBox(this, parent ? parent : this, 1375 IGUIComboBox* t = new CGUIComboBox(this, parent ? parent : this,
1376 id, rectangle); 1376 id, rectangle);
1377 t->drop(); 1377 t->drop();
1378 return t; 1378 return t;
1379} 1379}
1380 1380
1381 1381
1382//! returns the font 1382//! returns the font
1383IGUIFont* CGUIEnvironment::getFont(const io::path& filename) 1383IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
1384{ 1384{
1385 // search existing font 1385 // search existing font
1386 1386
1387 SFont f; 1387 SFont f;
1388 f.NamedPath.setPath(filename); 1388 f.NamedPath.setPath(filename);
1389 1389
1390 s32 index = Fonts.binary_search(f); 1390 s32 index = Fonts.binary_search(f);
1391 if (index != -1) 1391 if (index != -1)
1392 return Fonts[index].Font; 1392 return Fonts[index].Font;
1393 1393
1394 // font doesn't exist, attempt to load it 1394 // font doesn't exist, attempt to load it
1395 1395
1396 // does the file exist? 1396 // does the file exist?
1397 1397
1398 if (!FileSystem->existFile(filename)) 1398 if (!FileSystem->existFile(filename))
1399 { 1399 {
1400 os::Printer::log("Could not load font because the file does not exist", f.NamedPath.getPath(), ELL_ERROR); 1400 os::Printer::log("Could not load font because the file does not exist", f.NamedPath.getPath(), ELL_ERROR);
1401 return 0; 1401 return 0;
1402 } 1402 }
1403 1403
1404 IGUIFont* ifont=0; 1404 IGUIFont* ifont=0;
1405 io::IXMLReader *xml = FileSystem->createXMLReader(filename ); 1405 io::IXMLReader *xml = FileSystem->createXMLReader(filename );
1406 if (xml) 1406 if (xml)
1407 { 1407 {
1408 // this is an XML font, but we need to know what type 1408 // this is an XML font, but we need to know what type
1409 EGUI_FONT_TYPE t = EGFT_CUSTOM; 1409 EGUI_FONT_TYPE t = EGFT_CUSTOM;
1410 1410
1411 bool found=false; 1411 bool found=false;
1412 while(!found && xml->read()) 1412 while(!found && xml->read())
1413 { 1413 {
1414 if (xml->getNodeType() == io::EXN_ELEMENT) 1414 if (xml->getNodeType() == io::EXN_ELEMENT)
1415 { 1415 {
1416 if (core::stringw(L"font") == xml->getNodeName()) 1416 if (core::stringw(L"font") == xml->getNodeName())
1417 { 1417 {
1418 if (core::stringw(L"vector") == xml->getAttributeValue(L"type")) 1418 if (core::stringw(L"vector") == xml->getAttributeValue(L"type"))
1419 { 1419 {
1420 t = EGFT_VECTOR; 1420 t = EGFT_VECTOR;
1421 found=true; 1421 found=true;
1422 } 1422 }
1423 else if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type")) 1423 else if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type"))
1424 { 1424 {
1425 t = EGFT_BITMAP; 1425 t = EGFT_BITMAP;
1426 found=true; 1426 found=true;
1427 } 1427 }
1428 else found=true; 1428 else found=true;
1429 } 1429 }
1430 } 1430 }
1431 } 1431 }
1432 1432
1433 if (t==EGFT_BITMAP) 1433 if (t==EGFT_BITMAP)
1434 { 1434 {
1435 CGUIFont* font = new CGUIFont(this, filename); 1435 CGUIFont* font = new CGUIFont(this, filename);
1436 ifont = (IGUIFont*)font; 1436 ifont = (IGUIFont*)font;
1437 // change working directory, for loading textures 1437 // change working directory, for loading textures
1438 io::path workingDir = FileSystem->getWorkingDirectory(); 1438 io::path workingDir = FileSystem->getWorkingDirectory();
1439 FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.NamedPath.getPath())); 1439 FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.NamedPath.getPath()));
1440 1440
1441 // load the font 1441 // load the font
1442 if (!font->load(xml)) 1442 if (!font->load(xml))
1443 { 1443 {
1444 font->drop(); 1444 font->drop();
1445 font = 0; 1445 font = 0;
1446 ifont = 0; 1446 ifont = 0;
1447 } 1447 }
1448 // change working dir back again 1448 // change working dir back again
1449 FileSystem->changeWorkingDirectoryTo( workingDir ); 1449 FileSystem->changeWorkingDirectoryTo( workingDir );
1450 } 1450 }
1451 else if (t==EGFT_VECTOR) 1451 else if (t==EGFT_VECTOR)
1452 { 1452 {
1453 // todo: vector fonts 1453 // todo: vector fonts
1454 os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.NamedPath, ELL_ERROR); 1454 os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.NamedPath, ELL_ERROR);
1455 1455
1456 //CGUIFontVector* font = new CGUIFontVector(Driver); 1456 //CGUIFontVector* font = new CGUIFontVector(Driver);
1457 //ifont = (IGUIFont*)font; 1457 //ifont = (IGUIFont*)font;
1458 //if (!font->load(xml)) 1458 //if (!font->load(xml))
1459 } 1459 }
1460 xml->drop(); 1460 xml->drop();
1461 } 1461 }
1462 1462
1463 1463
1464 if (!ifont) 1464 if (!ifont)
1465 { 1465 {
1466 1466
1467 CGUIFont* font = new CGUIFont(this, f.NamedPath.getPath() ); 1467 CGUIFont* font = new CGUIFont(this, f.NamedPath.getPath() );
1468 ifont = (IGUIFont*)font; 1468 ifont = (IGUIFont*)font;
1469 if (!font->load(f.NamedPath.getPath())) 1469 if (!font->load(f.NamedPath.getPath()))
1470 { 1470 {
1471 font->drop(); 1471 font->drop();
1472 return 0; 1472 return 0;
1473 } 1473 }
1474 } 1474 }
1475 1475
1476 // add to fonts. 1476 // add to fonts.
1477 1477
1478 f.Font = ifont; 1478 f.Font = ifont;
1479 Fonts.push_back(f); 1479 Fonts.push_back(f);
1480 1480
1481 return ifont; 1481 return ifont;
1482} 1482}
1483 1483
1484 1484
1485//! add an externally loaded font 1485//! add an externally loaded font
1486IGUIFont* CGUIEnvironment::addFont(const io::path& name, IGUIFont* font) 1486IGUIFont* CGUIEnvironment::addFont(const io::path& name, IGUIFont* font)
1487{ 1487{
1488 if (font) 1488 if (font)
1489 { 1489 {
1490 SFont f; 1490 SFont f;
1491 f.NamedPath.setPath(name); 1491 f.NamedPath.setPath(name);
1492 s32 index = Fonts.binary_search(f); 1492 s32 index = Fonts.binary_search(f);
1493 if (index != -1) 1493 if (index != -1)
1494 return Fonts[index].Font; 1494 return Fonts[index].Font;
1495 f.Font = font; 1495 f.Font = font;
1496 Fonts.push_back(f); 1496 Fonts.push_back(f);
1497 font->grab(); 1497 font->grab();
1498 } 1498 }
1499 return font; 1499 return font;
1500} 1500}
1501 1501
1502//! remove loaded font 1502//! remove loaded font
1503void CGUIEnvironment::removeFont(IGUIFont* font) 1503void CGUIEnvironment::removeFont(IGUIFont* font)
1504{ 1504{
1505 if ( !font ) 1505 if ( !font )
1506 return; 1506 return;
1507 for ( u32 i=0; i<Fonts.size(); ++i ) 1507 for ( u32 i=0; i<Fonts.size(); ++i )
1508 { 1508 {
1509 if ( Fonts[i].Font == font ) 1509 if ( Fonts[i].Font == font )
1510 { 1510 {
1511 Fonts[i].Font->drop(); 1511 Fonts[i].Font->drop();
1512 Fonts.erase(i); 1512 Fonts.erase(i);
1513 return; 1513 return;
1514 } 1514 }
1515 } 1515 }
1516} 1516}
1517 1517
1518//! returns default font 1518//! returns default font
1519IGUIFont* CGUIEnvironment::getBuiltInFont() const 1519IGUIFont* CGUIEnvironment::getBuiltInFont() const
1520{ 1520{
1521 if (Fonts.empty()) 1521 if (Fonts.empty())
1522 return 0; 1522 return 0;
1523 1523
1524 return Fonts[0].Font; 1524 return Fonts[0].Font;
1525} 1525}
1526 1526
1527 1527
1528IGUISpriteBank* CGUIEnvironment::getSpriteBank(const io::path& filename) 1528IGUISpriteBank* CGUIEnvironment::getSpriteBank(const io::path& filename)
1529{ 1529{
1530 // search for the file name 1530 // search for the file name
1531 1531
1532 SSpriteBank b; 1532 SSpriteBank b;
1533 b.NamedPath.setPath(filename); 1533 b.NamedPath.setPath(filename);
1534 1534
1535 s32 index = Banks.binary_search(b); 1535 s32 index = Banks.binary_search(b);
1536 if (index != -1) 1536 if (index != -1)
1537 return Banks[index].Bank; 1537 return Banks[index].Bank;
1538 1538
1539 // we don't have this sprite bank, we should load it 1539 // we don't have this sprite bank, we should load it
1540 if (!FileSystem->existFile(b.NamedPath.getPath())) 1540 if (!FileSystem->existFile(b.NamedPath.getPath()))
1541 { 1541 {
1542 if ( filename != DefaultFontName ) 1542 if ( filename != DefaultFontName )
1543 { 1543 {
1544 os::Printer::log("Could not load sprite bank because the file does not exist", b.NamedPath.getPath(), ELL_DEBUG); 1544 os::Printer::log("Could not load sprite bank because the file does not exist", b.NamedPath.getPath(), ELL_DEBUG);
1545 } 1545 }
1546 return 0; 1546 return 0;
1547 } 1547 }
1548 1548
1549 // todo: load it! 1549 // todo: load it!
1550 1550
1551 return 0; 1551 return 0;
1552} 1552}
1553 1553
1554 1554
1555IGUISpriteBank* CGUIEnvironment::addEmptySpriteBank(const io::path& name) 1555IGUISpriteBank* CGUIEnvironment::addEmptySpriteBank(const io::path& name)
1556{ 1556{
1557 // no duplicate names allowed 1557 // no duplicate names allowed
1558 1558
1559 SSpriteBank b; 1559 SSpriteBank b;
1560 b.NamedPath.setPath(name); 1560 b.NamedPath.setPath(name);
1561 1561
1562 const s32 index = Banks.binary_search(b); 1562 const s32 index = Banks.binary_search(b);
1563 if (index != -1) 1563 if (index != -1)
1564 return 0; 1564 return 0;
1565 1565
1566 // create a new sprite bank 1566 // create a new sprite bank
1567 1567
1568 b.Bank = new CGUISpriteBank(this); 1568 b.Bank = new CGUISpriteBank(this);
1569 Banks.push_back(b); 1569 Banks.push_back(b);
1570 1570
1571 return b.Bank; 1571 return b.Bank;
1572} 1572}
1573 1573
1574 1574
1575//! Creates the image list from the given texture. 1575//! Creates the image list from the given texture.
1576IGUIImageList* CGUIEnvironment::createImageList( video::ITexture* texture, 1576IGUIImageList* CGUIEnvironment::createImageList( video::ITexture* texture,
1577 core::dimension2d<s32> imageSize, bool useAlphaChannel ) 1577 core::dimension2d<s32> imageSize, bool useAlphaChannel )
1578{ 1578{
1579 CGUIImageList* imageList = new CGUIImageList( Driver ); 1579 CGUIImageList* imageList = new CGUIImageList( Driver );
1580 if( !imageList->createImageList( texture, imageSize, useAlphaChannel ) ) 1580 if( !imageList->createImageList( texture, imageSize, useAlphaChannel ) )
1581 { 1581 {
1582 imageList->drop(); 1582 imageList->drop();
1583 return 0; 1583 return 0;
1584 } 1584 }
1585 1585
1586 return imageList; 1586 return imageList;
1587} 1587}
1588 1588
1589//! Returns the root gui element. 1589//! Returns the root gui element.
1590IGUIElement* CGUIEnvironment::getRootGUIElement() 1590IGUIElement* CGUIEnvironment::getRootGUIElement()
1591{ 1591{
1592 return this; 1592 return this;
1593} 1593}
1594 1594
1595 1595
1596//! Returns the next element in the tab group starting at the focused element 1596//! Returns the next element in the tab group starting at the focused element
1597IGUIElement* CGUIEnvironment::getNextElement(bool reverse, bool group) 1597IGUIElement* CGUIEnvironment::getNextElement(bool reverse, bool group)
1598{ 1598{
1599 // start the search at the root of the current tab group 1599 // start the search at the root of the current tab group
1600 IGUIElement *startPos = Focus ? Focus->getTabGroup() : 0; 1600 IGUIElement *startPos = Focus ? Focus->getTabGroup() : 0;
1601 s32 startOrder = -1; 1601 s32 startOrder = -1;
1602 1602
1603 // if we're searching for a group 1603 // if we're searching for a group
1604 if (group && startPos) 1604 if (group && startPos)
1605 { 1605 {
1606 startOrder = startPos->getTabOrder(); 1606 startOrder = startPos->getTabOrder();
1607 } 1607 }
1608 else 1608 else
1609 if (!group && Focus && !Focus->isTabGroup()) 1609 if (!group && Focus && !Focus->isTabGroup())
1610 { 1610 {
1611 startOrder = Focus->getTabOrder(); 1611 startOrder = Focus->getTabOrder();
1612 if (startOrder == -1) 1612 if (startOrder == -1)
1613 { 1613 {
1614 // this element is not part of the tab cycle, 1614 // this element is not part of the tab cycle,
1615 // but its parent might be... 1615 // but its parent might be...
1616 IGUIElement *el = Focus; 1616 IGUIElement *el = Focus;
1617 while (el && el->getParent() && startOrder == -1) 1617 while (el && el->getParent() && startOrder == -1)
1618 { 1618 {
1619 el = el->getParent(); 1619 el = el->getParent();
1620 startOrder = el->getTabOrder(); 1620 startOrder = el->getTabOrder();
1621 } 1621 }
1622 1622
1623 } 1623 }
1624 } 1624 }
1625 1625
1626 if (group || !startPos) 1626 if (group || !startPos)
1627 startPos = this; // start at the root 1627 startPos = this; // start at the root
1628 1628
1629 // find the element 1629 // find the element
1630 IGUIElement *closest = 0; 1630 IGUIElement *closest = 0;
1631 IGUIElement *first = 0; 1631 IGUIElement *first = 0;
1632 startPos->getNextElement(startOrder, reverse, group, first, closest); 1632 startPos->getNextElement(startOrder, reverse, group, first, closest);
1633 1633
1634 if (closest) 1634 if (closest)
1635 return closest; // we found an element 1635 return closest; // we found an element
1636 else if (first) 1636 else if (first)
1637 return first; // go to the end or the start 1637 return first; // go to the end or the start
1638 else if (group) 1638 else if (group)
1639 return this; // no group found? root group 1639 return this; // no group found? root group
1640 else 1640 else
1641 return 0; 1641 return 0;
1642} 1642}
1643 1643
1644 1644
1645//! creates an GUI Environment 1645//! creates an GUI Environment
1646IGUIEnvironment* createGUIEnvironment(io::IFileSystem* fs, 1646IGUIEnvironment* createGUIEnvironment(io::IFileSystem* fs,
1647 video::IVideoDriver* Driver, 1647 video::IVideoDriver* Driver,
1648 IOSOperator* op) 1648 IOSOperator* op)
1649{ 1649{
1650 return new CGUIEnvironment(fs, Driver, op); 1650 return new CGUIEnvironment(fs, Driver, op);
1651} 1651}
1652 1652
1653 1653
1654} // end namespace gui 1654} // end namespace gui
1655} // end namespace irr 1655} // end namespace irr
1656 1656
1657#endif // _IRR_COMPILE_WITH_GUI_ 1657#endif // _IRR_COMPILE_WITH_GUI_
1658 1658