xoreos  0.0.5
button.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 
34 
36 
38 
39 namespace Engines {
40 
42  : KotORJadeWidget(gui, tag),
43  _permanentHighlight(false),
44  _disableHighlight(false),
45  _disableHoverSound(false),
46  _hovered(false) {
47 }
48 
50 }
51 
54 
56  if (highlightable)
57  setDefaultHighlighting(highlightable);
58 
59  highlightable = getQuadHighlightableComponent();
60  if (highlightable)
61  setDefaultHighlighting(highlightable);
62 }
63 
64 void WidgetButton::setPermanentHighlight(bool permanentHighlight) {
65  _permanentHighlight = permanentHighlight;
67 }
68 
71  if (highlightable)
72  highlightable->setHighlightLowerBound(1.0f, 1.0f, 0.0f, 1.0f);
73 }
74 
75 void WidgetButton::setDisableHighlight(bool disableHighlight) {
76  _disableHighlight = disableHighlight;
77 
78  if (_disableHighlight) {
79  setHighlight(false);
80  } else {
81  if (_hovered)
82  setHighlight(true);
83  }
84 }
85 
86 void WidgetButton::setDisableHoverSound(bool disableHoverSound) {
87  _disableHoverSound = disableHoverSound;
88 }
89 
91  return _hovered;
92 }
93 
95  if (!_disableHoverSound)
96  _sound = playSound("gui_actscroll", Sound::kSoundTypeSFX);
97 
99  setHighlight(true);
100 
101  // The button is hovered at the moment
102  _hovered = true;
103 }
104 
106  if (!_disableHoverSound)
107  SoundMan.stopChannel(_sound);
108 
110  setHighlight(false);
111 
112  // The button is not hovered anymore
113  _hovered = false;
114 }
115 
116 void WidgetButton::mouseUp(uint8 UNUSED(state), float UNUSED(x), float UNUSED(y)) {
117  if (isDisabled())
118  return;
119 
120  playSound("gui_actuse", Sound::kSoundTypeSFX);
121  setActive(true);
122 }
123 
125  highlightable->setHighlightable(true);
126  highlightable->setHighlightDelta(0.0f, 0.0f, 0.0f, 0.05f);
127  highlightable->setHighlightLowerBound(1.0f, 1.0f, 0.0f, 0.2f);
128  highlightable->setHighlightUpperBound(1.0f, 1.0f, 0.0f, 1.0f);
129 }
130 
131 } // End of namespace Engines
void setDisableHighlight(bool)
Definition: button.cpp:75
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
void leave()
The mouse left the widget.
Definition: button.cpp:105
Graphics::Aurora::Highlightable * getTextHighlightableComponent() const
A class holding an UTF-8 string.
Definition: ustring.h:48
bool _permanentHighlight
Definition: button.h:54
bool isHovered() const
Definition: button.cpp:90
uint8_t uint8
Definition: types.h:200
A button widget for Star Wars: Knights of the Old Republic and Jade Empire.
void setHighlight(const Common::UString &hilight)
void setActive(bool active)
The widget&#39;s active state.
Definition: widget.cpp:268
A text object.
Sound::ChannelHandle _sound
Definition: button.h:58
bool _disableHighlight
Definition: button.h:55
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
Definition: button.cpp:116
void setHighlightable(bool highlightable)
A GUI.
Definition: gui.h:43
#define UNUSED(x)
Definition: system.h:170
void setDefaultHighlighting(Graphics::Aurora::Highlightable *highlightable)
Definition: button.cpp:124
The global sound manager, handling all sound output.
bool _disableHoverSound
Definition: button.h:56
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
void enter()
The mouse entered the widget.
Definition: button.cpp:94
void setHighlightDelta(float r, float g, float b, float a)
Set how much the quad changes per render.
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 setDisableHoverSound(bool)
Definition: button.cpp:86
A struct within a GFF3.
Definition: gff3file.h:164
Low-level detection of architecture/system properties.
void setPermanentHighlight(bool)
Definition: button.cpp:64
bool isDisabled() const
Is the widget disabled?
Definition: widget.cpp:63
virtual void load(const Aurora::GFF3Struct &gff)
Definition: button.cpp:52
Sound effect.
Definition: types.h:45
Generic Aurora engines utility functions.
WidgetButton(GUI &gui, const Common::UString &tag)
Definition: button.cpp:41
void setStaticHighlight()
Definition: button.cpp:69
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)
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...
Graphics::Aurora::Highlightable * getQuadHighlightableComponent() const