Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/OrxonoxOverlay.h @ 11957

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