xoreos  0.0.5
quickbar.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/error.h"
27 
28 #include "src/graphics/graphics.h"
29 
32 
34 
36 
38 
39 namespace Engines {
40 
41 namespace NWN {
42 
44  _buttonNumber(n) {
45 
46  Graphics::Aurora::ModelNode *invisible = 0;
47 
48  if (_buttonNumber == 11) {
49 
50  _model.reset(loadModelGUI("qb_but67end"));
51  if (!_model)
52  throw Common::Exception("Failed to load quickbar model");
53  invisible = _model->getNode("Plane72");
54 
55  } else {
56 
57  _model.reset(loadModelGUI("qb_but67"));
58  if (!_model)
59  throw Common::Exception("Failed to load quickbar model");
60  invisible = _model->getNode("Plane52");
61 
62  }
63 
64  if (invisible)
65  invisible->setInvisible(true);
66 
68  _model->setTag(NWNWidget::getTag());
69 
70 }
71 
73 }
74 
76  _model->show();
77 }
78 
80  _model->hide();
81 }
82 
83 void QuickbarButton::setPosition(float x, float y, float z) {
84  NWNWidget::setPosition(x, y, z);
85 
86  getPosition(x, y, z);
87  _model->setPosition(x, y, z);
88 }
89 
90 float QuickbarButton::getWidth() const {
91  return _model->getWidth();
92 }
93 
95  return _model->getHeight();
96 }
97 
99 }
100 
101 
103  getSlotSize();
104 
105  WidgetPanel *bottomEdge = new WidgetPanel(*this, "QBBottomEdge", "pnl_quick_bar");
106  addWidget(bottomEdge);
107 
108  _edgeHeight = bottomEdge->getHeight();
109 
110  for (size_t i = 0; i < 12; i++) {
111  QuickbarButton *button = new QuickbarButton(*this, i);
112 
113  button->setPosition(i * _slotWidth, bottomEdge->getHeight(), 0.0f);
114  addWidget(button);
115  }
116 
117  WidgetPanel *topEdge = new WidgetPanel(*this, "QBTopEdge", "pnl_quick_bar");
118  topEdge->setPosition(0.0f, _slotHeight, 0.0f);
119  addWidget(topEdge);
120 
121  notifyResized(0, 0, WindowMan.getWindowWidth(), WindowMan.getWindowHeight());
122 }
123 
125 }
126 
127 float Quickbar::getWidth() const {
128  return 12 * _slotWidth;
129 }
130 
131 float Quickbar::getHeight() const {
132  return _slotHeight + 2 * _edgeHeight;
133 }
134 
136 }
137 
140 
141  _slotWidth = floorf(_model->getWidth());
142  _slotHeight = floorf(_model->getHeight());
143 }
144 
145 void Quickbar::notifyResized(int UNUSED(oldWidth), int UNUSED(oldHeight),
146  int UNUSED(newWidth), int newHeight) {
147 
148  setPosition(- ((12 * _slotWidth) / 2.0f), - (newHeight / 2.0f), -10.0f);
149 }
150 
151 } // End of namespace NWN
152 
153 } // End of namespace Engines
float getHeight() const
Get the widget&#39;s height.
Definition: quickbar.cpp:94
A NWN panel widget.
Definition: panel.h:41
The global graphics manager.
virtual void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
Definition: widget.cpp:49
void setInvisible(bool invisible)
Should the node never be rendered at all?
Definition: modelnode.cpp:293
A class holding an UTF-8 string.
Definition: ustring.h:48
void setPosition(float x, float y, float z)
Set the GUI&#39;s position.
Definition: gui.cpp:394
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
float getHeight() const
Get the widget&#39;s height.
Definition: modelwidget.cpp:82
float getWidth() const
Definition: quickbar.cpp:127
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
Base class for all widgets in NWN.
Definition: nwnwidget.h:45
A button within the NWN quickbar.
Definition: quickbar.h:44
void show()
Show the widget.
Definition: quickbar.cpp:75
The ingame quickbar.
void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
Definition: quickbar.cpp:98
void hide()
Hide the widget.
Definition: quickbar.cpp:79
A GUI.
Definition: gui.h:43
Basic exceptions to throw.
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define UNUSED(x)
Definition: system.h:170
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
A node within a 3D model.
A 3D model of an object.
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: quickbar.cpp:135
Common::ScopedPtr< Graphics::Aurora::Model > _model
Definition: quickbar.h:60
StackException Exception
Definition: error.h:59
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: nwnwidget.cpp:60
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
float getHeight() const
Definition: quickbar.cpp:131
float getWidth() const
Get the widget&#39;s width.
Definition: quickbar.cpp:90
A widget in a GUI.
Definition: widget.h:40
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: modelwidget.cpp:71
QuickbarButton(::Engines::GUI &gui, size_t n)
Definition: quickbar.cpp:43
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: quickbar.cpp:83
Low-level detection of architecture/system properties.
Graphics::Aurora::Model * loadModelGUI(const Common::UString &resref)
Definition: model.cpp:65
void addWidget(Widget *widget)
Add a widget.
Definition: gui.cpp:250
A NWN panel widget.
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
Definition: quickbar.cpp:145
unsigned int uint
Definition: types.h:211
Generic Aurora engines model functions.