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