aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CGUIModalScreen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CGUIModalScreen.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CGUIModalScreen.cpp470
1 files changed, 235 insertions, 235 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUIModalScreen.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUIModalScreen.cpp
index 879cb49..d77e079 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CGUIModalScreen.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUIModalScreen.cpp
@@ -1,235 +1,235 @@
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 "CGUIModalScreen.h" 5#include "CGUIModalScreen.h"
6#ifdef _IRR_COMPILE_WITH_GUI_ 6#ifdef _IRR_COMPILE_WITH_GUI_
7 7
8#include "IGUIEnvironment.h" 8#include "IGUIEnvironment.h"
9#include "os.h" 9#include "os.h"
10#include "IVideoDriver.h" 10#include "IVideoDriver.h"
11#include "IGUISkin.h" 11#include "IGUISkin.h"
12 12
13namespace irr 13namespace irr
14{ 14{
15namespace gui 15namespace gui
16{ 16{
17 17
18//! constructor 18//! constructor
19CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* parent, s32 id) 19CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* parent, s32 id)
20: IGUIElement(EGUIET_MODAL_SCREEN, environment, parent, id, core::recti(0, 0, parent->getAbsolutePosition().getWidth(), parent->getAbsolutePosition().getHeight()) ), 20: IGUIElement(EGUIET_MODAL_SCREEN, environment, parent, id, core::recti(0, 0, parent->getAbsolutePosition().getWidth(), parent->getAbsolutePosition().getHeight()) ),
21 MouseDownTime(0) 21 MouseDownTime(0)
22{ 22{
23 #ifdef _DEBUG 23 #ifdef _DEBUG
24 setDebugName("CGUIModalScreen"); 24 setDebugName("CGUIModalScreen");
25 #endif 25 #endif
26 setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); 26 setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
27 27
28 // this element is a tab group 28 // this element is a tab group
29 setTabGroup(true); 29 setTabGroup(true);
30} 30}
31 31
32bool CGUIModalScreen::canTakeFocus(IGUIElement* target) const 32bool CGUIModalScreen::canTakeFocus(IGUIElement* target) const
33{ 33{
34 return (target && ((const IGUIElement*)target == this // this element can take it 34 return (target && ((const IGUIElement*)target == this // this element can take it
35 || isMyChild(target) // own children also 35 || isMyChild(target) // own children also
36 || (target->getType() == EGUIET_MODAL_SCREEN ) // other modals also fine (is now on top or explicitely requested) 36 || (target->getType() == EGUIET_MODAL_SCREEN ) // other modals also fine (is now on top or explicitely requested)
37 || (target->getParent() && target->getParent()->getType() == EGUIET_MODAL_SCREEN ))) // children of other modals will do 37 || (target->getParent() && target->getParent()->getType() == EGUIET_MODAL_SCREEN ))) // children of other modals will do
38 ; 38 ;
39} 39}
40 40
41bool CGUIModalScreen::isVisible() const 41bool CGUIModalScreen::isVisible() const
42{ 42{
43 // any parent invisible? 43 // any parent invisible?
44 IGUIElement * parentElement = getParent(); 44 IGUIElement * parentElement = getParent();
45 while ( parentElement ) 45 while ( parentElement )
46 { 46 {
47 if ( !parentElement->isVisible() ) 47 if ( !parentElement->isVisible() )
48 return false; 48 return false;
49 parentElement = parentElement->getParent(); 49 parentElement = parentElement->getParent();
50 } 50 }
51 51
52 // if we have no children then the modal is probably abused as a way to block input 52 // if we have no children then the modal is probably abused as a way to block input
53 if ( Children.empty() ) 53 if ( Children.empty() )
54 { 54 {
55 return IGUIElement::isVisible(); 55 return IGUIElement::isVisible();
56 } 56 }
57 57
58 // any child visible? 58 // any child visible?
59 bool visible = false; 59 bool visible = false;
60 core::list<IGUIElement*>::ConstIterator it = Children.begin(); 60 core::list<IGUIElement*>::ConstIterator it = Children.begin();
61 for (; it != Children.end(); ++it) 61 for (; it != Children.end(); ++it)
62 { 62 {
63 if ( (*it)->isVisible() ) 63 if ( (*it)->isVisible() )
64 { 64 {
65 visible = true; 65 visible = true;
66 break; 66 break;
67 } 67 }
68 } 68 }
69 return visible; 69 return visible;
70} 70}
71 71
72bool CGUIModalScreen::isPointInside(const core::position2d<s32>& point) const 72bool CGUIModalScreen::isPointInside(const core::position2d<s32>& point) const
73{ 73{
74 return true; 74 return true;
75} 75}
76 76
77//! called if an event happened. 77//! called if an event happened.
78bool CGUIModalScreen::OnEvent(const SEvent& event) 78bool CGUIModalScreen::OnEvent(const SEvent& event)
79{ 79{
80 if (!isEnabled() || !isVisible() ) 80 if (!isEnabled() || !isVisible() )
81 return IGUIElement::OnEvent(event); 81 return IGUIElement::OnEvent(event);
82 82
83 switch(event.EventType) 83 switch(event.EventType)
84 { 84 {
85 case EET_GUI_EVENT: 85 case EET_GUI_EVENT:
86 switch(event.GUIEvent.EventType) 86 switch(event.GUIEvent.EventType)
87 { 87 {
88 case EGET_ELEMENT_FOCUSED: 88 case EGET_ELEMENT_FOCUSED:
89 if ( event.GUIEvent.Caller == this && isMyChild(event.GUIEvent.Element) ) 89 if ( event.GUIEvent.Caller == this && isMyChild(event.GUIEvent.Element) )
90 { 90 {
91 Environment->removeFocus(0); // can't setFocus otherwise at it still has focus here 91 Environment->removeFocus(0); // can't setFocus otherwise at it still has focus here
92 Environment->setFocus(event.GUIEvent.Element); 92 Environment->setFocus(event.GUIEvent.Element);
93 MouseDownTime = os::Timer::getTime(); 93 MouseDownTime = os::Timer::getTime();
94 return true; 94 return true;
95 } 95 }
96 if ( !canTakeFocus(event.GUIEvent.Caller)) 96 if ( !canTakeFocus(event.GUIEvent.Caller))
97 { 97 {
98 if ( !Children.empty() ) 98 if ( !Children.empty() )
99 Environment->setFocus(*(Children.begin())); 99 Environment->setFocus(*(Children.begin()));
100 else 100 else
101 Environment->setFocus(this); 101 Environment->setFocus(this);
102 } 102 }
103 IGUIElement::OnEvent(event); 103 IGUIElement::OnEvent(event);
104 return false; 104 return false;
105 case EGET_ELEMENT_FOCUS_LOST: 105 case EGET_ELEMENT_FOCUS_LOST:
106 if ( !canTakeFocus(event.GUIEvent.Element)) 106 if ( !canTakeFocus(event.GUIEvent.Element))
107 { 107 {
108 if ( isMyChild(event.GUIEvent.Caller) ) 108 if ( isMyChild(event.GUIEvent.Caller) )
109 { 109 {
110 if ( !Children.empty() ) 110 if ( !Children.empty() )
111 Environment->setFocus(*(Children.begin())); 111 Environment->setFocus(*(Children.begin()));
112 else 112 else
113 Environment->setFocus(this); 113 Environment->setFocus(this);
114 } 114 }
115 else 115 else
116 { 116 {
117 MouseDownTime = os::Timer::getTime(); 117 MouseDownTime = os::Timer::getTime();
118 } 118 }
119 return true; 119 return true;
120 } 120 }
121 else 121 else
122 { 122 {
123 return IGUIElement::OnEvent(event); 123 return IGUIElement::OnEvent(event);
124 } 124 }
125 case EGET_ELEMENT_CLOSED: 125 case EGET_ELEMENT_CLOSED:
126 // do not interfere with children being removed 126 // do not interfere with children being removed
127 return IGUIElement::OnEvent(event); 127 return IGUIElement::OnEvent(event);
128 default: 128 default:
129 break; 129 break;
130 } 130 }
131 break; 131 break;
132 case EET_MOUSE_INPUT_EVENT: 132 case EET_MOUSE_INPUT_EVENT:
133 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) 133 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
134 { 134 {
135 MouseDownTime = os::Timer::getTime(); 135 MouseDownTime = os::Timer::getTime();
136 } 136 }
137 default: 137 default:
138 break; 138 break;
139 } 139 }
140 140
141 IGUIElement::OnEvent(event); // anyone knows why events are passed on here? Causes p.e. problems when this is child of a CGUIWindow. 141 IGUIElement::OnEvent(event); // anyone knows why events are passed on here? Causes p.e. problems when this is child of a CGUIWindow.
142 142
143 return true; // absorb everything else 143 return true; // absorb everything else
144} 144}
145 145
146 146
147//! draws the element and its children 147//! draws the element and its children
148void CGUIModalScreen::draw() 148void CGUIModalScreen::draw()
149{ 149{
150 IGUISkin *skin = Environment->getSkin(); 150 IGUISkin *skin = Environment->getSkin();
151 151
152 if (!skin) 152 if (!skin)
153 return; 153 return;
154 154
155 u32 now = os::Timer::getTime(); 155 u32 now = os::Timer::getTime();
156 if (now - MouseDownTime < 300 && (now / 70)%2) 156 if (now - MouseDownTime < 300 && (now / 70)%2)
157 { 157 {
158 core::list<IGUIElement*>::Iterator it = Children.begin(); 158 core::list<IGUIElement*>::Iterator it = Children.begin();
159 core::rect<s32> r; 159 core::rect<s32> r;
160 video::SColor c = Environment->getSkin()->getColor(gui::EGDC_3D_HIGH_LIGHT); 160 video::SColor c = Environment->getSkin()->getColor(gui::EGDC_3D_HIGH_LIGHT);
161 161
162 for (; it != Children.end(); ++it) 162 for (; it != Children.end(); ++it)
163 { 163 {
164 if ((*it)->isVisible()) 164 if ((*it)->isVisible())
165 { 165 {
166 r = (*it)->getAbsolutePosition(); 166 r = (*it)->getAbsolutePosition();
167 r.LowerRightCorner.X += 1; 167 r.LowerRightCorner.X += 1;
168 r.LowerRightCorner.Y += 1; 168 r.LowerRightCorner.Y += 1;
169 r.UpperLeftCorner.X -= 1; 169 r.UpperLeftCorner.X -= 1;
170 r.UpperLeftCorner.Y -= 1; 170 r.UpperLeftCorner.Y -= 1;
171 171
172 skin->draw2DRectangle(this, c, r, &AbsoluteClippingRect); 172 skin->draw2DRectangle(this, c, r, &AbsoluteClippingRect);
173 } 173 }
174 } 174 }
175 } 175 }
176 176
177 IGUIElement::draw(); 177 IGUIElement::draw();
178} 178}
179 179
180 180
181//! Removes a child. 181//! Removes a child.
182void CGUIModalScreen::removeChild(IGUIElement* child) 182void CGUIModalScreen::removeChild(IGUIElement* child)
183{ 183{
184 IGUIElement::removeChild(child); 184 IGUIElement::removeChild(child);
185 185
186 if (Children.empty()) 186 if (Children.empty())
187 { 187 {
188 remove(); 188 remove();
189 } 189 }
190} 190}
191 191
192 192
193//! adds a child 193//! adds a child
194void CGUIModalScreen::addChild(IGUIElement* child) 194void CGUIModalScreen::addChild(IGUIElement* child)
195{ 195{
196 IGUIElement::addChild(child); 196 IGUIElement::addChild(child);
197 Environment->setFocus(child); 197 Environment->setFocus(child);
198} 198}
199 199
200 200
201void CGUIModalScreen::updateAbsolutePosition() 201void CGUIModalScreen::updateAbsolutePosition()
202{ 202{
203 core::rect<s32> parentRect(0,0,0,0); 203 core::rect<s32> parentRect(0,0,0,0);
204 204
205 if (Parent) 205 if (Parent)
206 { 206 {
207 parentRect = Parent->getAbsolutePosition(); 207 parentRect = Parent->getAbsolutePosition();
208 RelativeRect.UpperLeftCorner.X = 0; 208 RelativeRect.UpperLeftCorner.X = 0;
209 RelativeRect.UpperLeftCorner.Y = 0; 209 RelativeRect.UpperLeftCorner.Y = 0;
210 RelativeRect.LowerRightCorner.X = parentRect.getWidth(); 210 RelativeRect.LowerRightCorner.X = parentRect.getWidth();
211 RelativeRect.LowerRightCorner.Y = parentRect.getHeight(); 211 RelativeRect.LowerRightCorner.Y = parentRect.getHeight();
212 } 212 }
213 213
214 IGUIElement::updateAbsolutePosition(); 214 IGUIElement::updateAbsolutePosition();
215} 215}
216 216
217 217
218//! Writes attributes of the element. 218//! Writes attributes of the element.
219void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const 219void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
220{ 220{
221 IGUIElement::serializeAttributes(out,options); 221 IGUIElement::serializeAttributes(out,options);
222} 222}
223 223
224//! Reads attributes of the element 224//! Reads attributes of the element
225void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) 225void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
226{ 226{
227 IGUIElement::deserializeAttributes(in, options); 227 IGUIElement::deserializeAttributes(in, options);
228} 228}
229 229
230 230
231} // end namespace gui 231} // end namespace gui
232} // end namespace irr 232} // end namespace irr
233 233
234#endif // _IRR_COMPILE_WITH_GUI_ 234#endif // _IRR_COMPILE_WITH_GUI_
235 235