diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CGUICheckBox.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CGUICheckBox.cpp | 205 |
1 files changed, 0 insertions, 205 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUICheckBox.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUICheckBox.cpp deleted file mode 100644 index 17598ea..0000000 --- a/libraries/irrlicht-1.8/source/Irrlicht/CGUICheckBox.cpp +++ /dev/null | |||
@@ -1,205 +0,0 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #include "CGUICheckBox.h" | ||
6 | |||
7 | #ifdef _IRR_COMPILE_WITH_GUI_ | ||
8 | |||
9 | #include "IGUISkin.h" | ||
10 | #include "IGUIEnvironment.h" | ||
11 | #include "IVideoDriver.h" | ||
12 | #include "IGUIFont.h" | ||
13 | #include "os.h" | ||
14 | |||
15 | namespace irr | ||
16 | { | ||
17 | namespace gui | ||
18 | { | ||
19 | |||
20 | //! constructor | ||
21 | CGUICheckBox::CGUICheckBox(bool checked, IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) | ||
22 | : IGUICheckBox(environment, parent, id, rectangle), checkTime(0), Pressed(false), Checked(checked) | ||
23 | { | ||
24 | #ifdef _DEBUG | ||
25 | setDebugName("CGUICheckBox"); | ||
26 | #endif | ||
27 | |||
28 | // this element can be tabbed into | ||
29 | setTabStop(true); | ||
30 | setTabOrder(-1); | ||
31 | } | ||
32 | |||
33 | |||
34 | //! called if an event happened. | ||
35 | bool CGUICheckBox::OnEvent(const SEvent& event) | ||
36 | { | ||
37 | if (isEnabled()) | ||
38 | { | ||
39 | switch(event.EventType) | ||
40 | { | ||
41 | case EET_KEY_INPUT_EVENT: | ||
42 | if (event.KeyInput.PressedDown && | ||
43 | (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) | ||
44 | { | ||
45 | Pressed = true; | ||
46 | return true; | ||
47 | } | ||
48 | else | ||
49 | if (Pressed && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE) | ||
50 | { | ||
51 | Pressed = false; | ||
52 | return true; | ||
53 | } | ||
54 | else | ||
55 | if (!event.KeyInput.PressedDown && Pressed && | ||
56 | (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) | ||
57 | { | ||
58 | Pressed = false; | ||
59 | if (Parent) | ||
60 | { | ||
61 | SEvent newEvent; | ||
62 | newEvent.EventType = EET_GUI_EVENT; | ||
63 | newEvent.GUIEvent.Caller = this; | ||
64 | newEvent.GUIEvent.Element = 0; | ||
65 | Checked = !Checked; | ||
66 | newEvent.GUIEvent.EventType = EGET_CHECKBOX_CHANGED; | ||
67 | Parent->OnEvent(newEvent); | ||
68 | } | ||
69 | return true; | ||
70 | } | ||
71 | break; | ||
72 | case EET_GUI_EVENT: | ||
73 | if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) | ||
74 | { | ||
75 | if (event.GUIEvent.Caller == this) | ||
76 | Pressed = false; | ||
77 | } | ||
78 | break; | ||
79 | case EET_MOUSE_INPUT_EVENT: | ||
80 | if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) | ||
81 | { | ||
82 | Pressed = true; | ||
83 | checkTime = os::Timer::getTime(); | ||
84 | Environment->setFocus(this); | ||
85 | return true; | ||
86 | } | ||
87 | else | ||
88 | if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) | ||
89 | { | ||
90 | bool wasPressed = Pressed; | ||
91 | Environment->removeFocus(this); | ||
92 | Pressed = false; | ||
93 | |||
94 | if (wasPressed && Parent) | ||
95 | { | ||
96 | if ( !AbsoluteClippingRect.isPointInside( core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y) ) ) | ||
97 | { | ||
98 | Pressed = false; | ||
99 | return true; | ||
100 | } | ||
101 | |||
102 | SEvent newEvent; | ||
103 | newEvent.EventType = EET_GUI_EVENT; | ||
104 | newEvent.GUIEvent.Caller = this; | ||
105 | newEvent.GUIEvent.Element = 0; | ||
106 | Checked = !Checked; | ||
107 | newEvent.GUIEvent.EventType = EGET_CHECKBOX_CHANGED; | ||
108 | Parent->OnEvent(newEvent); | ||
109 | } | ||
110 | |||
111 | return true; | ||
112 | } | ||
113 | break; | ||
114 | default: | ||
115 | break; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | return IGUIElement::OnEvent(event); | ||
120 | } | ||
121 | |||
122 | |||
123 | //! draws the element and its children | ||
124 | void CGUICheckBox::draw() | ||
125 | { | ||
126 | if (!IsVisible) | ||
127 | return; | ||
128 | |||
129 | IGUISkin* skin = Environment->getSkin(); | ||
130 | if (skin) | ||
131 | { | ||
132 | const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); | ||
133 | |||
134 | core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X, | ||
135 | ((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y, | ||
136 | 0, 0); | ||
137 | |||
138 | checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; | ||
139 | checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; | ||
140 | |||
141 | EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE; | ||
142 | if ( isEnabled() ) | ||
143 | col = Pressed ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE; | ||
144 | skin->draw3DSunkenPane(this, skin->getColor(col), | ||
145 | false, true, checkRect, &AbsoluteClippingRect); | ||
146 | |||
147 | if (Checked) | ||
148 | { | ||
149 | skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), | ||
150 | checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect); | ||
151 | } | ||
152 | if (Text.size()) | ||
153 | { | ||
154 | checkRect = AbsoluteRect; | ||
155 | checkRect.UpperLeftCorner.X += height + 5; | ||
156 | |||
157 | IGUIFont* font = skin->getFont(); | ||
158 | if (font) | ||
159 | { | ||
160 | font->draw(Text.c_str(), checkRect, | ||
161 | skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect); | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | IGUIElement::draw(); | ||
166 | } | ||
167 | |||
168 | |||
169 | //! set if box is checked | ||
170 | void CGUICheckBox::setChecked(bool checked) | ||
171 | { | ||
172 | Checked = checked; | ||
173 | } | ||
174 | |||
175 | |||
176 | //! returns if box is checked | ||
177 | bool CGUICheckBox::isChecked() const | ||
178 | { | ||
179 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
180 | return Checked; | ||
181 | } | ||
182 | |||
183 | |||
184 | //! Writes attributes of the element. | ||
185 | void CGUICheckBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const | ||
186 | { | ||
187 | IGUICheckBox::serializeAttributes(out,options); | ||
188 | out->addBool("Checked", Checked); | ||
189 | } | ||
190 | |||
191 | |||
192 | //! Reads attributes of the element | ||
193 | void CGUICheckBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) | ||
194 | { | ||
195 | Checked = in->getAttributeAsBool ("Checked"); | ||
196 | |||
197 | IGUICheckBox::deserializeAttributes(in,options); | ||
198 | } | ||
199 | |||
200 | |||
201 | } // end namespace gui | ||
202 | } // end namespace irr | ||
203 | |||
204 | #endif // _IRR_COMPILE_WITH_GUI_ | ||
205 | |||