Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/overlays/hud/HUDBar.h @ 11407

Last change on this file since 11407 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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