aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CGUIContextMenu.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/CGUIContextMenu.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 '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CGUIContextMenu.cpp1738
1 files changed, 869 insertions, 869 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUIContextMenu.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUIContextMenu.cpp
index 67631e7..b6f5b79 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CGUIContextMenu.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUIContextMenu.cpp
@@ -1,869 +1,869 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CGUIContextMenu.h" 5#include "CGUIContextMenu.h"
6 6
7#ifdef _IRR_COMPILE_WITH_GUI_ 7#ifdef _IRR_COMPILE_WITH_GUI_
8 8
9#include "IGUISkin.h" 9#include "IGUISkin.h"
10#include "IGUIEnvironment.h" 10#include "IGUIEnvironment.h"
11#include "IVideoDriver.h" 11#include "IVideoDriver.h"
12#include "IGUIFont.h" 12#include "IGUIFont.h"
13#include "IGUISpriteBank.h" 13#include "IGUISpriteBank.h"
14#include "os.h" 14#include "os.h"
15 15
16namespace irr 16namespace irr
17{ 17{
18namespace gui 18namespace gui
19{ 19{
20 20
21 21
22//! constructor 22//! constructor
23CGUIContextMenu::CGUIContextMenu(IGUIEnvironment* environment, 23CGUIContextMenu::CGUIContextMenu(IGUIEnvironment* environment,
24 IGUIElement* parent, s32 id, 24 IGUIElement* parent, s32 id,
25 core::rect<s32> rectangle, bool getFocus, bool allowFocus) 25 core::rect<s32> rectangle, bool getFocus, bool allowFocus)
26 : IGUIContextMenu(environment, parent, id, rectangle), EventParent(0), LastFont(0), 26 : IGUIContextMenu(environment, parent, id, rectangle), EventParent(0), LastFont(0),
27 CloseHandling(ECMC_REMOVE), HighLighted(-1), ChangeTime(0), AllowFocus(allowFocus) 27 CloseHandling(ECMC_REMOVE), HighLighted(-1), ChangeTime(0), AllowFocus(allowFocus)
28{ 28{
29 #ifdef _DEBUG 29 #ifdef _DEBUG
30 setDebugName("CGUIContextMenu"); 30 setDebugName("CGUIContextMenu");
31 #endif 31 #endif
32 32
33 Pos = rectangle.UpperLeftCorner; 33 Pos = rectangle.UpperLeftCorner;
34 recalculateSize(); 34 recalculateSize();
35 35
36 if (getFocus) 36 if (getFocus)
37 Environment->setFocus(this); 37 Environment->setFocus(this);
38 38
39 setNotClipped(true); 39 setNotClipped(true);
40} 40}
41 41
42 42
43//! destructor 43//! destructor
44CGUIContextMenu::~CGUIContextMenu() 44CGUIContextMenu::~CGUIContextMenu()
45{ 45{
46 for (u32 i=0; i<Items.size(); ++i) 46 for (u32 i=0; i<Items.size(); ++i)
47 if (Items[i].SubMenu) 47 if (Items[i].SubMenu)
48 Items[i].SubMenu->drop(); 48 Items[i].SubMenu->drop();
49 49
50 if (LastFont) 50 if (LastFont)
51 LastFont->drop(); 51 LastFont->drop();
52} 52}
53 53
54//! set behavior when menus are closed 54//! set behavior when menus are closed
55void CGUIContextMenu::setCloseHandling(ECONTEXT_MENU_CLOSE onClose) 55void CGUIContextMenu::setCloseHandling(ECONTEXT_MENU_CLOSE onClose)
56{ 56{
57 CloseHandling = onClose; 57 CloseHandling = onClose;
58} 58}
59 59
60//! get current behavior when the menue will be closed 60//! get current behavior when the menue will be closed
61ECONTEXT_MENU_CLOSE CGUIContextMenu::getCloseHandling() const 61ECONTEXT_MENU_CLOSE CGUIContextMenu::getCloseHandling() const
62{ 62{
63 return CloseHandling; 63 return CloseHandling;
64} 64}
65 65
66//! Returns amount of menu items 66//! Returns amount of menu items
67u32 CGUIContextMenu::getItemCount() const 67u32 CGUIContextMenu::getItemCount() const
68{ 68{
69 return Items.size(); 69 return Items.size();
70} 70}
71 71
72 72
73//! Adds a menu item. 73//! Adds a menu item.
74u32 CGUIContextMenu::addItem(const wchar_t* text, s32 commandId, bool enabled, bool hasSubMenu, bool checked, bool autoChecking) 74u32 CGUIContextMenu::addItem(const wchar_t* text, s32 commandId, bool enabled, bool hasSubMenu, bool checked, bool autoChecking)
75{ 75{
76 return insertItem(Items.size(), text, commandId, enabled, hasSubMenu, checked, autoChecking); 76 return insertItem(Items.size(), text, commandId, enabled, hasSubMenu, checked, autoChecking);
77} 77}
78 78
79//! Insert a menu item at specified position. 79//! Insert a menu item at specified position.
80u32 CGUIContextMenu::insertItem(u32 idx, const wchar_t* text, s32 commandId, bool enabled, 80u32 CGUIContextMenu::insertItem(u32 idx, const wchar_t* text, s32 commandId, bool enabled,
81 bool hasSubMenu, bool checked, bool autoChecking) 81 bool hasSubMenu, bool checked, bool autoChecking)
82{ 82{
83 SItem s; 83 SItem s;
84 s.Enabled = enabled; 84 s.Enabled = enabled;
85 s.Checked = checked; 85 s.Checked = checked;
86 s.AutoChecking = autoChecking; 86 s.AutoChecking = autoChecking;
87 s.Text = text; 87 s.Text = text;
88 s.IsSeparator = (text == 0); 88 s.IsSeparator = (text == 0);
89 s.SubMenu = 0; 89 s.SubMenu = 0;
90 s.CommandId = commandId; 90 s.CommandId = commandId;
91 91
92 if (hasSubMenu) 92 if (hasSubMenu)
93 { 93 {
94 s.SubMenu = new CGUIContextMenu(Environment, this, commandId, 94 s.SubMenu = new CGUIContextMenu(Environment, this, commandId,
95 core::rect<s32>(0,0,100,100), false, false); 95 core::rect<s32>(0,0,100,100), false, false);
96 s.SubMenu->setVisible(false); 96 s.SubMenu->setVisible(false);
97 } 97 }
98 98
99 u32 result = idx; 99 u32 result = idx;
100 if ( idx < Items.size() ) 100 if ( idx < Items.size() )
101 { 101 {
102 Items.insert(s, idx); 102 Items.insert(s, idx);
103 } 103 }
104 else 104 else
105 { 105 {
106 Items.push_back(s); 106 Items.push_back(s);
107 result = Items.size() - 1; 107 result = Items.size() - 1;
108 } 108 }
109 109
110 recalculateSize(); 110 recalculateSize();
111 return result; 111 return result;
112} 112}
113 113
114s32 CGUIContextMenu::findItemWithCommandId(s32 commandId, u32 idxStartSearch) const 114s32 CGUIContextMenu::findItemWithCommandId(s32 commandId, u32 idxStartSearch) const
115{ 115{
116 for ( u32 i=idxStartSearch; i<Items.size(); ++i ) 116 for ( u32 i=idxStartSearch; i<Items.size(); ++i )
117 { 117 {
118 if ( Items[i].CommandId == commandId ) 118 if ( Items[i].CommandId == commandId )
119 { 119 {
120 return (s32)i; 120 return (s32)i;
121 } 121 }
122 } 122 }
123 return -1; 123 return -1;
124} 124}
125 125
126//! Adds a sub menu from an element that already exists. 126//! Adds a sub menu from an element that already exists.
127void CGUIContextMenu::setSubMenu(u32 index, CGUIContextMenu* menu) 127void CGUIContextMenu::setSubMenu(u32 index, CGUIContextMenu* menu)
128{ 128{
129 if (index >= Items.size()) 129 if (index >= Items.size())
130 return; 130 return;
131 131
132 if (menu) 132 if (menu)
133 menu->grab(); 133 menu->grab();
134 if (Items[index].SubMenu) 134 if (Items[index].SubMenu)
135 Items[index].SubMenu->drop(); 135 Items[index].SubMenu->drop();
136 136
137 Items[index].SubMenu = menu; 137 Items[index].SubMenu = menu;
138 menu->setVisible(false); 138 menu->setVisible(false);
139 139
140 if (Items[index].SubMenu) 140 if (Items[index].SubMenu)
141 { 141 {
142 menu->AllowFocus = false; 142 menu->AllowFocus = false;
143 if ( Environment->getFocus() == menu ) 143 if ( Environment->getFocus() == menu )
144 { 144 {
145 Environment->setFocus( this ); 145 Environment->setFocus( this );
146 } 146 }
147 } 147 }
148 148
149 recalculateSize(); 149 recalculateSize();
150} 150}
151 151
152 152
153//! Adds a separator item to the menu 153//! Adds a separator item to the menu
154void CGUIContextMenu::addSeparator() 154void CGUIContextMenu::addSeparator()
155{ 155{
156 addItem(0, -1, true, false, false, false); 156 addItem(0, -1, true, false, false, false);
157} 157}
158 158
159 159
160//! Returns text of the menu item. 160//! Returns text of the menu item.
161const wchar_t* CGUIContextMenu::getItemText(u32 idx) const 161const wchar_t* CGUIContextMenu::getItemText(u32 idx) const
162{ 162{
163 if (idx >= Items.size()) 163 if (idx >= Items.size())
164 return 0; 164 return 0;
165 165
166 return Items[idx].Text.c_str(); 166 return Items[idx].Text.c_str();
167} 167}
168 168
169 169
170//! Sets text of the menu item. 170//! Sets text of the menu item.
171void CGUIContextMenu::setItemText(u32 idx, const wchar_t* text) 171void CGUIContextMenu::setItemText(u32 idx, const wchar_t* text)
172{ 172{
173 if (idx >= Items.size()) 173 if (idx >= Items.size())
174 return; 174 return;
175 175
176 Items[idx].Text = text; 176 Items[idx].Text = text;
177 recalculateSize(); 177 recalculateSize();
178} 178}
179 179
180//! should the element change the checked status on clicking 180//! should the element change the checked status on clicking
181void CGUIContextMenu::setItemAutoChecking(u32 idx, bool autoChecking) 181void CGUIContextMenu::setItemAutoChecking(u32 idx, bool autoChecking)
182{ 182{
183 if ( idx >= Items.size()) 183 if ( idx >= Items.size())
184 return; 184 return;
185 185
186 Items[idx].AutoChecking = autoChecking; 186 Items[idx].AutoChecking = autoChecking;
187} 187}
188 188
189//! does the element change the checked status on clicking 189//! does the element change the checked status on clicking
190bool CGUIContextMenu::getItemAutoChecking(u32 idx) const 190bool CGUIContextMenu::getItemAutoChecking(u32 idx) const
191{ 191{
192 if (idx >= Items.size()) 192 if (idx >= Items.size())
193 return false; 193 return false;
194 194
195 return Items[idx].AutoChecking; 195 return Items[idx].AutoChecking;
196} 196}
197 197
198 198
199//! Returns if a menu item is enabled 199//! Returns if a menu item is enabled
200bool CGUIContextMenu::isItemEnabled(u32 idx) const 200bool CGUIContextMenu::isItemEnabled(u32 idx) const
201{ 201{
202 if (idx >= Items.size()) 202 if (idx >= Items.size())
203 { 203 {
204 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 204 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
205 return false; 205 return false;
206 } 206 }
207 207
208 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 208 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
209 return Items[idx].Enabled; 209 return Items[idx].Enabled;
210} 210}
211 211
212 212
213//! Returns if a menu item is checked 213//! Returns if a menu item is checked
214bool CGUIContextMenu::isItemChecked(u32 idx) const 214bool CGUIContextMenu::isItemChecked(u32 idx) const
215{ 215{
216 if (idx >= Items.size()) 216 if (idx >= Items.size())
217 { 217 {
218 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 218 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
219 return false; 219 return false;
220 } 220 }
221 221
222 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 222 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
223 return Items[idx].Checked; 223 return Items[idx].Checked;
224} 224}
225 225
226 226
227//! Sets if the menu item should be enabled. 227//! Sets if the menu item should be enabled.
228void CGUIContextMenu::setItemEnabled(u32 idx, bool enabled) 228void CGUIContextMenu::setItemEnabled(u32 idx, bool enabled)
229{ 229{
230 if (idx >= Items.size()) 230 if (idx >= Items.size())
231 return; 231 return;
232 232
233 Items[idx].Enabled = enabled; 233 Items[idx].Enabled = enabled;
234} 234}
235 235
236 236
237//! Sets if the menu item should be checked. 237//! Sets if the menu item should be checked.
238void CGUIContextMenu::setItemChecked(u32 idx, bool checked ) 238void CGUIContextMenu::setItemChecked(u32 idx, bool checked )
239{ 239{
240 if (idx >= Items.size()) 240 if (idx >= Items.size())
241 return; 241 return;
242 242
243 Items[idx].Checked = checked; 243 Items[idx].Checked = checked;
244} 244}
245 245
246 246
247//! Removes a menu item 247//! Removes a menu item
248void CGUIContextMenu::removeItem(u32 idx) 248void CGUIContextMenu::removeItem(u32 idx)
249{ 249{
250 if (idx >= Items.size()) 250 if (idx >= Items.size())
251 return; 251 return;
252 252
253 if (Items[idx].SubMenu) 253 if (Items[idx].SubMenu)
254 { 254 {
255 Items[idx].SubMenu->drop(); 255 Items[idx].SubMenu->drop();
256 Items[idx].SubMenu = 0; 256 Items[idx].SubMenu = 0;
257 } 257 }
258 258
259 Items.erase(idx); 259 Items.erase(idx);
260 recalculateSize(); 260 recalculateSize();
261} 261}
262 262
263 263
264//! Removes all menu items 264//! Removes all menu items
265void CGUIContextMenu::removeAllItems() 265void CGUIContextMenu::removeAllItems()
266{ 266{
267 for (u32 i=0; i<Items.size(); ++i) 267 for (u32 i=0; i<Items.size(); ++i)
268 if (Items[i].SubMenu) 268 if (Items[i].SubMenu)
269 Items[i].SubMenu->drop(); 269 Items[i].SubMenu->drop();
270 270
271 Items.clear(); 271 Items.clear();
272 recalculateSize(); 272 recalculateSize();
273} 273}
274 274
275 275
276//! called if an event happened. 276//! called if an event happened.
277bool CGUIContextMenu::OnEvent(const SEvent& event) 277bool CGUIContextMenu::OnEvent(const SEvent& event)
278{ 278{
279 if (isEnabled()) 279 if (isEnabled())
280 { 280 {
281 281
282 switch(event.EventType) 282 switch(event.EventType)
283 { 283 {
284 case EET_GUI_EVENT: 284 case EET_GUI_EVENT:
285 switch(event.GUIEvent.EventType) 285 switch(event.GUIEvent.EventType)
286 { 286 {
287 case EGET_ELEMENT_FOCUS_LOST: 287 case EGET_ELEMENT_FOCUS_LOST:
288 if (event.GUIEvent.Caller == this && !isMyChild(event.GUIEvent.Element) && AllowFocus) 288 if (event.GUIEvent.Caller == this && !isMyChild(event.GUIEvent.Element) && AllowFocus)
289 { 289 {
290 // set event parent of submenus 290 // set event parent of submenus
291 IGUIElement * p = EventParent ? EventParent : Parent; 291 IGUIElement * p = EventParent ? EventParent : Parent;
292 setEventParent(p); 292 setEventParent(p);
293 293
294 SEvent event; 294 SEvent event;
295 event.EventType = EET_GUI_EVENT; 295 event.EventType = EET_GUI_EVENT;
296 event.GUIEvent.Caller = this; 296 event.GUIEvent.Caller = this;
297 event.GUIEvent.Element = 0; 297 event.GUIEvent.Element = 0;
298 event.GUIEvent.EventType = EGET_ELEMENT_CLOSED; 298 event.GUIEvent.EventType = EGET_ELEMENT_CLOSED;
299 if ( !p->OnEvent(event) ) 299 if ( !p->OnEvent(event) )
300 { 300 {
301 if ( CloseHandling & ECMC_HIDE ) 301 if ( CloseHandling & ECMC_HIDE )
302 { 302 {
303 setVisible(false); 303 setVisible(false);
304 } 304 }
305 if ( CloseHandling & ECMC_REMOVE ) 305 if ( CloseHandling & ECMC_REMOVE )
306 { 306 {
307 remove(); 307 remove();
308 } 308 }
309 } 309 }
310 310
311 return false; 311 return false;
312 } 312 }
313 break; 313 break;
314 case EGET_ELEMENT_FOCUSED: 314 case EGET_ELEMENT_FOCUSED:
315 if (event.GUIEvent.Caller == this && !AllowFocus) 315 if (event.GUIEvent.Caller == this && !AllowFocus)
316 { 316 {
317 return true; 317 return true;
318 } 318 }
319 break; 319 break;
320 default: 320 default:
321 break; 321 break;
322 } 322 }
323 break; 323 break;
324 case EET_MOUSE_INPUT_EVENT: 324 case EET_MOUSE_INPUT_EVENT:
325 switch(event.MouseInput.Event) 325 switch(event.MouseInput.Event)
326 { 326 {
327 case EMIE_LMOUSE_LEFT_UP: 327 case EMIE_LMOUSE_LEFT_UP:
328 { 328 {
329 // menu might be removed if it loses focus in sendClick, so grab a reference 329 // menu might be removed if it loses focus in sendClick, so grab a reference
330 grab(); 330 grab();
331 const u32 t = sendClick(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)); 331 const u32 t = sendClick(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
332 if ((t==0 || t==1) && Environment->hasFocus(this)) 332 if ((t==0 || t==1) && Environment->hasFocus(this))
333 Environment->removeFocus(this); 333 Environment->removeFocus(this);
334 drop(); 334 drop();
335 } 335 }
336 return true; 336 return true;
337 case EMIE_LMOUSE_PRESSED_DOWN: 337 case EMIE_LMOUSE_PRESSED_DOWN:
338 return true; 338 return true;
339 case EMIE_MOUSE_MOVED: 339 case EMIE_MOUSE_MOVED:
340 if (Environment->hasFocus(this)) 340 if (Environment->hasFocus(this))
341 highlight(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y), true); 341 highlight(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y), true);
342 return true; 342 return true;
343 default: 343 default:
344 break; 344 break;
345 } 345 }
346 break; 346 break;
347 default: 347 default:
348 break; 348 break;
349 } 349 }
350 } 350 }
351 351
352 return IGUIElement::OnEvent(event); 352 return IGUIElement::OnEvent(event);
353} 353}
354 354
355 355
356//! Sets the visible state of this element. 356//! Sets the visible state of this element.
357void CGUIContextMenu::setVisible(bool visible) 357void CGUIContextMenu::setVisible(bool visible)
358{ 358{
359 HighLighted = -1; 359 HighLighted = -1;
360 ChangeTime = os::Timer::getTime(); 360 ChangeTime = os::Timer::getTime();
361 for (u32 j=0; j<Items.size(); ++j) 361 for (u32 j=0; j<Items.size(); ++j)
362 if (Items[j].SubMenu) 362 if (Items[j].SubMenu)
363 Items[j].SubMenu->setVisible(false); 363 Items[j].SubMenu->setVisible(false);
364 364
365 IGUIElement::setVisible(visible); 365 IGUIElement::setVisible(visible);
366} 366}
367 367
368 368
369//! sends a click Returns: 369//! sends a click Returns:
370//! 0 if click went outside of the element, 370//! 0 if click went outside of the element,
371//! 1 if a valid button was clicked, 371//! 1 if a valid button was clicked,
372//! 2 if a nonclickable element was clicked 372//! 2 if a nonclickable element was clicked
373u32 CGUIContextMenu::sendClick(const core::position2d<s32>& p) 373u32 CGUIContextMenu::sendClick(const core::position2d<s32>& p)
374{ 374{
375 u32 t = 0; 375 u32 t = 0;
376 376
377 // get number of open submenu 377 // get number of open submenu
378 s32 openmenu = -1; 378 s32 openmenu = -1;
379 s32 j; 379 s32 j;
380 for (j=0; j<(s32)Items.size(); ++j) 380 for (j=0; j<(s32)Items.size(); ++j)
381 if (Items[j].SubMenu && Items[j].SubMenu->isVisible()) 381 if (Items[j].SubMenu && Items[j].SubMenu->isVisible())
382 { 382 {
383 openmenu = j; 383 openmenu = j;
384 break; 384 break;
385 } 385 }
386 386
387 // delegate click operation to submenu 387 // delegate click operation to submenu
388 if (openmenu != -1) 388 if (openmenu != -1)
389 { 389 {
390 t = Items[j].SubMenu->sendClick(p); 390 t = Items[j].SubMenu->sendClick(p);
391 if (t != 0) 391 if (t != 0)
392 return t; // clicked something 392 return t; // clicked something
393 } 393 }
394 394
395 // check click on myself 395 // check click on myself
396 if (isPointInside(p) && 396 if (isPointInside(p) &&
397 (u32)HighLighted < Items.size()) 397 (u32)HighLighted < Items.size())
398 { 398 {
399 if (!Items[HighLighted].Enabled || 399 if (!Items[HighLighted].Enabled ||
400 Items[HighLighted].IsSeparator || 400 Items[HighLighted].IsSeparator ||
401 Items[HighLighted].SubMenu) 401 Items[HighLighted].SubMenu)
402 return 2; 402 return 2;
403 403
404 if ( Items[HighLighted].AutoChecking ) 404 if ( Items[HighLighted].AutoChecking )
405 { 405 {
406 Items[HighLighted].Checked = Items[HighLighted].Checked ? false : true; 406 Items[HighLighted].Checked = Items[HighLighted].Checked ? false : true;
407 } 407 }
408 408
409 SEvent event; 409 SEvent event;
410 event.EventType = EET_GUI_EVENT; 410 event.EventType = EET_GUI_EVENT;
411 event.GUIEvent.Caller = this; 411 event.GUIEvent.Caller = this;
412 event.GUIEvent.Element = 0; 412 event.GUIEvent.Element = 0;
413 event.GUIEvent.EventType = EGET_MENU_ITEM_SELECTED; 413 event.GUIEvent.EventType = EGET_MENU_ITEM_SELECTED;
414 if (EventParent) 414 if (EventParent)
415 EventParent->OnEvent(event); 415 EventParent->OnEvent(event);
416 else if (Parent) 416 else if (Parent)
417 Parent->OnEvent(event); 417 Parent->OnEvent(event);
418 418
419 return 1; 419 return 1;
420 } 420 }
421 421
422 return 0; 422 return 0;
423} 423}
424 424
425 425
426//! returns true, if an element was highligted 426//! returns true, if an element was highligted
427bool CGUIContextMenu::highlight(const core::position2d<s32>& p, bool canOpenSubMenu) 427bool CGUIContextMenu::highlight(const core::position2d<s32>& p, bool canOpenSubMenu)
428{ 428{
429 if (!isEnabled()) 429 if (!isEnabled())
430 { 430 {
431 return false; 431 return false;
432 } 432 }
433 433
434 // get number of open submenu 434 // get number of open submenu
435 s32 openmenu = -1; 435 s32 openmenu = -1;
436 s32 i; 436 s32 i;
437 for (i=0; i<(s32)Items.size(); ++i) 437 for (i=0; i<(s32)Items.size(); ++i)
438 if (Items[i].Enabled && Items[i].SubMenu && Items[i].SubMenu->isVisible()) 438 if (Items[i].Enabled && Items[i].SubMenu && Items[i].SubMenu->isVisible())
439 { 439 {
440 openmenu = i; 440 openmenu = i;
441 break; 441 break;
442 } 442 }
443 443
444 // delegate highlight operation to submenu 444 // delegate highlight operation to submenu
445 if (openmenu != -1) 445 if (openmenu != -1)
446 { 446 {
447 if (Items[openmenu].Enabled && Items[openmenu].SubMenu->highlight(p, canOpenSubMenu)) 447 if (Items[openmenu].Enabled && Items[openmenu].SubMenu->highlight(p, canOpenSubMenu))
448 { 448 {
449 HighLighted = openmenu; 449 HighLighted = openmenu;
450 ChangeTime = os::Timer::getTime(); 450 ChangeTime = os::Timer::getTime();
451 return true; 451 return true;
452 } 452 }
453 } 453 }
454 454
455 // highlight myself 455 // highlight myself
456 for (i=0; i<(s32)Items.size(); ++i) 456 for (i=0; i<(s32)Items.size(); ++i)
457 { 457 {
458 if (Items[i].Enabled && getHRect(Items[i], AbsoluteRect).isPointInside(p)) 458 if (Items[i].Enabled && getHRect(Items[i], AbsoluteRect).isPointInside(p))
459 { 459 {
460 HighLighted = i; 460 HighLighted = i;
461 ChangeTime = os::Timer::getTime(); 461 ChangeTime = os::Timer::getTime();
462 462
463 // make submenus visible/invisible 463 // make submenus visible/invisible
464 for (s32 j=0; j<(s32)Items.size(); ++j) 464 for (s32 j=0; j<(s32)Items.size(); ++j)
465 if (Items[j].SubMenu) 465 if (Items[j].SubMenu)
466 { 466 {
467 if ( j == i && canOpenSubMenu && Items[j].Enabled ) 467 if ( j == i && canOpenSubMenu && Items[j].Enabled )
468 Items[j].SubMenu->setVisible(true); 468 Items[j].SubMenu->setVisible(true);
469 else if ( j != i ) 469 else if ( j != i )
470 Items[j].SubMenu->setVisible(false); 470 Items[j].SubMenu->setVisible(false);
471 } 471 }
472 return true; 472 return true;
473 } 473 }
474 } 474 }
475 475
476 HighLighted = openmenu; 476 HighLighted = openmenu;
477 return false; 477 return false;
478} 478}
479 479
480 480
481//! returns the item highlight-area 481//! returns the item highlight-area
482core::rect<s32> CGUIContextMenu::getHRect(const SItem& i, const core::rect<s32>& absolute) const 482core::rect<s32> CGUIContextMenu::getHRect(const SItem& i, const core::rect<s32>& absolute) const
483{ 483{
484 core::rect<s32> r = absolute; 484 core::rect<s32> r = absolute;
485 r.UpperLeftCorner.Y += i.PosY; 485 r.UpperLeftCorner.Y += i.PosY;
486 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + i.Dim.Height; 486 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + i.Dim.Height;
487 return r; 487 return r;
488} 488}
489 489
490 490
491//! Gets drawing rect of Item 491//! Gets drawing rect of Item
492core::rect<s32> CGUIContextMenu::getRect(const SItem& i, const core::rect<s32>& absolute) const 492core::rect<s32> CGUIContextMenu::getRect(const SItem& i, const core::rect<s32>& absolute) const
493{ 493{
494 core::rect<s32> r = absolute; 494 core::rect<s32> r = absolute;
495 r.UpperLeftCorner.Y += i.PosY; 495 r.UpperLeftCorner.Y += i.PosY;
496 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + i.Dim.Height; 496 r.LowerRightCorner.Y = r.UpperLeftCorner.Y + i.Dim.Height;
497 r.UpperLeftCorner.X += 20; 497 r.UpperLeftCorner.X += 20;
498 return r; 498 return r;
499} 499}
500 500
501 501
502//! draws the element and its children 502//! draws the element and its children
503void CGUIContextMenu::draw() 503void CGUIContextMenu::draw()
504{ 504{
505 if (!IsVisible) 505 if (!IsVisible)
506 return; 506 return;
507 507
508 IGUISkin* skin = Environment->getSkin(); 508 IGUISkin* skin = Environment->getSkin();
509 509
510 if (!skin) 510 if (!skin)
511 return; 511 return;
512 512
513 IGUIFont* font = skin->getFont(EGDF_MENU); 513 IGUIFont* font = skin->getFont(EGDF_MENU);
514 if (font != LastFont) 514 if (font != LastFont)
515 { 515 {
516 if (LastFont) 516 if (LastFont)
517 LastFont->drop(); 517 LastFont->drop();
518 LastFont = font; 518 LastFont = font;
519 if (LastFont) 519 if (LastFont)
520 LastFont->grab(); 520 LastFont->grab();
521 521
522 recalculateSize(); 522 recalculateSize();
523 } 523 }
524 524
525 IGUISpriteBank* sprites = skin->getSpriteBank(); 525 IGUISpriteBank* sprites = skin->getSpriteBank();
526 526
527 core::rect<s32> rect = AbsoluteRect; 527 core::rect<s32> rect = AbsoluteRect;
528 core::rect<s32>* clip = 0; 528 core::rect<s32>* clip = 0;
529 529
530 // draw frame 530 // draw frame
531 skin->draw3DMenuPane(this, AbsoluteRect, clip); 531 skin->draw3DMenuPane(this, AbsoluteRect, clip);
532 532
533 // loop through all menu items 533 // loop through all menu items
534 534
535 rect = AbsoluteRect; 535 rect = AbsoluteRect;
536 s32 y = AbsoluteRect.UpperLeftCorner.Y; 536 s32 y = AbsoluteRect.UpperLeftCorner.Y;
537 537
538 for (s32 i=0; i<(s32)Items.size(); ++i) 538 for (s32 i=0; i<(s32)Items.size(); ++i)
539 { 539 {
540 if (Items[i].IsSeparator) 540 if (Items[i].IsSeparator)
541 { 541 {
542 // draw separator 542 // draw separator
543 rect = AbsoluteRect; 543 rect = AbsoluteRect;
544 rect.UpperLeftCorner.Y += Items[i].PosY + 3; 544 rect.UpperLeftCorner.Y += Items[i].PosY + 3;
545 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; 545 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1;
546 rect.UpperLeftCorner.X += 5; 546 rect.UpperLeftCorner.X += 5;
547 rect.LowerRightCorner.X -= 5; 547 rect.LowerRightCorner.X -= 5;
548 skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), rect, clip); 548 skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), rect, clip);
549 549
550 rect.LowerRightCorner.Y += 1; 550 rect.LowerRightCorner.Y += 1;
551 rect.UpperLeftCorner.Y += 1; 551 rect.UpperLeftCorner.Y += 1;
552 skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), rect, clip); 552 skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), rect, clip);
553 553
554 y += 10; 554 y += 10;
555 } 555 }
556 else 556 else
557 { 557 {
558 rect = getRect(Items[i], AbsoluteRect); 558 rect = getRect(Items[i], AbsoluteRect);
559 559
560 // draw highlighted 560 // draw highlighted
561 561
562 if (i == HighLighted && Items[i].Enabled) 562 if (i == HighLighted && Items[i].Enabled)
563 { 563 {
564 core::rect<s32> r = AbsoluteRect; 564 core::rect<s32> r = AbsoluteRect;
565 r.LowerRightCorner.Y = rect.LowerRightCorner.Y; 565 r.LowerRightCorner.Y = rect.LowerRightCorner.Y;
566 r.UpperLeftCorner.Y = rect.UpperLeftCorner.Y; 566 r.UpperLeftCorner.Y = rect.UpperLeftCorner.Y;
567 r.LowerRightCorner.X -= 5; 567 r.LowerRightCorner.X -= 5;
568 r.UpperLeftCorner.X += 5; 568 r.UpperLeftCorner.X += 5;
569 skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), r, clip); 569 skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), r, clip);
570 } 570 }
571 571
572 // draw text 572 // draw text
573 573
574 EGUI_DEFAULT_COLOR c = EGDC_BUTTON_TEXT; 574 EGUI_DEFAULT_COLOR c = EGDC_BUTTON_TEXT;
575 575
576 if (i == HighLighted) 576 if (i == HighLighted)
577 c = EGDC_HIGH_LIGHT_TEXT; 577 c = EGDC_HIGH_LIGHT_TEXT;
578 578
579 if (!Items[i].Enabled) 579 if (!Items[i].Enabled)
580 c = EGDC_GRAY_TEXT; 580 c = EGDC_GRAY_TEXT;
581 581
582 if (font) 582 if (font)
583 font->draw(Items[i].Text.c_str(), rect, 583 font->draw(Items[i].Text.c_str(), rect,
584 skin->getColor(c), false, true, clip); 584 skin->getColor(c), false, true, clip);
585 585
586 // draw submenu symbol 586 // draw submenu symbol
587 if (Items[i].SubMenu && sprites) 587 if (Items[i].SubMenu && sprites)
588 { 588 {
589 core::rect<s32> r = rect; 589 core::rect<s32> r = rect;
590 r.UpperLeftCorner.X = r.LowerRightCorner.X - 15; 590 r.UpperLeftCorner.X = r.LowerRightCorner.X - 15;
591 591
592 sprites->draw2DSprite(skin->getIcon(EGDI_CURSOR_RIGHT), 592 sprites->draw2DSprite(skin->getIcon(EGDI_CURSOR_RIGHT),
593 r.getCenter(), clip, skin->getColor(c), 593 r.getCenter(), clip, skin->getColor(c),
594 (i == HighLighted) ? ChangeTime : 0, 594 (i == HighLighted) ? ChangeTime : 0,
595 (i == HighLighted) ? os::Timer::getTime() : 0, 595 (i == HighLighted) ? os::Timer::getTime() : 0,
596 (i == HighLighted), true); 596 (i == HighLighted), true);
597 } 597 }
598 598
599 // draw checked symbol 599 // draw checked symbol
600 if (Items[i].Checked && sprites) 600 if (Items[i].Checked && sprites)
601 { 601 {
602 core::rect<s32> r = rect; 602 core::rect<s32> r = rect;
603 r.LowerRightCorner.X = r.UpperLeftCorner.X - 15; 603 r.LowerRightCorner.X = r.UpperLeftCorner.X - 15;
604 r.UpperLeftCorner.X = r.LowerRightCorner.X + 15; 604 r.UpperLeftCorner.X = r.LowerRightCorner.X + 15;
605 sprites->draw2DSprite(skin->getIcon(EGDI_CHECK_BOX_CHECKED), 605 sprites->draw2DSprite(skin->getIcon(EGDI_CHECK_BOX_CHECKED),
606 r.getCenter(), clip, skin->getColor(c), 606 r.getCenter(), clip, skin->getColor(c),
607 (i == HighLighted) ? ChangeTime : 0, 607 (i == HighLighted) ? ChangeTime : 0,
608 (i == HighLighted) ? os::Timer::getTime() : 0, 608 (i == HighLighted) ? os::Timer::getTime() : 0,
609 (i == HighLighted), true); 609 (i == HighLighted), true);
610 } 610 }
611 } 611 }
612 } 612 }
613 613
614 IGUIElement::draw(); 614 IGUIElement::draw();
615} 615}
616 616
617 617
618void CGUIContextMenu::recalculateSize() 618void CGUIContextMenu::recalculateSize()
619{ 619{
620 IGUIFont* font = Environment->getSkin()->getFont(EGDF_MENU); 620 IGUIFont* font = Environment->getSkin()->getFont(EGDF_MENU);
621 621
622 if (!font) 622 if (!font)
623 return; 623 return;
624 624
625 core::rect<s32> rect; 625 core::rect<s32> rect;
626 rect.UpperLeftCorner = RelativeRect.UpperLeftCorner; 626 rect.UpperLeftCorner = RelativeRect.UpperLeftCorner;
627 u32 width = 100; 627 u32 width = 100;
628 u32 height = 3; 628 u32 height = 3;
629 629
630 u32 i; 630 u32 i;
631 for (i=0; i<Items.size(); ++i) 631 for (i=0; i<Items.size(); ++i)
632 { 632 {
633 if (Items[i].IsSeparator) 633 if (Items[i].IsSeparator)
634 { 634 {
635 Items[i].Dim.Width = 100; 635 Items[i].Dim.Width = 100;
636 Items[i].Dim.Height = 10; 636 Items[i].Dim.Height = 10;
637 } 637 }
638 else 638 else
639 { 639 {
640 Items[i].Dim = font->getDimension(Items[i].Text.c_str()); 640 Items[i].Dim = font->getDimension(Items[i].Text.c_str());
641 Items[i].Dim.Width += 40; 641 Items[i].Dim.Width += 40;
642 642
643 if (Items[i].Dim.Width > width) 643 if (Items[i].Dim.Width > width)
644 width = Items[i].Dim.Width; 644 width = Items[i].Dim.Width;
645 } 645 }
646 646
647 Items[i].PosY = height; 647 Items[i].PosY = height;
648 height += Items[i].Dim.Height; 648 height += Items[i].Dim.Height;
649 } 649 }
650 650
651 height += 5; 651 height += 5;
652 652
653 if (height < 10) 653 if (height < 10)
654 height = 10; 654 height = 10;
655 655
656 rect.LowerRightCorner.X = RelativeRect.UpperLeftCorner.X + width; 656 rect.LowerRightCorner.X = RelativeRect.UpperLeftCorner.X + width;
657 rect.LowerRightCorner.Y = RelativeRect.UpperLeftCorner.Y + height; 657 rect.LowerRightCorner.Y = RelativeRect.UpperLeftCorner.Y + height;
658 658
659 setRelativePosition(rect); 659 setRelativePosition(rect);
660 660
661 // recalculate submenus 661 // recalculate submenus
662 for (i=0; i<Items.size(); ++i) 662 for (i=0; i<Items.size(); ++i)
663 { 663 {
664 if (Items[i].SubMenu) 664 if (Items[i].SubMenu)
665 { 665 {
666 // move submenu 666 // move submenu
667 const s32 w = Items[i].SubMenu->getAbsolutePosition().getWidth(); 667 const s32 w = Items[i].SubMenu->getAbsolutePosition().getWidth();
668 const s32 h = Items[i].SubMenu->getAbsolutePosition().getHeight(); 668 const s32 h = Items[i].SubMenu->getAbsolutePosition().getHeight();
669 669
670 core::rect<s32> subRect(width-5, Items[i].PosY, width+w-5, Items[i].PosY+h); 670 core::rect<s32> subRect(width-5, Items[i].PosY, width+w-5, Items[i].PosY+h);
671 671
672 // if it would be drawn beyond the right border, then add it to the left side 672 // if it would be drawn beyond the right border, then add it to the left side
673 gui::IGUIElement * root = Environment->getRootGUIElement(); 673 gui::IGUIElement * root = Environment->getRootGUIElement();
674 if ( root ) 674 if ( root )
675 { 675 {
676 core::rect<s32> rectRoot( root->getAbsolutePosition() ); 676 core::rect<s32> rectRoot( root->getAbsolutePosition() );
677 if ( getAbsolutePosition().UpperLeftCorner.X+subRect.LowerRightCorner.X > rectRoot.LowerRightCorner.X ) 677 if ( getAbsolutePosition().UpperLeftCorner.X+subRect.LowerRightCorner.X > rectRoot.LowerRightCorner.X )
678 { 678 {
679 subRect.UpperLeftCorner.X = -w; 679 subRect.UpperLeftCorner.X = -w;
680 subRect.LowerRightCorner.X = 0; 680 subRect.LowerRightCorner.X = 0;
681 } 681 }
682 } 682 }
683 683
684 Items[i].SubMenu->setRelativePosition(subRect); 684 Items[i].SubMenu->setRelativePosition(subRect);
685 } 685 }
686 } 686 }
687} 687}
688 688
689 689
690//! Returns the selected item in the menu 690//! Returns the selected item in the menu
691s32 CGUIContextMenu::getSelectedItem() const 691s32 CGUIContextMenu::getSelectedItem() const
692{ 692{
693 return HighLighted; 693 return HighLighted;
694} 694}
695 695
696 696
697//! \return Returns a pointer to the submenu of an item. 697//! \return Returns a pointer to the submenu of an item.
698IGUIContextMenu* CGUIContextMenu::getSubMenu(u32 idx) const 698IGUIContextMenu* CGUIContextMenu::getSubMenu(u32 idx) const
699{ 699{
700 if (idx >= Items.size()) 700 if (idx >= Items.size())
701 return 0; 701 return 0;
702 702
703 return Items[idx].SubMenu; 703 return Items[idx].SubMenu;
704} 704}
705 705
706 706
707//! Returns command id of a menu item 707//! Returns command id of a menu item
708s32 CGUIContextMenu::getItemCommandId(u32 idx) const 708s32 CGUIContextMenu::getItemCommandId(u32 idx) const
709{ 709{
710 if (idx >= Items.size()) 710 if (idx >= Items.size())
711 return -1; 711 return -1;
712 712
713 return Items[idx].CommandId; 713 return Items[idx].CommandId;
714} 714}
715 715
716 716
717//! Sets the command id of a menu item 717//! Sets the command id of a menu item
718void CGUIContextMenu::setItemCommandId(u32 idx, s32 id) 718void CGUIContextMenu::setItemCommandId(u32 idx, s32 id)
719{ 719{
720 if (idx >= Items.size()) 720 if (idx >= Items.size())
721 return; 721 return;
722 722
723 Items[idx].CommandId = id; 723 Items[idx].CommandId = id;
724} 724}
725 725
726 726
727//! Writes attributes of the element. 727//! Writes attributes of the element.
728void CGUIContextMenu::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const 728void CGUIContextMenu::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
729{ 729{
730 IGUIElement::serializeAttributes(out,options); 730 IGUIElement::serializeAttributes(out,options);
731 out->addPosition2d("Position", Pos); 731 out->addPosition2d("Position", Pos);
732 732
733 if (Parent->getType() == EGUIET_CONTEXT_MENU || Parent->getType() == EGUIET_MENU ) 733 if (Parent->getType() == EGUIET_CONTEXT_MENU || Parent->getType() == EGUIET_MENU )
734 { 734 {
735 const IGUIContextMenu* const ptr = (const IGUIContextMenu*)Parent; 735 const IGUIContextMenu* const ptr = (const IGUIContextMenu*)Parent;
736 // find the position of this item in its parent's list 736 // find the position of this item in its parent's list
737 u32 i; 737 u32 i;
738 // VC6 needs the cast for this 738 // VC6 needs the cast for this
739 for (i=0; (i<ptr->getItemCount()) && (ptr->getSubMenu(i) != (const IGUIContextMenu*)this); ++i) 739 for (i=0; (i<ptr->getItemCount()) && (ptr->getSubMenu(i) != (const IGUIContextMenu*)this); ++i)
740 ; // do nothing 740 ; // do nothing
741 741
742 out->addInt("ParentItem", i); 742 out->addInt("ParentItem", i);
743 } 743 }
744 744
745 out->addInt("CloseHandling", (s32)CloseHandling); 745 out->addInt("CloseHandling", (s32)CloseHandling);
746 746
747 // write out the item list 747 // write out the item list
748 out->addInt("ItemCount", Items.size()); 748 out->addInt("ItemCount", Items.size());
749 749
750 core::stringc tmp; 750 core::stringc tmp;
751 751
752 for (u32 i=0; i < Items.size(); ++i) 752 for (u32 i=0; i < Items.size(); ++i)
753 { 753 {
754 tmp = "IsSeparator"; tmp += i; 754 tmp = "IsSeparator"; tmp += i;
755 out->addBool(tmp.c_str(), Items[i].IsSeparator); 755 out->addBool(tmp.c_str(), Items[i].IsSeparator);
756 756
757 if (!Items[i].IsSeparator) 757 if (!Items[i].IsSeparator)
758 { 758 {
759 tmp = "Text"; tmp += i; 759 tmp = "Text"; tmp += i;
760 out->addString(tmp.c_str(), Items[i].Text.c_str()); 760 out->addString(tmp.c_str(), Items[i].Text.c_str());
761 tmp = "CommandID"; tmp += i; 761 tmp = "CommandID"; tmp += i;
762 out->addInt(tmp.c_str(), Items[i].CommandId); 762 out->addInt(tmp.c_str(), Items[i].CommandId);
763 tmp = "Enabled"; tmp += i; 763 tmp = "Enabled"; tmp += i;
764 out->addBool(tmp.c_str(), Items[i].Enabled); 764 out->addBool(tmp.c_str(), Items[i].Enabled);
765 tmp = "Checked"; tmp += i; 765 tmp = "Checked"; tmp += i;
766 out->addBool(tmp.c_str(), Items[i].Checked); 766 out->addBool(tmp.c_str(), Items[i].Checked);
767 tmp = "AutoChecking"; tmp += i; 767 tmp = "AutoChecking"; tmp += i;
768 out->addBool(tmp.c_str(), Items[i].AutoChecking); 768 out->addBool(tmp.c_str(), Items[i].AutoChecking);
769 } 769 }
770 } 770 }
771} 771}
772 772
773 773
774//! Reads attributes of the element 774//! Reads attributes of the element
775void CGUIContextMenu::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) 775void CGUIContextMenu::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
776{ 776{
777 IGUIElement::deserializeAttributes(in,options); 777 IGUIElement::deserializeAttributes(in,options);
778 778
779 Pos = in->getAttributeAsPosition2d("Position"); 779 Pos = in->getAttributeAsPosition2d("Position");
780 780
781 // link to this item's parent 781 // link to this item's parent
782 if (Parent && ( Parent->getType() == EGUIET_CONTEXT_MENU || Parent->getType() == EGUIET_MENU ) ) 782 if (Parent && ( Parent->getType() == EGUIET_CONTEXT_MENU || Parent->getType() == EGUIET_MENU ) )
783 ((CGUIContextMenu*)Parent)->setSubMenu(in->getAttributeAsInt("ParentItem"),this); 783 ((CGUIContextMenu*)Parent)->setSubMenu(in->getAttributeAsInt("ParentItem"),this);
784 784
785 CloseHandling = (ECONTEXT_MENU_CLOSE)in->getAttributeAsInt("CloseHandling"); 785 CloseHandling = (ECONTEXT_MENU_CLOSE)in->getAttributeAsInt("CloseHandling");
786 786
787 removeAllItems(); 787 removeAllItems();
788 788
789 // read the item list 789 // read the item list
790 const s32 count = in->getAttributeAsInt("ItemCount"); 790 const s32 count = in->getAttributeAsInt("ItemCount");
791 791
792 for (s32 i=0; i<count; ++i) 792 for (s32 i=0; i<count; ++i)
793 { 793 {
794 core::stringc tmp; 794 core::stringc tmp;
795 core::stringw txt; 795 core::stringw txt;
796 s32 commandid=-1; 796 s32 commandid=-1;
797 bool enabled=true; 797 bool enabled=true;
798 bool checked=false; 798 bool checked=false;
799 bool autochecking=false; 799 bool autochecking=false;
800 800
801 tmp = "IsSeparator"; tmp += i; 801 tmp = "IsSeparator"; tmp += i;
802 if ( in->existsAttribute(tmp.c_str()) && in->getAttributeAsBool(tmp.c_str()) ) 802 if ( in->existsAttribute(tmp.c_str()) && in->getAttributeAsBool(tmp.c_str()) )
803 addSeparator(); 803 addSeparator();
804 else 804 else
805 { 805 {
806 tmp = "Text"; tmp += i; 806 tmp = "Text"; tmp += i;
807 if ( in->existsAttribute(tmp.c_str()) ) 807 if ( in->existsAttribute(tmp.c_str()) )
808 txt = in->getAttributeAsStringW(tmp.c_str()); 808 txt = in->getAttributeAsStringW(tmp.c_str());
809 809
810 tmp = "CommandID"; tmp += i; 810 tmp = "CommandID"; tmp += i;
811 if ( in->existsAttribute(tmp.c_str()) ) 811 if ( in->existsAttribute(tmp.c_str()) )
812 commandid = in->getAttributeAsInt(tmp.c_str()); 812 commandid = in->getAttributeAsInt(tmp.c_str());
813 813
814 tmp = "Enabled"; tmp += i; 814 tmp = "Enabled"; tmp += i;
815 if ( in->existsAttribute(tmp.c_str()) ) 815 if ( in->existsAttribute(tmp.c_str()) )
816 enabled = in->getAttributeAsBool(tmp.c_str()); 816 enabled = in->getAttributeAsBool(tmp.c_str());
817 817
818 tmp = "Checked"; tmp += i; 818 tmp = "Checked"; tmp += i;
819 if ( in->existsAttribute(tmp.c_str()) ) 819 if ( in->existsAttribute(tmp.c_str()) )
820 checked = in->getAttributeAsBool(tmp.c_str()); 820 checked = in->getAttributeAsBool(tmp.c_str());
821 821
822 tmp = "AutoChecking"; tmp += i; 822 tmp = "AutoChecking"; tmp += i;
823 if ( in->existsAttribute(tmp.c_str()) ) 823 if ( in->existsAttribute(tmp.c_str()) )
824 autochecking = in->getAttributeAsBool(tmp.c_str()); 824 autochecking = in->getAttributeAsBool(tmp.c_str());
825 825
826 addItem(core::stringw(txt.c_str()).c_str(), commandid, enabled, false, checked, autochecking); 826 addItem(core::stringw(txt.c_str()).c_str(), commandid, enabled, false, checked, autochecking);
827 } 827 }
828 } 828 }
829 829
830 recalculateSize(); 830 recalculateSize();
831} 831}
832 832
833 833
834// because sometimes the element has no parent at click time 834// because sometimes the element has no parent at click time
835void CGUIContextMenu::setEventParent(IGUIElement *parent) 835void CGUIContextMenu::setEventParent(IGUIElement *parent)
836{ 836{
837 EventParent = parent; 837 EventParent = parent;
838 838
839 for (u32 i=0; i<Items.size(); ++i) 839 for (u32 i=0; i<Items.size(); ++i)
840 if (Items[i].SubMenu) 840 if (Items[i].SubMenu)
841 Items[i].SubMenu->setEventParent(parent); 841 Items[i].SubMenu->setEventParent(parent);
842} 842}
843 843
844 844
845bool CGUIContextMenu::hasOpenSubMenu() const 845bool CGUIContextMenu::hasOpenSubMenu() const
846{ 846{
847 for (u32 i=0; i<Items.size(); ++i) 847 for (u32 i=0; i<Items.size(); ++i)
848 if (Items[i].SubMenu && Items[i].SubMenu->isVisible()) 848 if (Items[i].SubMenu && Items[i].SubMenu->isVisible())
849 return true; 849 return true;
850 850
851 return false; 851 return false;
852} 852}
853 853
854 854
855void CGUIContextMenu::closeAllSubMenus() 855void CGUIContextMenu::closeAllSubMenus()
856{ 856{
857 for (u32 i=0; i<Items.size(); ++i) 857 for (u32 i=0; i<Items.size(); ++i)
858 if (Items[i].SubMenu) 858 if (Items[i].SubMenu)
859 Items[i].SubMenu->setVisible(false); 859 Items[i].SubMenu->setVisible(false);
860 860
861 //HighLighted = -1; 861 //HighLighted = -1;
862} 862}
863 863
864 864
865} // end namespace 865} // end namespace
866} // end namespace 866} // end namespace
867 867
868#endif // _IRR_COMPILE_WITH_GUI_ 868#endif // _IRR_COMPILE_WITH_GUI_
869 869