[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 |
---|
| 28 | * |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | #ifndef _HUDBar_H__ |
---|
| 32 | #define _HUDBar_H__ |
---|
| 33 | |
---|
[5693] | 34 | #include "overlays/OverlaysPrereqs.h" |
---|
[1588] | 35 | |
---|
[1614] | 36 | #include <map> |
---|
[3196] | 37 | #include <vector> |
---|
| 38 | |
---|
[1588] | 39 | #include "util/Math.h" |
---|
[3196] | 40 | #include "util/OgreForwardRefs.h" |
---|
| 41 | #include "core/BaseObject.h" |
---|
[1601] | 42 | #include "overlays/OrxonoxOverlay.h" |
---|
[1588] | 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
[5693] | 46 | class _OverlaysExport BarColour : public BaseObject |
---|
[1618] | 47 | { |
---|
| 48 | public: |
---|
[2087] | 49 | BarColour(BaseObject* creator); |
---|
[3196] | 50 | virtual ~BarColour() { } |
---|
[1618] | 51 | |
---|
[1747] | 52 | virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); |
---|
[1618] | 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 | |
---|
[1627] | 65 | |
---|
[5693] | 66 | class _OverlaysExport HUDBar : public OrxonoxOverlay |
---|
[1615] | 67 | { |
---|
[1588] | 68 | public: |
---|
[2087] | 69 | HUDBar(BaseObject* creator); |
---|
[1615] | 70 | virtual ~HUDBar(); |
---|
[1588] | 71 | |
---|
[1615] | 72 | virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); |
---|
[1588] | 73 | |
---|
[1615] | 74 | void clearColours(); |
---|
[1588] | 75 | |
---|
[2662] | 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_; } |
---|
[1588] | 86 | |
---|
[2662] | 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_; } |
---|
[1627] | 98 | |
---|
[2662] | 99 | inline void setAutoColour(bool val) |
---|
| 100 | { |
---|
| 101 | if (val != this->autoColour_) |
---|
| 102 | { |
---|
| 103 | this->autoColour_ = val; |
---|
| 104 | this->valueChanged(); |
---|
[1627] | 105 | |
---|
[2662] | 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 | |
---|
[1627] | 119 | protected: |
---|
| 120 | virtual void valueChanged(); |
---|
| 121 | |
---|
[1588] | 122 | private: |
---|
[1618] | 123 | void addColour(BarColour* colour); |
---|
| 124 | BarColour* getColour(unsigned int index); |
---|
| 125 | |
---|
[1615] | 126 | bool right2Left_; |
---|
| 127 | bool autoColour_; //!< whether bar changes colour automatically |
---|
| 128 | float value_; //!< progress of bar |
---|
[2662] | 129 | ColourValue currentColour_; |
---|
[1588] | 130 | |
---|
[1615] | 131 | Ogre::PanelOverlayElement* bar_; |
---|
| 132 | Ogre::TextureUnitState* textureUnitState_; |
---|
| 133 | std::map<float, ColourValue> colours_; |
---|
[1618] | 134 | std::vector<BarColour*> barColours_; |
---|
[1615] | 135 | |
---|
| 136 | static unsigned int materialcount_s; |
---|
[1588] | 137 | }; |
---|
| 138 | } |
---|
| 139 | #endif /* _HUDBar_H__ */ |
---|