xoreos  0.0.5
progressbar.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 
30 
31 namespace Engines {
32 
34  : KotORJadeWidget(gui, tag),
35  _maxValue(0),
36  _curValue(0),
37  _horizontal(true) {
38 }
39 
41 }
42 
45 
46  _maxValue = gff.getSint("MAXVALUE");
47  _curValue = gff.getSint("CURVALUE");
48  _horizontal = gff.getBool("STARTFROMLEFT", true);
49 
50  if (gff.hasField("PROGRESS")) {
51  const Aurora::GFF3Struct &progress = gff.getStruct("PROGRESS");
52  const Common::UString fill = progress.getString("FILL");
53 
54  _progress.reset(new Graphics::Aurora::GUIQuad(fill, 0.0f, 0.0f, getWidth(), getHeight()));
55 
56  float x, y, z;
57  getPosition(x, y, z);
58  _progress->setPosition(x, y, -FLT_MAX);
59 
60  update();
61  }
62 }
63 
64 void WidgetProgressbar::setPosition(float x, float y, float z) {
65  float oX, oY, oZ;
66  getPosition(oX, oY, oZ);
67 
69 
70  float dx = x - oX;
71  float dy = y - oY;
72  float dz = z - oZ;
73 
74  if (_progress) {
75  _progress->getPosition(x, y, z);
76  _progress->setPosition(x + dx, y + dy, z + dz);
77  }
78 }
79 
81  if (isVisible() || isInvisible())
82  return;
83 
85 
86  if (_progress)
87  _progress->show();
88 }
89 
91  if (!isVisible())
92  return;
93 
95 
96  if (_progress)
97  _progress->hide();
98 }
99 
101  _curValue = curValue;
102  update();
103 }
104 
105 void WidgetProgressbar::setMaxValue(int maxValue) {
106  _maxValue = maxValue;
107  update();
108 }
109 
111  return _curValue;
112 }
113 
115  return _maxValue;
116 }
117 
119  if (_horizontal) {
120  if ((_maxValue <= 0) || (_curValue >= _maxValue))
121  _progress->setWidth(_width);
122  else if (_curValue <= 0)
123  _progress->setWidth(0.0f);
124  else
125  _progress->setWidth(_width * (static_cast<float>(_curValue) / static_cast<float>(_maxValue)));
126  } else {
127  if ((_maxValue <= 0) || (_curValue >= _maxValue))
128  _progress->setHeight(_height);
129  else if (_curValue <= 0)
130  _progress->setHeight(0.0f);
131  else
132  _progress->setHeight(_height * (static_cast<float>(_curValue) / static_cast<float>(_maxValue)));
133  }
134 }
135 
136 } // End of namespace Engines
int64 getSint(const Common::UString &field, int64 def=0) const
Definition: gff3file.cpp:473
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _progress
Definition: progressbar.h:59
void setCurrentValue(int curValue)
Set the current progress bar value.
bool getBool(const Common::UString &field, bool def=false) const
Definition: gff3file.cpp:510
virtual void hide()
Hide the widget.
A class holding an UTF-8 string.
Definition: ustring.h:48
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
int getCurrentValue()
Get the current progress bar value.
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
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.
Definition: progressbar.cpp:64
void hide()
Hide the widget.
Definition: progressbar.cpp:90
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.
void setMaxValue(int maxValue)
Set the max progress bar value.
int getMaxValue()
Get the max progress bar value.
WidgetProgressbar(GUI &gui, const Common::UString &tag)
Definition: progressbar.cpp:33
A progressbar widget for Star Wars: Knights of the Old Republic and Jade Empire.
void show()
Show the widget.
Definition: progressbar.cpp:80
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
void load(const Aurora::GFF3Struct &gff)
Definition: progressbar.cpp:43
virtual void load(const Aurora::GFF3Struct &gff)
float getWidth() const
Get the widget&#39;s width.
#define FLT_MAX
Definition: maths.h:47
virtual void setPosition(float x, float y, float z)
Set the widget&#39;s position.
float getHeight() const
Get the widget&#39;s height.