Orxonox  0.0.5 Codename: Arcturus
HUDBar.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Yuning Chai
24  * Co-authors:
25  * Felix Schulthess
26  * Fabian 'x3n' Landau
27  * Reto Grieder
28  * Benjamin Knecht
29  *
30  */
31 
32 #ifndef _HUDBar_H__
33 #define _HUDBar_H__
34 
36 
37 #include <map>
38 #include <vector>
39 
40 #include "util/Math.h"
41 #include "util/OgreForwardRefs.h"
42 #include "core/BaseObject.h"
44 
45 namespace orxonox
46 {
48  {
49  public:
50  BarColour(Context* context);
51  virtual ~BarColour() { }
52 
53  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
54 
55  void setColour(const ColourValue& colour) { this->colour_ = colour; }
56  const ColourValue& getColour() const { return this->colour_; }
57 
58  void setPosition(float pos) { this->position_ = pos; }
59  float getPosition() const { return this->position_; }
60 
61  private:
62  ColourValue colour_;
63  float position_;
64  };
65 
66 
68  {
69  public:
70  HUDBar(Context* context);
71  virtual ~HUDBar();
72 
73  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
74 
75  void clearColours();
76 
77  inline void setRightToLeft(bool r2l)
78  {
79  if (r2l != this->right2Left_)
80  {
81  this->right2Left_ = r2l;
82  this->valueChanged();
83  }
84  }
85  inline bool getRightToLeft() const
86  { return this->right2Left_; }
87 
88  inline void setValue(float value)
89  {
90  float temp = clamp(value, 0.0f, 1.0f);
91  if (temp != this->value_)
92  {
93  this->value_ = temp;
94  this->valueChanged();
95  }
96  }
97  inline float getValue() const
98  { return this->value_; }
99 
100  inline void setAutoColour(bool val)
101  {
102  if (val != this->autoColour_)
103  {
104  this->autoColour_ = val;
105  this->valueChanged();
106 
107  if (!val)
108  this->currentColour_ = ColourValue::White;
109  }
110  }
111  inline bool getAutoColour() const
112  { return this->autoColour_; }
113 
114  void setBarTexture(const std::string& texture);
115  const std::string& getBarTexture() const;
116 
117  void setIconMaterial(const std::string& iconMaterial);
118  const std::string& getIconMaterial() const;
119 
120  inline const ColourValue& getCurrentBarColour() const
121  { return this->currentColour_; }
122 
123  void setIconPosition(Vector2 position);
124  void setIconDimensions(Vector2 dimensions);
125 
126  protected:
127  virtual void valueChanged();
128  private:
129  void addColour(BarColour* colour);
130  BarColour* getColour(unsigned int index);
131 
133  bool autoColour_;
134  float value_;
135  ColourValue currentColour_;
136  bool bUseIcon_;
137 
138  Ogre::PanelOverlayElement* bar_;
139  Ogre::TextureUnitState* textureUnitState_;
140  Ogre::PanelOverlayElement* icon_;
141  std::map<float, ColourValue> colours_;
142  std::vector<BarColour*> barColours_;
143 
144  static unsigned int materialcount_s;
145  };
146 }
147 #endif /* _HUDBar_H__ */
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
bool bUseIcon_
Definition: HUDBar.h:136
Ogre::PanelOverlayElement * bar_
Definition: HUDBar.h:138
void setAutoColour(bool val)
Definition: HUDBar.h:100
::std::string string
Definition: gtest-port.h:756
Ogre::PanelOverlayElement * icon_
Definition: HUDBar.h:140
std::map< float, ColourValue > colours_
Definition: HUDBar.h:141
ColourValue colour_
Definition: HUDBar.h:62
Definition: HUDBar.h:67
std::vector< BarColour * > barColours_
Definition: HUDBar.h:142
virtual ~BarColour()
Definition: HUDBar.h:51
Ogre::ColourValue colour(const btVector3 &color, btScalar alpha)
Definition: OgreBulletUtils.h:41
constexpr T clamp(T x, T min, T max)
Keeps a value between a lower and an upper limit.
Definition: Math.h:120
float value_
progress of bar
Definition: HUDBar.h:134
xmlelement
Definition: Super.h:519
void setRightToLeft(bool r2l)
Definition: HUDBar.h:77
float getPosition() const
Definition: HUDBar.h:59
const ColourValue & getColour() const
Definition: HUDBar.h:56
bool getAutoColour() const
Definition: HUDBar.h:111
ColourValue currentColour_
Definition: HUDBar.h:135
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
bool right2Left_
Definition: HUDBar.h:132
Ogre::TextureUnitState * textureUnitState_
Definition: HUDBar.h:139
#define _OverlaysExport
Definition: OverlaysPrereqs.h:60
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Shared library macros, enums, constants and forward declarations for the overlays module ...
Definition: HUDBar.h:47
Mode
Definition: CorePrereqs.h:102
bool autoColour_
whether bar changes colour automatically
Definition: HUDBar.h:133
Declaration of BaseObject, the base class of all objects in Orxonox.
Definition: Context.h:45
void setColour(const ColourValue &colour)
Definition: HUDBar.h:55
Base class to display content directly onto the screen.
Definition: OrxonoxOverlay.h:72
Declaration of the OrxonoxOverlay class.
void setValue(float value)
Definition: HUDBar.h:88
float position_
Definition: HUDBar.h:63
void setPosition(float pos)
Definition: HUDBar.h:58
float getValue() const
Definition: HUDBar.h:97
static unsigned int materialcount_s
Definition: HUDBar.h:144
const ColourValue & getCurrentBarColour() const
Definition: HUDBar.h:120
bool getRightToLeft() const
Definition: HUDBar.h:85