xoreos  0.0.5
button.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 
29 
31 
33 
34 namespace Engines {
35 
36 namespace NWN {
37 
39  const Common::UString &model, const Common::UString &sound) :
40  ModelWidget(gui, tag, model) {
41 
42  _model->setClickable(true);
43  _model->setState("up");
44 
45  _sound = sound;
47 }
48 
50 }
51 
54 
55  if (isDisabled())
56  return;
57 
58  if (_mode == kModeNormal)
59  _model->setState("hilite");
60 }
61 
64 
65  if (isDisabled())
66  return;
67 
68  if (_mode == kModeNormal)
69  _model->setState("up");
70 }
71 
72 void WidgetButton::setPosition(float x, float y, float z) {
73  ModelWidget::setPosition(x, y, z);
74 
75  // Don't write on the border
77  _caption->getPosition(x, y, z);
78  _caption->setPosition(x + 7, y, z);
79  }
80 }
81 
83  _mode = mode;
84 
85  if (mode == kModeUnchanged)
86  _model->setState("disabled");
87 }
88 
90  return _mode;
91 }
92 
93 void WidgetButton::setPressed(bool pushed) {
94  if (pushed)
95  _model->setState("down");
96  else
97  _model->setState("up");
98 }
99 
101  if (_model->getState() == "down")
102  return true;
103 
104  return false;
105 }
106 
107 void WidgetButton::setDisabled(bool disabled) {
108  ModelWidget::setDisabled(disabled);
109 
110  if (isDisabled())
111  _model->setState("disabled");
112  else
113  _model->setState("up");
114 }
115 
116 void WidgetButton::mouseDown(uint8 state, float UNUSED(x), float UNUSED(y)) {
117  if (isDisabled())
118  return;
119 
120  if (state != SDL_BUTTON_LMASK)
121  return;
122 
123  if (_mode == kModeNormal) {
124  _model->setState("down");
126  } else if (_mode == kModeUnchanged) {
128  }
129 }
130 
131 void WidgetButton::mouseUp(uint8 UNUSED(state), float UNUSED(x), float UNUSED(y)) {
132  if (isDisabled())
133  return;
134 
135  setActive(true);
136 
137  if (_mode == kModeNormal) {
138  _model->setState("hilite");
139  } else if (_mode == kModeToggle) {
140  _model->setState("down");
142  }
143 }
144 
145 void WidgetButton::mouseWheel(uint8 state, int x, int y) {
146  if (_owner) {
147  _owner->mouseWheel(state, x, y);
148  }
149 }
150 
151 } // End of namespace NWN
152 
153 } // End of namespace Engines
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: button.cpp:72
const Common::UString & getState() const
Return the name of the current state.
Definition: model.cpp:361
A NWN button widget.
Widget * _owner
The widget&#39;s owner, if any.
Definition: widget.h:113
A class holding an UTF-8 string.
Definition: ustring.h:48
void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
Definition: button.cpp:116
uint8_t uint8
Definition: types.h:200
void setActive(bool active)
The widget&#39;s active state.
Definition: widget.cpp:268
A text object.
void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: button.cpp:107
void leave()
The mouse left the widget.
Definition: button.cpp:62
WidgetButton(::Engines::GUI &gui, const Common::UString &tag, const Common::UString &model, const Common::UString &sound="gui_button")
Definition: button.cpp:38
bool isPressed() const
Definition: button.cpp:100
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
Definition: button.cpp:131
Common::UString _sound
Definition: button.h:67
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 setClickable(bool clickable)
Set the object&#39;s clickable state.
Definition: renderable.cpp:94
#define UNUSED(x)
Definition: system.h:170
void setMode(Mode mode)
Definition: button.cpp:82
Mode getMode() const
Definition: button.cpp:89
const float kHAlignLeft
Definition: types.h:42
A 3D model of an object.
Common::ScopedPtr< Graphics::Aurora::Text > _caption
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
virtual void mouseWheel(uint8 state, int x, int y)
A mouse wheel was used on the widget.
Definition: widget.cpp:197
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: modelwidget.cpp:71
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
Sound effect.
Definition: types.h:45
Generic Aurora engines utility functions.
void setDisabled(bool disabled)
Disable/Enable the widget.
void setPressed(bool pushed)
Definition: button.cpp:93
void enter()
The mouse entered the widget.
Definition: button.cpp:52
void mouseWheel(uint8 state, int x, int y)
A mouse wheel was used on the widget.
Definition: button.cpp:145