Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 25, 2008, 9:07:55 PM (16 years ago)
Author:
rgrieder
Message:

Added documentation for OrxonoxOverlay and clarified the size/actual size mess.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud/src/orxonox/overlays/OrxonoxOverlay.h

    r1615 r1622  
    2727 */
    2828
     29/**
     30@file
     31@brief Declaration of the OrxonoxOverlay class.
     32*/
     33
    2934#ifndef _OrxonoxOverlay_H__
    3035#define _OrxonoxOverlay_H__
     
    3944namespace orxonox
    4045{
     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    */
    4169    class _OrxonoxExport OrxonoxOverlay : public BaseObject, public WindowEventListener
    4270    {
     
    4775        virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
    4876
     77        //! Shows the overlay with an detour to BaseObject::visibility_
    4978        void show() { this->setVisibility(true); }
     79        //! Hides the overlay with an detour to BaseObject::visibility_
    5080        void hide() { this->setVisibility(false); }
    5181
    52         void setAspectCorrection(bool val);
    53         bool getAspectCorrection() { return this->bCorrectAspect_; }
     82        /** Sets whether the aspect of the overlay is corrected.
     83            This is for instance useful for round objects that should stay round no matter
     84            what the screen resolution is. */
     85        void setAspectCorrection(bool val)        { this->bCorrectAspect_ = val; this->sizeCorrectionChanged(); }
     86        //! Returns whether the window aspect is corrected
     87        bool getAspectCorrection() const          { return this->bCorrectAspect_; }
    5488
    55         /** Sets the position of this overlay. */
    56         void setPosition(Vector2 pos) { this->position_ = pos; this->positionChanged(); }
     89        //! Sets the position of this overlay on the screen.
     90        void setPosition(Vector2 pos)             { this->position_ = pos; this->positionChanged(); }
    5791
    58         /** Gets the current position. */
    59         Vector2 getPosition() const { return this->position_; }
     92        //! Returns the current position on the screen.
     93        const Vector2& getPosition() const        { return this->position_; }
    6094
    61         /** Scrolls the overlay by the offsets provided. */
    62         void scroll(Vector2 scroll) { this->position_ += scroll; this->positionChanged(); }
     95        //! Scrolls the overlay. @param offset The offset given.
     96        void scroll(const Vector2& offset)        { this->position_ += offset; this->positionChanged(); }
    6397
    64         /** Sets the origin point of this overlay. */
    65         void setOrigin(Vector2 pos) { this->origin_ = pos; this->positionChanged(); }
     98        /** Sets the point in the overlay where to pick it when translating.
     99            For instance setting it to (1.0,1.0) means that the lower right corner of the
     100            overlay will be put at position_.
     101            This primarily helps aligning an overlay to any corner/margin on the screen. */
     102        void setPickPoint(const Vector2& position){ this->pickPoint_ = position; this->positionChanged(); }
    66103
    67         /** Gets the origin point of this overlay */
    68         Vector2 getOrigin() const { return this->origin_; }
     104        //! Gets the pick point of this overlay. @see setPickPoint()
     105        const Vector2& getPickPoint() const       { return this->pickPoint_; }
    69106
    70         /** Sets the rotation applied to this overlay.*/
    71         void setRotation(const Degree& angle) { this->angle_ = angle; this->angleChanged(); }
     107        //! Sets the rotation angle applied to this overlay in degrees.
     108        void setRotation(const Degree& angle)     { this->angle_ = angle; this->angleChanged(); }
    72109
    73         /** Gets the rotation applied to this overlay, in degrees.*/
    74         const Radian& getRotation() const { return this->angle_; }
     110        //! Gets the rotation angle applied to this overlay in degrees.
     111        const Radian& getRotation() const         { return this->angle_; }
    75112
    76         /** Adds the passed in angle to the rotation applied to this overlay. */
    77         void rotate(const Degree& angle) { this->angle_ += angle; this->angleChanged(); }
     113        //! Rotates the overlay by angle degrees.
     114        void rotate(const Degree& angle)          { this->angle_ += angle; this->angleChanged(); }
    78115
    79         /** Sets the size of this overlay. */
    80         void setSize(const Vector2& size) { this->size_ = size; this->sizeChanged(); }
     116        //! Sets the size of this overlay.
     117        void setSize(const Vector2& size)         { this->size_ = size; this->sizeChanged(); }
    81118
    82         /** Gets the current size (not corrected) */
    83         Vector2 getUncorrectedSize() const { return this->size_; }
     119        //! Gets the current size that was set (uncorrected)
     120        Vector2 getSize() const                   { return this->size_ * this->sizeCorrection_; }
    84121
    85         /** Gets the current size (corrected) */
    86         Vector2 getSize() const { return this->size_ * this->sizeCorrection_; }
     122        //! Gets the actual size of the overlay on the screen (corrected)
     123        const Vector2& getActualSize() const      { return this->size_; }
    87124
    88         /** Gets the current size correction */
    89         Vector2 getSizeCorrection() const { return this->sizeCorrection_; }
     125        //! Gets the current size correction (default: 1.0, 1.0)
     126        const Vector2& getSizeCorrection() const { return this->sizeCorrection_; }
    90127
    91         /** Scales the overlay */
    92         void scale(Vector2 scale) { this->size_ *= scale; this->sizeChanged(); }
     128        //! Scales the overlay by scale.
     129        void scale(const Vector2& scale)          { this->size_ *= scale; this->sizeChanged(); }
    93130
     131        //! ConsoleCommand: Accesses the overlay by its name and scales it.
    94132        static void scaleOverlay(const std::string& name, float scale);
     133        //! ConsoleCommand: Accesses the overlay by its name and scrolls it.
    95134        static void scrollOverlay(const std::string& name, const Vector2& scroll);
     135        //! ConsoleCommand: Accesses the overlay by its name and rotates it.
    96136        static void rotateOverlay(const std::string& name, const Degree& angle);
    97137
    98138    protected:
    99139        virtual void changedVisibility();
     140        virtual void angleChanged();
     141        virtual void sizeCorrectionChanged();
    100142        virtual void sizeChanged();
    101         virtual void angleChanged();
    102143        virtual void positionChanged();
    103         virtual void sizeCorrectionChanged();
    104144
    105145        void setBackgroundMaterial(const std::string& material);
    106146        const std::string& getBackgroundMaterial() const;
    107147
    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_;
     148        Ogre::Overlay* overlay_;                   //!< The overlay the entire class is about.
     149        Ogre::PanelOverlayElement* background_;    //!< Background image (blank per default).
     150
     151        float windowAspectRatio_;                  //!< Screen.width / screen.height
     152        bool bCorrectAspect_;                      //!< Whether or not to correct the size. @see setAspectCorrection()
     153        Vector2 size_;                             //!< Internal size of the overlay.
     154        Vector2 sizeCorrection_;                   //!< Value to correct the size because of the window aspect.
     155        Vector2 position_;                         //!< Position of the pickPoint on the screen.
     156        Vector2 pickPoint_;                        //!< Point on the overlay to pick when translating
     157        Radian angle_;                             //!< Rotation angle of the overlay
    117158
    118159    private:
    119160        void windowResized(int newWidth, int newHeight);
    120161
    121         static unsigned int hudOverlayCounter_s;
     162        static unsigned int hudOverlayCounter_s;   //!< Static counter for hud elements
     163        /** Contains all the overlays in a map for quick access via console commands.
     164            We could also use the ObjectList, but that doesn't guarantee XMLPort(.) was called and is slower. */
    122165        static std::map<std::string, OrxonoxOverlay*> overlays_s;
    123166  };
Note: See TracChangeset for help on using the changeset viewer.