[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> |
---|
| 39 | |
---|
[1588] | 40 | #include "util/Math.h" |
---|
[3196] | 41 | #include "util/OgreForwardRefs.h" |
---|
| 42 | #include "core/BaseObject.h" |
---|
[1601] | 43 | #include "overlays/OrxonoxOverlay.h" |
---|
[1588] | 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
[5693] | 47 | class _OverlaysExport BarColour : public BaseObject |
---|
[1618] | 48 | { |
---|
| 49 | public: |
---|
[9667] | 50 | BarColour(Context* context); |
---|
[3196] | 51 | virtual ~BarColour() { } |
---|
[1618] | 52 | |
---|
[11071] | 53 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; |
---|
[1618] | 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 | |
---|
[1627] | 66 | |
---|
[5693] | 67 | class _OverlaysExport HUDBar : public OrxonoxOverlay |
---|
[1615] | 68 | { |
---|
[1588] | 69 | public: |
---|
[9667] | 70 | HUDBar(Context* context); |
---|
[1615] | 71 | virtual ~HUDBar(); |
---|
[1588] | 72 | |
---|
[11071] | 73 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; |
---|
[1588] | 74 | |
---|
[1615] | 75 | void clearColours(); |
---|
[1588] | 76 | |
---|
[2662] | 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_; } |
---|
[1588] | 87 | |
---|
[2662] | 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_; } |
---|
[1627] | 99 | |
---|
[2662] | 100 | inline void setAutoColour(bool val) |
---|
| 101 | { |
---|
| 102 | if (val != this->autoColour_) |
---|
| 103 | { |
---|
| 104 | this->autoColour_ = val; |
---|
| 105 | this->valueChanged(); |
---|
[1627] | 106 | |
---|
[2662] | 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 | |
---|
[11052] | 117 | void setIconMaterial(const std::string& iconMaterial); |
---|
| 118 | const std::string& getIconMaterial() const; |
---|
| 119 | |
---|
[2662] | 120 | inline const ColourValue& getCurrentBarColour() const |
---|
| 121 | { return this->currentColour_; } |
---|
| 122 | |
---|
[11795] | 123 | void setIconPosition(Vector2 position); |
---|
| 124 | void setIconDimensions(Vector2 dimensions); |
---|
[11052] | 125 | |
---|
[1627] | 126 | protected: |
---|
| 127 | virtual void valueChanged(); |
---|
[1588] | 128 | private: |
---|
[1618] | 129 | void addColour(BarColour* colour); |
---|
| 130 | BarColour* getColour(unsigned int index); |
---|
| 131 | |
---|
[1615] | 132 | bool right2Left_; |
---|
| 133 | bool autoColour_; //!< whether bar changes colour automatically |
---|
| 134 | float value_; //!< progress of bar |
---|
[2662] | 135 | ColourValue currentColour_; |
---|
[11052] | 136 | bool bUseIcon_; |
---|
[1588] | 137 | |
---|
[1615] | 138 | Ogre::PanelOverlayElement* bar_; |
---|
| 139 | Ogre::TextureUnitState* textureUnitState_; |
---|
[11052] | 140 | Ogre::PanelOverlayElement* icon_; |
---|
[1615] | 141 | std::map<float, ColourValue> colours_; |
---|
[1618] | 142 | std::vector<BarColour*> barColours_; |
---|
[1615] | 143 | |
---|
| 144 | static unsigned int materialcount_s; |
---|
[1588] | 145 | }; |
---|
| 146 | } |
---|
| 147 | #endif /* _HUDBar_H__ */ |
---|