xoreos  0.0.5
scrollbar.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 
27 #include "src/aurora/gff3file.h"
28 
31 
33 
34 namespace Engines {
35 
37  : KotORJadeWidget(gui, tag),
38  _arrowHeight(0.0f) {
39 }
40 
42 }
43 
46 
47  float x, y, z;
48  getPosition(x, y, z);
49 
50  if (gff.hasField("DIR")) {
51  const Aurora::GFF3Struct &dir = gff.getStruct("DIR");
52  Common::UString texName = dir.getString("IMAGE");
53  if (!texName.empty()) {
54  Graphics::Aurora::TextureHandle arrowTex = TextureMan.get(dir.getString("IMAGE"));
55  _arrowHeight = arrowTex.getTexture().getHeight();
56 
57  _upArrow.reset(new Graphics::Aurora::GUIQuad(arrowTex, 0.0f, 0.0f, _width, _arrowHeight));
58  _upArrow->setPosition(x, y + _height - _arrowHeight, 0.0f);
59 
60  _downArrow.reset(new Graphics::Aurora::GUIQuad(arrowTex, 0.0f, 0.0f, _width, _arrowHeight, 0.0f, 1.0f, 1.0f, 0.0f));
61  _downArrow->setPosition(x, y, 0.0f);
62  }
63  }
64 
65  if (gff.hasField("THUMB")) {
66  const Aurora::GFF3Struct &thumb = gff.getStruct("THUMB");
67 
68  _thumb.reset(new Graphics::Aurora::GUIQuad(thumb.getString("IMAGE"), 0.0f, 0.0f,
71 
72  _thumb->setPosition(x + _borderDimension, y + _arrowHeight + _borderDimension, 0.0f);
73  }
74 
75  if (_highlight) {
76  _highlight->setPosition(x, y + _arrowHeight, 0.0f);
77  _highlight->setHeight(_height - 2 * _arrowHeight);
78  }
79 
80  if (_border) {
81  _border->setPosition(x, y + _arrowHeight, 0.0f);
82  _border->setSize(_width, _height - 2 * _arrowHeight);
83  }
84 
85  if (_quad) {
86  _quad->setPosition(x, y + _borderDimension + _arrowHeight, 0.0f);
87  _quad->setHeight(_height - 2 * (_borderDimension + _arrowHeight));
88  }
89 }
90 
92  if (isVisible() || isInvisible())
93  return;
94 
96 
97  if (_upArrow)
98  _upArrow->show();
99  if (_downArrow)
100  _downArrow->show();
101  if (_thumb)
102  _thumb->show();
103 }
104 
106  if (!isVisible())
107  return;
108 
109  if (_thumb)
110  _thumb->hide();
111  if (_downArrow)
112  _downArrow->hide();
113  if (_upArrow)
114  _upArrow->hide();
115 
117 }
118 
119 void WidgetScrollbar::setPosition(float x, float y, float z) {
120  float oX, oY, oZ;
121  getPosition(oX, oY, oZ);
122 
123  float dx = x - oX;
124  float dy = y - oY;
125  float dz = z - oZ;
126 
128 
129  if (_upArrow) {
130  _upArrow->getPosition(x, y, z);
131  _upArrow->setPosition(x + dx, y + dy, z + dz);
132  }
133 
134  if (_downArrow) {
135  _downArrow->getPosition(x, y, z);
136  _downArrow->setPosition(x + dx, y + dy, z + dz);
137  }
138 
139  if (_thumb) {
140  _thumb->getPosition(x, y, z);
141  _thumb->setPosition(x + dx, y + dy, z + dz);
142  }
143 }
144 
145 void WidgetScrollbar::setWidth(float width) {
146  float deltaWidth = width - _width;
147 
149 
150  float x, y, z;
151  getPosition(x, y, z);
152 
153  if (_upArrow) {
154  width = _upArrow->getWidth();
155  _upArrow->setWidth(width + deltaWidth);
156  }
157 
158  if (_downArrow) {
159  width = _downArrow->getWidth();
160  _downArrow->setWidth(width + deltaWidth);
161  }
162 
163  if (_thumb) {
164  width = _thumb->getWidth();
165  _thumb->setWidth(width + deltaWidth);
166  }
167 }
168 
169 void WidgetScrollbar::setHeight(float height) {
170  float deltaHeight = height - _height;
171 
173 
174  float x, y, z;
175  getPosition(x, y, z);
176 
177  if (_upArrow) {
178  float aX, aY, aZ;
179  _upArrow->getPosition(aX, aY, aZ);
180  _upArrow->setPosition(aX, y + height - _arrowHeight, aZ);
181  }
182 
183  if (_thumb) {
184  height = _thumb->getHeight();
185  _thumb->setHeight(height + deltaHeight);
186  }
187 }
188 
189 } // End of namespace Engines
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
virtual void setHeight(float height)
Set the height of the widget.
virtual void hide()
Hide the widget.
A class holding an UTF-8 string.
Definition: ustring.h:48
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
Common::ScopedPtr< Graphics::Aurora::BorderQuad > _border
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _upArrow
Definition: scrollbar.h:47
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _highlight
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _quad
The Aurora texture manager.
bool hasField(const Common::UString &field) const
Does this specific field exist?
Definition: gff3file.cpp:400
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
uint32 getHeight() const
Definition: texture.cpp:80
bool isVisible() const
Is the widget visible?
Definition: widget.cpp:59
void load(const Aurora::GFF3Struct &gff)
Definition: scrollbar.cpp:44
A scrollbar widget for Star Wars: Knights of the Old Republic and Jade Empire.
A GUI.
Definition: gui.h:43
bool isInvisible() const
Is the widget invisible (never visible)?
Definition: widget.cpp:67
virtual void show()
Show the widget.
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _thumb
Definition: scrollbar.h:49
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: scrollbar.cpp:119
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void show()
Show the widget.
Definition: scrollbar.cpp:91
void setWidth(float width)
Set the width of the widget.
Definition: scrollbar.cpp:145
void hide()
Hide the widget.
Definition: scrollbar.cpp:105
WidgetScrollbar(GUI &gui, const Common::UString &tag)
Definition: scrollbar.cpp:36
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _downArrow
Definition: scrollbar.h:48
void setHeight(float height)
Set the height of the widget.
Definition: scrollbar.cpp:169
A struct within a GFF3.
Definition: gff3file.h:164
const GFF3Struct & getStruct(const Common::UString &field) const
Definition: gff3file.cpp:728
Low-level detection of architecture/system properties.
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
A textured quad for a GUI element.
virtual void load(const Aurora::GFF3Struct &gff)
A handle to a texture.
Definition: texturehandle.h:51
virtual void setWidth(float width)
Set the width of the widget.
virtual void setPosition(float x, float y, float z)
Set the widget&#39;s position.