Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/overlays/OrxonoxOverlay.h @ 2350

Last change on this file since 2350 was 2256, checked in by landauf, 16 years ago

The SpaceShips HUD is working again (Speedbar and Radar)

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