Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/SuperOrxoBros_HS18/src/modules/overlays/hud/HUDBar.h @ 12175

Last change on this file since 12175 was 12175, checked in by siramesh, 5 years ago

Super Orxo Bros (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 4.2 KB
Line 
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
35#include "overlays/OverlaysPrereqs.h"
36
37#include <map>
38#include <vector>
39
40#include "util/Math.h"
41#include "util/OgreForwardRefs.h"
42#include "core/BaseObject.h"
43#include "overlays/OrxonoxOverlay.h"
44
45namespace orxonox
46{
47    class _OverlaysExport BarColour : public BaseObject
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
67    class _OverlaysExport HUDBar : public OrxonoxOverlay
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
132        bool right2Left_;
133        bool autoColour_;                   //!< whether bar changes colour automatically
134        float value_;                       //!< progress of bar
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__ */
Note: See TracBrowser for help on using the repository browser.