xoreos  0.0.5
nwnwidgetwithcaption.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/ustring.h"
26 
27 #include "src/graphics/font.h"
28 
31 
33 
34 namespace Engines {
35 
36 namespace NWN {
37 
39  NWNWidget(gui, tag), _r(1.0f), _g(1.0f), _b(1.0f), _a(1.0f) {
40 
41 }
42 
44 }
45 
47  if (isVisible())
48  return;
49 
50  if (_caption && !isInvisible())
51  _caption->show();
52 
54 }
55 
57  if (!isVisible())
58  return;
59 
60  if (_caption)
61  _caption->hide();
63 }
64 
66  float r, float g, float b, float a, float halign, float valign) {
67 
68  _caption.reset(new Graphics::Aurora::Text(FontMan.get(font), getWidth(), getHeight(), text, r, g, b, a, halign, valign));
69  _caption->setTag(getTag() + "#Caption");
70 
71  float x, y, z;
72  getPosition(x, y, z);
73  _caption->setPosition(x, y, z - 1.0);
74 }
75 
76 void NWNWidgetWithCaption::setPosition(float x, float y, float z) {
77  NWNWidget::setPosition(x, y, z);
78 
79  getPosition(x, y, z);
80  if (_caption)
81  _caption->setPosition(x, y, z - 1.0);
82 }
83 
84 void NWNWidgetWithCaption::setColor(float r, float g, float b, float a) {
85  _r = r;
86  _g = g;
87  _b = b;
88  _a = a;
89 
90  if (_caption)
91  _caption->setColor(_r, _g, _b, _a);
92 }
93 
95  if (!_caption)
96  return;
97 
98  _caption->setText(text);
99 }
100 
102  if (_caption)
103  return _caption->get();
104  return "";
105 }
106 
108  if (_caption)
109  return _caption->getWidth();
110  return 0.0f;
111 }
112 
114  if (_caption)
115  return _caption->getHeight();
116  return 0.0f;
117 }
118 
120  if (_caption)
121  return _caption->getHorizontalAlign();
123 }
124 
126  if (_caption)
127  return _caption->getVerticalAlign();
129 }
130 
132  if (disabled == isDisabled())
133  return;
134 
135  _a = disabled ? (_a * 0.6f) : (_a / 0.6f);
136 
137  if (_caption)
138  _caption->setColor(_r, _g, _b, _a);
139 
140  NWNWidget::setDisabled(disabled);
141 }
142 
143 } // End of namespace NWN
144 
145 } // End of namespace Engines
float getHeight() const
Get the widget&#39;s height.
A class holding an UTF-8 string.
Definition: ustring.h:48
NWNWidgetWithCaption(::Engines::GUI &gui, const Common::UString &tag)
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
const float kVAlignTop
Definition: types.h:46
A text object.
void setText(const Common::UString &text)
virtual void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: widget.cpp:154
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
bool isVisible() const
Is the widget visible?
Definition: widget.cpp:59
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
The Aurora font manager.
void hide()
Hide the widget.
Definition: nwnwidget.cpp:40
A GUI.
Definition: gui.h:43
bool isInvisible() const
Is the widget invisible (never visible)?
Definition: widget.cpp:67
A text object.
Definition: text.h:42
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
const float kHAlignLeft
Definition: types.h:42
const Common::UString getText() const
virtual void initCaption(const Common::UString &font, const Common::UString &text, float r=1.0f, float g=1.0f, float b=1.0f, float a=1.0f, float halign=Graphics::Aurora::kHAlignLeft, float valign=Graphics::Aurora::kVAlignTop)
Common::ScopedPtr< Graphics::Aurora::Text > _caption
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: nwnwidget.cpp:60
Unicode string handling.
A NWN widget with a text caption.
PointerType get() const
Returns the plain pointer value.
Definition: scopedptr.h:96
virtual void show()
Show the widget.
Definition: widget.cpp:71
bool isDisabled() const
Is the widget disabled?
Definition: widget.cpp:63
void setDisabled(bool disabled)
Disable/Enable the widget.
A font.
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
float getWidth() const
Get the widget&#39;s width.
void setColor(float r, float g, float b, float a)