xoreos  0.0.5
checkbox.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/system.h"
26 #include "src/common/ustring.h"
27 
30 
32 
34 
35 namespace Engines {
36 
37 namespace NWN {
38 
40  const Common::UString &model) :
41  ModelWidget(gui, tag, model) {
42 
43  _model->setClickable(true);
44 
46 
47  _model->setState("uncheckeddown");
48  if ((node = _model->getNode("XPlane")))
49  node->setInvisible(true);
50 
51  _model->setState("checkedup");
52  if ((node = _model->getNode("XPlane")))
53  node->move(0.0f, 0.0f, -10.0f);
54  _model->setState("checkeddown");
55  if ((node = _model->getNode("XPlane")))
56  node->move(0.0f, 0.0f, -10.0f);
57  _model->setState("checkedhilite");
58  if ((node = _model->getNode("XPlane")))
59  node->move(0.0f, 0.0f, -10.0f);
60 
61  _state = false;
62  _down = false;
63  updateModel(false);
64 }
65 
67 }
68 
69 void WidgetCheckBox::updateModel(bool highlight) {
70  if (highlight) {
71  if (_state) {
72  if (_down)
73  _model->setState("checkeddown");
74  else
75  _model->setState("checkedhilite");
76  } else {
77  if (_down)
78  _model->setState("uncheckeddown");
79  else
80  _model->setState("hilite");
81  }
82  } else {
83  if (_state) {
84  if (_down)
85  _model->setState("checkeddown");
86  else
87  _model->setState("checkedup");
88  } else {
89  if (_down)
90  _model->setState("uncheckeddown");
91  else
92  _model->setState("uncheckedup");
93  }
94  }
95 }
96 
98  return _state;
99 }
100 
101 void WidgetCheckBox::setState(bool state) {
102  if (!_groupMembers.empty()) {
103  // Group members, we are a radio button
104 
105  if (!state)
106  // We can't just uncheck a radio button without checking another one
107  return;
108 
109  _state = true;
110  updateModel(false);
111  setActive(true);
112 
113  } else {
114  // No group members, we are a check box
115 
116  _state = !!state;
117  updateModel(false);
118  setActive(true);
119  }
120 }
121 
124 
125  if (isDisabled())
126  return;
127 
128  _down = false;
129  updateModel(true);
130 }
131 
134 
135  if (isDisabled())
136  return;
137 
138  _down = false;
139  updateModel(false);
140 }
141 
142 void WidgetCheckBox::mouseDown(uint8 state, float UNUSED(x), float UNUSED(y)) {
143  if (isDisabled())
144  return;
145 
146  if (state != SDL_BUTTON_LMASK)
147  return;
148 
149  _down = true;
150  updateModel(true);
151 
152  playSound("gui_check", Sound::kSoundTypeSFX);
153 }
154 
155 void WidgetCheckBox::mouseUp(uint8 UNUSED(state), float UNUSED(x), float UNUSED(y)) {
156  if (isDisabled())
157  return;
158 
159  if (!_groupMembers.empty()) {
160  // Group members, we are a radio button
161 
162  bool oldState = _state;
163 
164  _down = false;
165  _state = true;
166  updateModel(true);
167 
168  if (oldState != _state)
169  setActive(true);
170 
171  } else {
172  // No group members, we are a check box
173 
174  _state = !_state;
175  _down = false;
176  updateModel(true);
177  setActive(true);
178  }
179 
180 }
181 
184 
185  _state = false;
186  _down = false;
187  updateModel(false);
188 }
189 
190 } // End of namespace NWN
191 
192 } // End of namespace Engines
void leave()
The mouse left the widget.
Definition: checkbox.cpp:132
WidgetCheckBox(::Engines::GUI &gui, const Common::UString &tag, const Common::UString &model)
Definition: checkbox.cpp:39
void setInvisible(bool invisible)
Should the node never be rendered at all?
Definition: modelnode.cpp:293
void enter()
The mouse entered the widget.
Definition: checkbox.cpp:122
A class holding an UTF-8 string.
Definition: ustring.h:48
uint8_t uint8
Definition: types.h:200
void setActive(bool active)
The widget&#39;s active state.
Definition: widget.cpp:268
virtual void signalGroupMemberActive()
A fellow group member signaled that it is now active.
Definition: widget.cpp:264
A NWN checkbox widget.
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
Definition: checkbox.cpp:155
void setState(const Common::UString &name="")
Set the current animation state.
Definition: model.cpp:324
void leave()
The mouse left the widget.
Definition: nwnwidget.cpp:55
A GUI.
Definition: gui.h:43
void updateModel(bool highlight)
Definition: checkbox.cpp:69
void setClickable(bool clickable)
Set the object&#39;s clickable state.
Definition: renderable.cpp:94
#define UNUSED(x)
Definition: system.h:170
A node within a 3D model.
A 3D model of an object.
void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
Definition: checkbox.cpp:142
Graphics::Aurora::Model * _model
Definition: modelwidget.h:64
Sound::ChannelHandle playSound(const Common::UString &sound, Sound::SoundType soundType, bool loop, float volume, bool pitchVariance)
Play this sound resource.
Definition: util.cpp:81
void enter()
The mouse entered the widget.
Definition: nwnwidget.cpp:50
Unicode string handling.
A NWN model widget.
Definition: modelwidget.h:45
Low-level detection of architecture/system properties.
bool isDisabled() const
Is the widget disabled?
Definition: widget.cpp:63
void move(float x, float y, float z)
Move the node, relative to its current position.
Definition: modelnode.cpp:251
Sound effect.
Definition: types.h:45
Generic Aurora engines utility functions.
std::list< Widget * > _groupMembers
The widget&#39;s fellow group members.
Definition: widget.h:117
void setState(bool state)
Definition: checkbox.cpp:101
void signalGroupMemberActive()
A fellow group member signaled that it is now active.
Definition: checkbox.cpp:182
ModelNode * getNode(const Common::UString &node)
Get the specified node, from the current state.
Definition: model.cpp:379