[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 | |
---|
[1622] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Declaration of the OrxonoxOverlay class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[1601] | 34 | #ifndef _OrxonoxOverlay_H__ |
---|
| 35 | #define _OrxonoxOverlay_H__ |
---|
[1588] | 36 | |
---|
| 37 | #include "OrxonoxPrereqs.h" |
---|
| 38 | |
---|
[3196] | 39 | #include <string> |
---|
| 40 | |
---|
[1588] | 41 | #include "util/Math.h" |
---|
[3196] | 42 | #include "util/OgreForwardRefs.h" |
---|
[1588] | 43 | #include "core/BaseObject.h" |
---|
[6753] | 44 | #include "core/Super.h" |
---|
[3327] | 45 | #include "core/WindowEventListener.h" |
---|
[1588] | 46 | |
---|
[9159] | 47 | |
---|
[1588] | 48 | namespace orxonox |
---|
| 49 | { |
---|
[1622] | 50 | /** |
---|
| 51 | @brief |
---|
| 52 | Base class to display content directly onto the screen. |
---|
| 53 | This is merely a wrapper of the Ogre::Overlay to implement more features and integrate it |
---|
| 54 | in our class hierarchy for xml loading and config values. |
---|
| 55 | The mentioned features are: |
---|
| 56 | - Automatic positioning depending on the scale and the rotation angle. |
---|
| 57 | You can specify a "pick point" relative to the overlay itself. This point will always be exactly |
---|
| 58 | at the position (position_) of the overlay. That allows for margin/corner aligment. |
---|
| 59 | It even works when a rotation angle is applied. |
---|
| 60 | - Virtual methods for changedVisibilty() (BaseObject), angleChanged(), sizeCorrectionChanged(), |
---|
| 61 | sizeChanged() and positionChanged(), that can be overridden by any derivative. This enables for |
---|
| 62 | custom configurability of the size, position and rotation attributes. For intance, the HUDNavigation |
---|
| 63 | should behave differently to sizeChanged() than a standard overlay. |
---|
| 64 | - Console commands for scale, rotate and scroll (accessed by name) |
---|
| 65 | - Standard Ogre::PanelOverlayElement for a background image (class doesn't have to be derived |
---|
| 66 | only for displaying a picture). |
---|
| 67 | - Reacts to changes of the window aspect |
---|
| 68 | - Last but not least: On demand you can tell the overlay to automatically resale to correct for |
---|
| 69 | aspect distortion. E.g. if you play 1024x768 you wouldn't want a round object to be oval. |
---|
| 70 | Remark: This can (due to the Ogre::Overlay transformation order) only work for angle that are |
---|
| 71 | multiples of 90 degrees. But it's only a small drawback. |
---|
| 72 | */ |
---|
[1614] | 73 | class _OrxonoxExport OrxonoxOverlay : public BaseObject, public WindowEventListener |
---|
| 74 | { |
---|
[1588] | 75 | public: |
---|
[1632] | 76 | /** |
---|
| 77 | @brief |
---|
| 78 | Describes the rotational state of a an overlay. |
---|
| 79 | Horizontal means 0/180 degrees, Vertical is 90/270 degrees |
---|
[8309] | 80 | and in between is everything else. |
---|
[1632] | 81 | */ |
---|
| 82 | enum RotationState |
---|
| 83 | { |
---|
| 84 | Horizontal, |
---|
| 85 | Vertical, |
---|
| 86 | Inbetween |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | public: |
---|
[2087] | 90 | OrxonoxOverlay(BaseObject* creator); |
---|
[1614] | 91 | virtual ~OrxonoxOverlay(); |
---|
[1588] | 92 | |
---|
[7401] | 93 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
[1588] | 94 | |
---|
[2087] | 95 | virtual void changedName(); |
---|
| 96 | |
---|
[1622] | 97 | //! Shows the overlay with an detour to BaseObject::visibility_ |
---|
[1625] | 98 | void show() { this->setVisible(true); } |
---|
[1622] | 99 | //! Hides the overlay with an detour to BaseObject::visibility_ |
---|
[1625] | 100 | void hide() { this->setVisible(false); } |
---|
[1588] | 101 | |
---|
[1622] | 102 | /** Sets whether the aspect of the overlay is corrected. |
---|
| 103 | This is for instance useful for round objects that should stay round no matter |
---|
| 104 | what the screen resolution is. */ |
---|
| 105 | void setAspectCorrection(bool val) { this->bCorrectAspect_ = val; this->sizeCorrectionChanged(); } |
---|
| 106 | //! Returns whether the window aspect is corrected |
---|
| 107 | bool getAspectCorrection() const { return this->bCorrectAspect_; } |
---|
[1588] | 108 | |
---|
[1622] | 109 | //! Sets the position of this overlay on the screen. |
---|
| 110 | void setPosition(Vector2 pos) { this->position_ = pos; this->positionChanged(); } |
---|
[1588] | 111 | |
---|
[1622] | 112 | //! Returns the current position on the screen. |
---|
| 113 | const Vector2& getPosition() const { return this->position_; } |
---|
[1588] | 114 | |
---|
[1622] | 115 | //! Scrolls the overlay. @param offset The offset given. |
---|
| 116 | void scroll(const Vector2& offset) { this->position_ += offset; this->positionChanged(); } |
---|
[1598] | 117 | |
---|
[1622] | 118 | /** Sets the point in the overlay where to pick it when translating. |
---|
| 119 | For instance setting it to (1.0,1.0) means that the lower right corner of the |
---|
| 120 | overlay will be put at position_. |
---|
| 121 | This primarily helps aligning an overlay to any corner/margin on the screen. */ |
---|
| 122 | void setPickPoint(const Vector2& position){ this->pickPoint_ = position; this->positionChanged(); } |
---|
[1598] | 123 | |
---|
[1622] | 124 | //! Gets the pick point of this overlay. @see setPickPoint() |
---|
| 125 | const Vector2& getPickPoint() const { return this->pickPoint_; } |
---|
[1588] | 126 | |
---|
[1622] | 127 | //! Sets the rotation angle applied to this overlay in degrees. |
---|
| 128 | void setRotation(const Degree& angle) { this->angle_ = angle; this->angleChanged(); } |
---|
[1588] | 129 | |
---|
[1622] | 130 | //! Gets the rotation angle applied to this overlay in degrees. |
---|
[2662] | 131 | const Degree& getRotation() const { return this->angle_; } |
---|
[1588] | 132 | |
---|
[1622] | 133 | //! Rotates the overlay by angle degrees. |
---|
| 134 | void rotate(const Degree& angle) { this->angle_ += angle; this->angleChanged(); } |
---|
[1588] | 135 | |
---|
[1622] | 136 | //! Sets the size of this overlay. |
---|
| 137 | void setSize(const Vector2& size) { this->size_ = size; this->sizeChanged(); } |
---|
[1588] | 138 | |
---|
[1622] | 139 | //! Gets the current size that was set (uncorrected) |
---|
[3196] | 140 | const Vector2& getSize() const { return this->size_; } |
---|
[1595] | 141 | |
---|
[1622] | 142 | //! Gets the actual size of the overlay on the screen (corrected) |
---|
[3196] | 143 | Vector2 getActualSize() const { return this->size_ * this->sizeCorrection_; } |
---|
[1595] | 144 | |
---|
[1622] | 145 | //! Gets the current size correction (default: 1.0, 1.0) |
---|
| 146 | const Vector2& getSizeCorrection() const { return this->sizeCorrection_; } |
---|
[1588] | 147 | |
---|
[1622] | 148 | //! Scales the overlay by scale. |
---|
| 149 | void scale(const Vector2& scale) { this->size_ *= scale; this->sizeChanged(); } |
---|
[1614] | 150 | |
---|
[1622] | 151 | //! ConsoleCommand: Accesses the overlay by its name and scales it. |
---|
[1615] | 152 | static void scaleOverlay(const std::string& name, float scale); |
---|
[1622] | 153 | //! ConsoleCommand: Accesses the overlay by its name and scrolls it. |
---|
[1615] | 154 | static void scrollOverlay(const std::string& name, const Vector2& scroll); |
---|
[2993] | 155 | static void toggleVisibility(const std::string& name); |
---|
[8309] | 156 | static void showOverlay(const std::string& name); |
---|
[1622] | 157 | //! ConsoleCommand: Accesses the overlay by its name and rotates it. |
---|
[1615] | 158 | static void rotateOverlay(const std::string& name, const Degree& angle); |
---|
| 159 | |
---|
[6417] | 160 | void setBackgroundMaterial(const std::string& material); |
---|
| 161 | const std::string& getBackgroundMaterial() const; |
---|
| 162 | |
---|
[8706] | 163 | void setBackgroundTexture(const std::string& texture); |
---|
| 164 | const std::string& getBackgroundTexture() const; |
---|
| 165 | |
---|
[6417] | 166 | void setBackgroundAlpha(float alpha); |
---|
| 167 | |
---|
[8706] | 168 | void setBackgroundColour(ColourValue colour); |
---|
| 169 | |
---|
[1747] | 170 | virtual void changedVisibility(); |
---|
| 171 | |
---|
[2890] | 172 | inline void setOwner(BaseObject* owner) |
---|
[2662] | 173 | { |
---|
| 174 | if (this->owner_ != owner) |
---|
| 175 | { |
---|
| 176 | this->owner_ = owner; |
---|
| 177 | this->changedOwner(); |
---|
| 178 | } |
---|
| 179 | } |
---|
[2890] | 180 | inline BaseObject* getOwner() const |
---|
[2662] | 181 | { return this->owner_; } |
---|
| 182 | virtual void changedOwner() {} |
---|
| 183 | |
---|
[6057] | 184 | void setOverlayGroup(OverlayGroup* group); |
---|
[2662] | 185 | inline OverlayGroup* getOverlayGroup() const |
---|
| 186 | { return this->group_; } |
---|
[6417] | 187 | virtual void changedOverlayGroup() |
---|
[5980] | 188 | { this->changedVisibility(); } |
---|
[9159] | 189 | void add3DMesh(Ogre::Entity* entity); |
---|
[2662] | 190 | |
---|
[9159] | 191 | |
---|
[1588] | 192 | protected: |
---|
[1622] | 193 | virtual void angleChanged(); |
---|
| 194 | virtual void sizeCorrectionChanged(); |
---|
[1614] | 195 | virtual void sizeChanged(); |
---|
| 196 | virtual void positionChanged(); |
---|
[1590] | 197 | |
---|
[1622] | 198 | Ogre::Overlay* overlay_; //!< The overlay the entire class is about. |
---|
| 199 | Ogre::PanelOverlayElement* background_; //!< Background image (blank per default). |
---|
[9159] | 200 | Ogre::SceneNode* overlay3d_; //!< The scene where one can add 3D objects to the overlay |
---|
[1588] | 201 | |
---|
[1622] | 202 | float windowAspectRatio_; //!< Screen.width / screen.height |
---|
| 203 | bool bCorrectAspect_; //!< Whether or not to correct the size. @see setAspectCorrection() |
---|
| 204 | Vector2 size_; //!< Internal size of the overlay. |
---|
| 205 | Vector2 sizeCorrection_; //!< Value to correct the size because of the window aspect. |
---|
| 206 | Vector2 position_; //!< Position of the pickPoint on the screen. |
---|
| 207 | Vector2 pickPoint_; //!< Point on the overlay to pick when translating |
---|
[2662] | 208 | Degree angle_; //!< Rotation angle of the overlay |
---|
[3196] | 209 | RotationState rotState_; //!< horizontal, vertical or inbetween |
---|
[1622] | 210 | |
---|
[1615] | 211 | private: |
---|
[2896] | 212 | void windowResized(unsigned int newWidth, unsigned int newHeight); |
---|
[1615] | 213 | |
---|
[1622] | 214 | static unsigned int hudOverlayCounter_s; //!< Static counter for hud elements |
---|
| 215 | /** Contains all the overlays in a map for quick access via console commands. |
---|
| 216 | We could also use the ObjectList, but that doesn't guarantee XMLPort(.) was called and is slower. */ |
---|
[1615] | 217 | static std::map<std::string, OrxonoxOverlay*> overlays_s; |
---|
[2890] | 218 | BaseObject* owner_; |
---|
[2662] | 219 | OverlayGroup* group_; |
---|
[6417] | 220 | Ogre::Pass* backgroundAlphaPass_; |
---|
[9159] | 221 | |
---|
[1588] | 222 | }; |
---|
[2662] | 223 | |
---|
[5929] | 224 | SUPER_FUNCTION(6, OrxonoxOverlay, changedOwner, false); |
---|
| 225 | SUPER_FUNCTION(7, OrxonoxOverlay, changedOverlayGroup, false); |
---|
[1588] | 226 | } |
---|
| 227 | |
---|
[1601] | 228 | #endif /* _OrxonoxOverlay_H__ */ |
---|