xoreos  0.0.5
listitembutton.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 <cassert>
26 
31 
34 
38 
39 namespace Engines {
40 
41 namespace NWN {
42 
44  const Common::UString &button, float spacing,
45  const Common::UString &soundClick) :
46  WidgetListItem(gui), _spacing(spacing),
47  _sound(soundClick) {
48 
49  _button.reset(loadModelGUI(button));
50  assert(_button);
51 
52  _button->setClickable(true);
54 }
55 
57 }
58 
61 
62  _button->show();
63 }
64 
67 
68  _button->hide();
69 }
70 
71 void WidgetListItemBaseButton::setPosition(float x, float y, float z) {
72  NWNWidget::setPosition(x, y, z);
73 
74  getPosition(x, y, z);
75  _button->setPosition(x, y, z);
76 }
77 
78 void WidgetListItemBaseButton::mouseDown(uint8 state, float x, float y) {
79  Engines::Widget::mouseDown(state, x, y);
80 
81  if (SoundMan.isValidChannel(_channelHandle))
82  SoundMan.stopChannel(_channelHandle);
83 
85 }
86 
88  return _button->getWidth();
89 }
90 
92  return _button->getHeight() + _spacing;
93 }
94 
97 
98  _button->setTag(tag);
99 }
100 
102  _sound = sound;
103 }
104 
107  return false;
108 
109  _button->setState("down");
110 
111  return true;
112 }
113 
116  return false;
117 
118  _button->setState("");
119  if (SoundMan.isPlaying(_channelHandle))
120  SoundMan.stopChannel(_channelHandle);
121 
122  return true;
123 }
124 
126  const Common::UString &text, const Common::UString &icon,
127  uint32 otherButtons, const Common::UString &soundClick) :
128  WidgetListItemBaseButton(gui, button, 1.0f, soundClick),
129  _isRight(true), _isMovable(false), _moveButtonRight(0), _moveButtonLeft(0) {
130 
131  _text.reset(new Graphics::Aurora::Text(FontMan.get("fnt_galahad14"), text));
132 
133  if (!icon.empty())
134  _icon.reset(new Portrait(icon, Portrait::kSizeIcon));
135 
136  if (otherButtons & kHelpButton)
137  _helpButton.reset(loadModelGUI("ctl_cg_btn_help"));
138 
139  if (otherButtons & kMoveButton) {
140  _isMovable = true;
141 
142  _moveButtonRight = new WidgetButton(gui, "Item#" + text + "#MoveButtonRight", "ctl_cg_btn_right");
144 
145  _moveButtonLeft = new WidgetButton(gui, "Item#" + text + "#MoveButtonLeft", "ctl_cg_btn_left");
147  }
148 }
149 
151 }
152 
155 
156  _text->show();
157 
158  if (_icon)
159  _icon->show();
160 
161  if (_moveButtonRight) {
162  if (_isRight) {
164  if (_moveButtonLeft->isVisible())
166  } else {
170  }
171  }
172 }
173 
176 
177  _text->hide();
178 
179  if (_icon)
180  _icon->hide();
181 
182  if (_moveButtonRight) {
183  if (_isRight) {
185  } else {
187  }
188  }
189 }
190 
191 void WidgetListItemButton::setPosition(float x, float y, float z) {
193 
194  float pX, pY, pZ;
195  if (_button->getNode("text0")) {
196  _button->getNode("text0")->getPosition(pX, pY, pZ);
197  pY -= (4 - _text->getLineCount()) * _text->getHeight() * 0.5f;
198  } else if (_button->getNode("text")) {
199  _button->getNode("text")->getPosition(pX, pY, pZ);
200  pY -= _text->getHeight() / 2;
201  } else {
202  pX = 0.0f;
203  pY = -_text->getHeight() / 2;
204  pZ = 5.0f;
205  }
206 
207  _text->setPosition(x + pX, y + pY, z - pZ);
208 
209  if (_moveButtonRight) {
210  _button->getNode("addremovebutton")->getPosition(pX, pY, pZ);
211  _moveButtonRight->setPosition(x + pX, y + pY, z - pZ - 100.f);
212  _moveButtonLeft->setPosition(x + pX, y + pY, z - pZ - 100.f);
213  }
214 
215  if (_helpButton) {
216  _button->getNode("helpbutton")->getPosition(pX, pY, pZ);
217  _helpButton->setPosition(x + pX, y + pY, z - pZ - 100.f);
218  }
219 
220  if (!_icon)
221  return;
222 
223  _button->getNode("icon")->getPosition(pX, pY, pZ);
224  _icon->setPosition(x + pX - _icon->getWidth() / 2, y + pY - _icon->getHeight() / 2, z - 100.f);
225 }
226 
227 void WidgetListItemButton::mouseDown(uint8 state, float x, float y) {
229 
230  if (_helpButton) {
231  if (_helpButton->isIn(x, y)) {
232  _helpButton->setState("down");
233  }
234  }
235 }
236 
237 void WidgetListItemButton::mouseUp(uint8 state, float x, float y) {
239 
240  if (_helpButton) {
241  _helpButton->setState("up");
242  if (_helpButton->isIn(x, y)) {
243  callbackHelp();
244  }
245  }
246 }
247 
249  if (_helpButton)
250  _helpButton->show();
251 }
252 
254  if (_helpButton)
255  _helpButton->hide();
256 }
257 
259  return _isMovable;
260 }
261 
263  _isMovable = false;
264  _text->setColor(0.5f, 0.5f, 0.5f, 1.f);
265 }
266 
267 void WidgetListItemButton::setTextColor(float r, float g, float b, float a) {
268  _text->setColor(r, g, b, a);
269 }
270 
272  if (!_moveButtonRight)
273  return;
274 
275  _isRight = !_isRight;
276 
277  if (isVisible()) {
278  hide();
279  show();
280  }
281 }
282 
284 }
285 
286 } // End of namespace NWN
287 
288 } // End of namespace Engines
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: button.cpp:72
A NWN button widget.
virtual void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
Definition: widget.cpp:49
A class holding an UTF-8 string.
Definition: ustring.h:48
Common::ScopedPtr< Portrait > _icon
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
uint8_t uint8
Definition: types.h:200
WidgetListItemButton(::Engines::GUI &gui, const Common::UString &button, const Common::UString &text, const Common::UString &icon, uint32 otherButtons=0x04, const Common::UString &soundClick="gui_button")
A text object.
void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
bool isVisible() const
Is the widget visible?
Definition: widget.cpp:59
void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
float getWidth() const
Get the widget&#39;s width.
void hide()
Hide the widget.
Definition: modelwidget.cpp:63
The Aurora font manager.
An item widget within a NWN listbox widget.
Definition: listbox.h:51
void hide()
Hide the widget.
Definition: nwnwidget.cpp:40
A NWN button widget.
Definition: button.h:39
A GUI.
Definition: gui.h:43
virtual void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
Definition: widget.cpp:191
float getHeight() const
Get the widget&#39;s height.
void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
A text object.
Definition: text.h:42
void leave()
The mouse left the widget.
void setSound(const Common::UString &sound)
void enter()
The mouse entered the widget.
void setTextColor(float r, float g, float b, float a)
void show()
Show the widget.
Definition: modelwidget.cpp:53
A node within a 3D model.
A 3D model of an object.
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: nwnwidget.cpp:60
virtual bool deactivate()
Definition: listbox.cpp:124
Sound::ChannelHandle playSound(const Common::UString &sound, Sound::SoundType soundType, bool loop, float volume, bool pitchVariance)
Play this sound resource.
Definition: util.cpp:81
Button items used in WidgetListBox.
Common::ScopedPtr< Graphics::Aurora::Text > _text
A NWN portrait model.
Definition: portrait.h:47
virtual void show()
Show the widget.
Definition: widget.cpp:71
A handle to a sound channel.
Definition: types.h:35
uint32_t uint32
Definition: types.h:204
Sound effect.
Definition: types.h:45
Graphics::Aurora::Model * loadModelGUI(const Common::UString &resref)
Definition: model.cpp:65
A portrait model and widget.
Generic Aurora engines utility functions.
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
Definition: listbox.cpp:62
Common::ScopedPtr< Graphics::Aurora::Model > _helpButton
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
virtual void addSub(Widget &widget)
Add a sub-widget to the widget.
Definition: widget.cpp:206
Common::ScopedPtr< Graphics::Aurora::Model > _button
WidgetListItemBaseButton(::Engines::GUI &gui, const Common::UString &button, float spacing=0.0f, const Common::UString &soundClick="gui_button")
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
Generic Aurora engines model functions.