xoreos  0.0.5
checkbox.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 
29 #include "src/sound/sound.h"
30 
38 
40 
42 
43 namespace Engines {
44 
46  : KotORJadeWidget(gui, tag),
47  _state(false),
48  _unselectedR(1.0f),
49  _unselectedG(1.0f),
50  _unselectedB(1.0f),
51  _unselectedA(1.0f) {
52 }
53 
55 }
56 
59 
60  Border border = createBorder(gff);
62 
63  if (!border.fill.empty())
64  texture = TextureMan.get(border.fill);
65 
66  _selected = gff.getStruct("SELECTED").getString("FILL");
67  _unselected = gff.getStruct("BORDER").getString("FILL");
68  _selectedHighlighted = gff.getStruct("HILIGHTSELECTED").getString("FILL");
69  _unselectedHighlighted = gff.getStruct("HILIGHT").getString("FILL");
70 
71  float squareLength = _quad->getHeight();
72  float x, y, z;
73 
74  if (!border.fill.empty()) {
75  float _quadPosCorrect = (squareLength - (texture.getTexture().getHeight() * 0.625f)) / 2;
76  if (_quad) {
77  _quad->getPosition(x, y, z);
78  _quad->setPosition(x + _quadPosCorrect, y + _quadPosCorrect, z);
79  _quad->setHeight(texture.getTexture().getHeight() * 0.625f);
80  _quad->setWidth(texture.getTexture().getWidth() * 0.625f);
81  }
82  }
83 
84  if (_text) {
85  _text->getPosition(x, y, z);
86  _text->setPosition(x + squareLength, y, z);
87  _text->setSize(_text->getWidth() - squareLength, _text->getHeight());
88  }
89 
91  if (highlightable)
92  setTextHighlighting(highlightable);
93 
94  highlightable = getQuadHighlightableComponent();
95  if (highlightable)
96  setQuadHighlighting(highlightable);
97 }
98 
99 void WidgetCheckBox::setState(bool state) {
100  _state = state;
101 
102  // Preserve the current color after replacing the texture
103 
104  float textR, textG, textB, textA;
105  _text->getColor(textR, textG, textB, textA);
106 
107  float quadR, quadG, quadB, quadA;
108  if (_quad)
109  _quad->getColor(quadR, quadG, quadB, quadA);
110 
111  //-
112 
115 
116  _text->setColor(textR, textG, textB, textA);
117 
118  if (_quad)
119  _quad->setColor(quadR, quadG, quadB, quadA);
120 
121  setActive(true);
122 }
123 
125  return _state;
126 }
127 
129  float r, g, b, a;
130  _sound = playSound("gui_actscroll", Sound::kSoundTypeSFX);
131 
133  if (highlightable && highlightable->isHighlightable()) {
135  _text->getHighlightedLowerBound(r, g, b, a);
136  _text->setColor(r, g, b, a);
137  _text->setHighlighted(true);
138  }
139 
140  highlightable = getQuadHighlightableComponent();
141  if (highlightable && highlightable->isHighlightable()) {
143  highlightable->getHighlightedLowerBound(r, g, b, a);
144  _quad->setColor(r, g, b, a);
145  highlightable->setHighlighted(true);
146  }
147 
148 }
149 
151  SoundMan.stopChannel(_sound);
152 
154  if (highlightable && highlightable->isHighlightable()) {
155  _text->setHighlighted(false);
157  }
158 
159  highlightable = getQuadHighlightableComponent();
160  if (highlightable && highlightable->isHighlightable()) {
161  highlightable->setHighlighted(false);
163  }
164 }
165 
166 void WidgetCheckBox::mouseUp(uint8 UNUSED(state), float UNUSED(x), float UNUSED(y)) {
167  if (isDisabled())
168  return;
169 
170  setState(!_state);
171  playSound("gui_check", Sound::kSoundTypeSFX);
172  setActive(true);
173 }
174 
176  _selected = selected;
177 }
178 
180  _unselected = unselected;
181 }
182 
183 void WidgetCheckBox::setSelectedHighlighted(const Common::UString &selectedHighlighted) {
184  _selectedHighlighted = selectedHighlighted;
185 }
186 
187 void WidgetCheckBox::setUnselectedHighlighted(const Common::UString &unselectedHighlighted) {
188  _unselectedHighlighted = unselectedHighlighted;
189 }
190 
192  highlightable->setHighlightable(true);
193  highlightable->setHighlightDelta(0.0f, 0.0f, 0.0f, 0.05f);
194  highlightable->setHighlightLowerBound(1.0f, 1.0f, 0.0f, 0.2f);
195  highlightable->setHighlightUpperBound(1.0f, 1.0f, 0.0f, 1.0f);
196 }
197 
199  highlightable->setHighlightable(true);
200  highlightable->setHighlightLowerBound(1.0f, 1.0f, 0.0f, 1.0f);
201 }
202 
203 } // End of namespace Engines
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
void setQuadHighlighting(Graphics::Aurora::Highlightable *highlightable)
Definition: checkbox.cpp:198
Graphics::Aurora::Highlightable * getTextHighlightableComponent() const
void setSelected(const Common::UString &selected)
Definition: checkbox.cpp:175
void setFill(const Common::UString &fill)
Common::UString _unselectedHighlighted
Definition: checkbox.h:56
A class holding an UTF-8 string.
Definition: ustring.h:48
void setHighlighted(bool hightlighted)
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
uint8_t uint8
Definition: types.h:200
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _quad
The Aurora texture manager.
void setHighlight(const Common::UString &hilight)
void setActive(bool active)
The widget&#39;s active state.
Definition: widget.cpp:268
A text object.
A checkbox widget for Star Wars: Knights of the Old Repulic and Jade Empire.
Common::UString _selectedHighlighted
Definition: checkbox.h:56
uint32 getHeight() const
Definition: texture.cpp:80
void setUnselectedHighlighted(const Common::UString &unselectedHighlighted)
Definition: checkbox.cpp:187
The Aurora font manager.
void setHighlightable(bool highlightable)
A GUI.
Definition: gui.h:43
#define UNUSED(x)
Definition: system.h:170
Common::UString _selected
Definition: checkbox.h:55
WidgetCheckBox(GUI &gui, const Common::UString &tag)
Definition: checkbox.cpp:45
void setState(bool state)
Definition: checkbox.cpp:99
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
void setUnselected(const Common::UString &unselected)
Definition: checkbox.cpp:179
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
Definition: checkbox.cpp:166
void setHighlightDelta(float r, float g, float b, float a)
Set how much the quad changes per render.
uint32 getWidth() const
Definition: texture.cpp:76
void leave()
The mouse left the widget.
Definition: checkbox.cpp:150
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 load(const Aurora::GFF3Struct &gff)
Definition: checkbox.cpp:57
Common::UString _unselected
Definition: checkbox.h:55
A texture as used in the Aurora engines.
A struct within a GFF3.
Definition: gff3file.h:164
void enter()
The mouse entered the widget.
Definition: checkbox.cpp:128
const GFF3Struct & getStruct(const Common::UString &field) const
Definition: gff3file.cpp:728
Low-level detection of architecture/system properties.
bool isDisabled() const
Is the widget disabled?
Definition: widget.cpp:63
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
Sound effect.
Definition: types.h:45
Generic Aurora engines utility functions.
void setSelectedHighlighted(const Common::UString &selectedHighlighted)
Definition: checkbox.cpp:183
Common::ScopedPtr< Graphics::Aurora::HighlightableText > _text
void setHighlightUpperBound(float r, float g, float b, float a)
When any of the quad properties are greater than this bound, the signs of the delta floats will flip...
A textured quad for a GUI element.
virtual void load(const Aurora::GFF3Struct &gff)
A handle to a texture.
Definition: texturehandle.h:51
void setTextHighlighting(Graphics::Aurora::Highlightable *highlightable)
Definition: checkbox.cpp:191
bool getState() const
Definition: checkbox.cpp:124
Border createBorder(const Aurora::GFF3Struct &gff)
Sound::ChannelHandle _sound
Definition: checkbox.h:59
void setHighlightLowerBound(float r, float g, float b, float a)
When any of the quad properties are less than this bound, the signs of the delta floats will flip...
void getHighlightedLowerBound(float &r, float &g, float &b, float &a) const
Graphics::Aurora::Highlightable * getQuadHighlightableComponent() const