[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 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[1601] | 29 | #ifndef _OrxonoxOverlay_H__ |
---|
| 30 | #define _OrxonoxOverlay_H__ |
---|
[1588] | 31 | |
---|
| 32 | #include "OrxonoxPrereqs.h" |
---|
| 33 | |
---|
| 34 | #include <OgrePrerequisites.h> |
---|
[1590] | 35 | #include "tools/WindowEventListener.h" |
---|
[1588] | 36 | #include "util/Math.h" |
---|
| 37 | #include "core/BaseObject.h" |
---|
| 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[1614] | 41 | class _OrxonoxExport OrxonoxOverlay : public BaseObject, public WindowEventListener |
---|
| 42 | { |
---|
[1588] | 43 | public: |
---|
[1614] | 44 | OrxonoxOverlay(); |
---|
| 45 | virtual ~OrxonoxOverlay(); |
---|
[1588] | 46 | |
---|
[1614] | 47 | virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); |
---|
[1588] | 48 | |
---|
[1614] | 49 | void show() { this->setVisibility(true); } |
---|
| 50 | void hide() { this->setVisibility(false); } |
---|
[1588] | 51 | |
---|
[1614] | 52 | void setAspectCorrection(bool val); |
---|
| 53 | bool getAspectCorrection() { return this->bCorrectAspect_; } |
---|
[1588] | 54 | |
---|
[1614] | 55 | /** Sets the position of this overlay. */ |
---|
| 56 | void setPosition(Vector2 pos) { this->position_ = pos; this->positionChanged(); } |
---|
[1588] | 57 | |
---|
[1614] | 58 | /** Gets the current position. */ |
---|
| 59 | Vector2 getPosition() const { return this->position_; } |
---|
[1588] | 60 | |
---|
[1614] | 61 | /** Scrolls the overlay by the offsets provided. */ |
---|
| 62 | void scroll(Vector2 scroll) { this->position_ += scroll; this->positionChanged(); } |
---|
[1598] | 63 | |
---|
[1614] | 64 | /** Sets the origin point of this overlay. */ |
---|
| 65 | void setOrigin(Vector2 pos) { this->origin_ = pos; this->positionChanged(); } |
---|
[1598] | 66 | |
---|
[1614] | 67 | /** Gets the origin point of this overlay */ |
---|
| 68 | Vector2 getOrigin() const { return this->origin_; } |
---|
[1588] | 69 | |
---|
[1614] | 70 | /** Sets the rotation applied to this overlay.*/ |
---|
[1615] | 71 | void setRotation(const Degree& angle) { this->angle_ = angle; this->angleChanged(); } |
---|
[1588] | 72 | |
---|
[1614] | 73 | /** Gets the rotation applied to this overlay, in degrees.*/ |
---|
| 74 | const Radian& getRotation() const { return this->angle_; } |
---|
[1588] | 75 | |
---|
[1614] | 76 | /** Adds the passed in angle to the rotation applied to this overlay. */ |
---|
[1615] | 77 | void rotate(const Degree& angle) { this->angle_ += angle; this->angleChanged(); } |
---|
[1588] | 78 | |
---|
[1614] | 79 | /** Sets the size of this overlay. */ |
---|
| 80 | void setSize(const Vector2& size) { this->size_ = size; this->sizeChanged(); } |
---|
[1588] | 81 | |
---|
[1614] | 82 | /** Gets the current size (not corrected) */ |
---|
| 83 | Vector2 getUncorrectedSize() const { return this->size_; } |
---|
[1595] | 84 | |
---|
[1614] | 85 | /** Gets the current size (corrected) */ |
---|
| 86 | Vector2 getSize() const { return this->size_ * this->sizeCorrection_; } |
---|
[1595] | 87 | |
---|
[1614] | 88 | /** Gets the current size correction */ |
---|
| 89 | Vector2 getSizeCorrection() const { return this->sizeCorrection_; } |
---|
[1588] | 90 | |
---|
[1614] | 91 | /** Scales the overlay */ |
---|
| 92 | void scale(Vector2 scale) { this->size_ *= scale; this->sizeChanged(); } |
---|
| 93 | |
---|
[1615] | 94 | static void scaleOverlay(const std::string& name, float scale); |
---|
| 95 | static void scrollOverlay(const std::string& name, const Vector2& scroll); |
---|
| 96 | static void rotateOverlay(const std::string& name, const Degree& angle); |
---|
| 97 | |
---|
[1588] | 98 | protected: |
---|
[1614] | 99 | virtual void changedVisibility(); |
---|
| 100 | virtual void sizeChanged(); |
---|
| 101 | virtual void angleChanged(); |
---|
| 102 | virtual void positionChanged(); |
---|
[1615] | 103 | virtual void sizeCorrectionChanged(); |
---|
[1590] | 104 | |
---|
[1614] | 105 | void setBackgroundMaterial(const std::string& material); |
---|
[1615] | 106 | const std::string& getBackgroundMaterial() const; |
---|
[1595] | 107 | |
---|
[1614] | 108 | Ogre::Overlay* overlay_; |
---|
| 109 | Ogre::PanelOverlayElement* background_; |
---|
| 110 | float windowAspectRatio_; |
---|
| 111 | bool bCorrectAspect_; |
---|
| 112 | Vector2 size_; |
---|
| 113 | Vector2 sizeCorrection_; |
---|
| 114 | Radian angle_; |
---|
| 115 | Vector2 position_; |
---|
| 116 | Vector2 origin_; |
---|
[1588] | 117 | |
---|
[1615] | 118 | private: |
---|
| 119 | void windowResized(int newWidth, int newHeight); |
---|
| 120 | |
---|
[1614] | 121 | static unsigned int hudOverlayCounter_s; |
---|
[1615] | 122 | static std::map<std::string, OrxonoxOverlay*> overlays_s; |
---|
[1588] | 123 | }; |
---|
| 124 | } |
---|
| 125 | |
---|
[1601] | 126 | #endif /* _OrxonoxOverlay_H__ */ |
---|