Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands3/src/modules/overlays/hud/HUDBar.h @ 7645

Last change on this file since 7645 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 3.9 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 *
29 */
30
31#ifndef _HUDBar_H__
32#define _HUDBar_H__
33
34#include "overlays/OverlaysPrereqs.h"
35
36#include <map>
37#include <vector>
38
39#include "util/Math.h"
40#include "util/OgreForwardRefs.h"
41#include "core/BaseObject.h"
42#include "overlays/OrxonoxOverlay.h"
43
44namespace orxonox
45{
46    class _OverlaysExport BarColour : public BaseObject
47    {
48    public:
49        BarColour(BaseObject* creator);
50        virtual ~BarColour() { }
51
52        virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
53
54        void setColour(const ColourValue& colour) { this->colour_ = colour; }
55        const ColourValue& getColour() const { return this->colour_; }
56
57        void setPosition(float pos) { this->position_ = pos; }
58        float getPosition() const    { return this->position_; }
59
60    private:
61        ColourValue colour_;
62        float position_;
63    };
64
65
66    class _OverlaysExport HUDBar : public OrxonoxOverlay
67    {
68    public:
69        HUDBar(BaseObject* creator);
70        virtual ~HUDBar();
71
72        virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
73
74        void clearColours();
75
76        inline void setRightToLeft(bool r2l)
77        {
78            if (r2l != this->right2Left_)
79            {
80                this->right2Left_ = r2l;
81                this->valueChanged();
82            }
83        }
84        inline bool getRightToLeft() const
85            { return this->right2Left_; }
86
87        inline void setValue(float value)
88        {
89            float temp = clamp(value, 0.0f, 1.0f);
90            if (temp != this->value_)
91            {
92                this->value_ = temp;
93                this->valueChanged();
94            }
95        }
96        inline float getValue() const
97            { return this->value_; }
98
99        inline void setAutoColour(bool val)
100        {
101            if (val != this->autoColour_)
102            {
103                this->autoColour_ = val;
104                this->valueChanged();
105
106                if (!val)
107                    this->currentColour_ = ColourValue::White;
108            }
109        }
110        inline bool getAutoColour() const
111            { return this->autoColour_; }
112
113        void setBarTexture(const std::string& texture);
114        const std::string& getBarTexture() const;
115
116        inline const ColourValue& getCurrentBarColour() const
117            { return this->currentColour_; }
118
119    protected:
120        virtual void valueChanged();
121
122    private:
123        void addColour(BarColour* colour);
124        BarColour* getColour(unsigned int index);
125
126        bool right2Left_;
127        bool autoColour_;                   //!< whether bar changes colour automatically
128        float value_;                       //!< progress of bar
129        ColourValue currentColour_;
130
131        Ogre::PanelOverlayElement* bar_;
132        Ogre::TextureUnitState* textureUnitState_;
133        std::map<float, ColourValue> colours_;
134        std::vector<BarColour*> barColours_;
135
136        static unsigned int materialcount_s;
137    };
138}
139#endif /* _HUDBar_H__ */
Note: See TracBrowser for help on using the repository browser.