OgreOverlayElement.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028
    00029 #ifndef __OverlayElement_H__
    00030 #define __OverlayElement_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreString.h"
    00034 #include "OgreRenderable.h"
    00035 #include "OgreUTFString.h"
    00036 #include "OgreStringInterface.h"
    00037 #include "OgreOverlayElementCommands.h"
    00038
    00039 #include "OgreColourValue.h"
    00040 #include "OgreRectangle.h"
    00041
    00042 namespace Ogre {
    00050 #if OGRE_UNICODE_SUPPORT
    00051     typedef UTFString DisplayString;
    00052 #   define OGRE_DEREF_DISPLAYSTRING_ITERATOR(it) it.getCharacter()
    00053 #else
    00054     typedef String DisplayString;
    00055 #   define OGRE_DEREF_DISPLAYSTRING_ITERATOR(it) *it
    00056 #endif
    00057
    00059     enum GuiMetricsMode
    00060     {
    00062         GMM_RELATIVE,
    00064         GMM_PIXELS,
    00066         GMM_RELATIVE_ASPECT_ADJUSTED
    00067     };
    00068
    00072     enum GuiHorizontalAlignment
    00073     {
    00074         GHA_LEFT,
    00075         GHA_CENTER,
    00076         GHA_RIGHT
    00077     };
    00081     enum GuiVerticalAlignment
    00082     {
    00083         GVA_TOP,
    00084         GVA_CENTER,
    00085         GVA_BOTTOM
    00086     };
    00087
    00109     class _OgreExport OverlayElement : public StringInterface, public Renderable, public OverlayAlloc
    00110     {
    00111     public:
    00112
    00113     protected:
    00114         // Command object for setting / getting parameters
    00115         static OverlayElementCommands::CmdLeft msLeftCmd;
    00116         static OverlayElementCommands::CmdTop msTopCmd;
    00117         static OverlayElementCommands::CmdWidth msWidthCmd;
    00118         static OverlayElementCommands::CmdHeight msHeightCmd;
    00119         static OverlayElementCommands::CmdMaterial msMaterialCmd;
    00120         static OverlayElementCommands::CmdCaption msCaptionCmd;
    00121         static OverlayElementCommands::CmdMetricsMode msMetricsModeCmd;
    00122         static OverlayElementCommands::CmdHorizontalAlign msHorizontalAlignCmd;
    00123         static OverlayElementCommands::CmdVerticalAlign msVerticalAlignCmd;
    00124         static OverlayElementCommands::CmdVisible msVisibleCmd;
    00125
    00126
    00127         String mName;
    00128         bool mVisible;
    00129         bool mCloneable;
    00130         Real mLeft;
    00131         Real mTop;
    00132         Real mWidth;
    00133         Real mHeight;
    00134         String mMaterialName;
    00135         MaterialPtr mMaterial;
    00136         DisplayString mCaption;
    00137         ColourValue mColour;
    00138         Rectangle mClippingRegion;
    00139
    00140         GuiMetricsMode mMetricsMode;
    00141         GuiHorizontalAlignment mHorzAlign;
    00142         GuiVerticalAlignment mVertAlign;
    00143
    00144         // metric-mode positions, used in GMM_PIXELS & GMM_RELATIVE_ASPECT_ADJUSTED mode.
    00145         Real mPixelTop;
    00146         Real mPixelLeft;
    00147         Real mPixelWidth;
    00148         Real mPixelHeight;
    00149         Real mPixelScaleX;
    00150         Real mPixelScaleY;
    00151
    00152         // Parent pointer
    00153         OverlayContainer* mParent;
    00154         // Overlay attached to
    00155         Overlay* mOverlay;
    00156
    00157         // Derived positions from parent
    00158         Real mDerivedLeft;
    00159         Real mDerivedTop;
    00160         bool mDerivedOutOfDate;
    00161
    00163         bool mGeomPositionsOutOfDate;
    00165         bool mGeomUVsOutOfDate;
    00166
    00167         // Zorder for when sending to render queue
    00168         // Derived from parent
    00169         ushort mZOrder;
    00170
    00171         // world transforms
    00172         Matrix4 mXForm;
    00173
    00174         // is element enabled
    00175         bool mEnabled;
    00176
    00177         // is element initialised
    00178         bool mInitialised;
    00179
    00180         // Used to see if this element is created from a Template
    00181         OverlayElement* mSourceTemplate ;
    00182
    00187         virtual void updatePositionGeometry(void) = 0;
    00192         virtual void updateTextureGeometry(void) = 0;
    00193
    00202         virtual void addBaseParameters(void);
    00203
    00204     public:
    00206         OverlayElement(const String& name);
    00207         virtual ~OverlayElement();
    00208
    00210         virtual void initialise(void) = 0;
    00211
    00213         const String& getName(void) const;
    00214
    00215
    00217         virtual void show(void);
    00218
    00220         virtual void hide(void);
    00221
    00223         bool isVisible(void) const;
    00224
    00225         bool isEnabled() const;
    00226         virtual void setEnabled(bool b);
    00227
    00228
    00230         void setDimensions(Real width, Real height);
    00231
    00234         void setPosition(Real left, Real top);
    00235
    00237         void setWidth(Real width);
    00239         Real getWidth(void) const;
    00240
    00242         void setHeight(Real height);
    00244         Real getHeight(void) const;
    00245
    00247         void setLeft(Real left);
    00249         Real getLeft(void) const;
    00250
    00252         void setTop(Real Top);
    00254         Real getTop(void) const;
    00255
    00257         Real _getLeft(void) const { return mLeft; }
    00259         Real _getTop(void) const { return mTop; }
    00261         Real _getWidth(void) const { return mWidth; }
    00263         Real _getHeight(void) const { return mHeight; }
    00265         void _setLeft(Real left);
    00267         void _setTop(Real top);
    00269         void _setWidth(Real width);
    00271         void _setHeight(Real height);
    00273         void _setPosition(Real left, Real top);
    00275         void _setDimensions(Real width, Real height);
    00276
    00278         virtual const String& getMaterialName(void) const;
    00279
    00290         virtual void setMaterialName(const String& matName);
    00291
    00292
    00293         // --- Renderable Overrides ---
    00295         const MaterialPtr& getMaterial(void) const;
    00296
    00297         // NB getRenderOperation not implemented, still abstract here
    00298
    00300         void getWorldTransforms(Matrix4* xform) const;
    00301
    00303         virtual void _positionsOutOfDate(void);
    00304
    00306         virtual void _update(void);
    00307
    00309         virtual void _updateFromParent(void);
    00310
    00312         virtual void _notifyParent(OverlayContainer* parent, Overlay* overlay);
    00313
    00315         virtual Real _getDerivedLeft(void);
    00316
    00318         virtual Real _getDerivedTop(void);
    00319
    00321         virtual Real _getRelativeWidth(void);
    00323         virtual Real _getRelativeHeight(void);
    00324
    00325
    00327         virtual void _getClippingRegion(Rectangle &clippingRegion);
    00328
    00341         virtual ushort _notifyZOrder(ushort newZOrder);
    00342
    00346         virtual void _notifyWorldTransforms(const Matrix4& xform);
    00347
    00351         virtual void _notifyViewport();
    00352
    00354         virtual void _updateRenderQueue(RenderQueue* queue);
    00355
    00357         void visitRenderables(Renderable::Visitor* visitor,
    00358             bool debugRenderables = false);
    00359
    00361         virtual const String& getTypeName(void) const = 0;
    00362
    00369         virtual void setCaption(const DisplayString& text);
    00371         virtual const DisplayString& getCaption(void) const;
    00378         virtual void setColour(const ColourValue& col);
    00379
    00381         virtual const ColourValue& getColour(void) const;
    00382
    00393         virtual void setMetricsMode(GuiMetricsMode gmm);
    00395         virtual GuiMetricsMode getMetricsMode(void) const;
    00411         virtual void setHorizontalAlignment(GuiHorizontalAlignment gha);
    00413         virtual GuiHorizontalAlignment getHorizontalAlignment(void) const;
    00429         virtual void setVerticalAlignment(GuiVerticalAlignment gva);
    00431         virtual GuiVerticalAlignment getVerticalAlignment(void) const;
    00432
    00433
    00434
    00435
    00437         virtual bool contains(Real x, Real y) const;
    00438
    00440         virtual OverlayElement* findElementAt(Real x, Real y);      // relative to parent
    00441
    00445         inline virtual bool isContainer() const
    00446         { return false; }
    00447
    00448         inline virtual bool isKeyEnabled() const
    00449         { return false; }
    00450
    00451         inline virtual bool isCloneable() const
    00452         { return mCloneable; }
    00453
    00454         inline virtual void setCloneable(bool c)
    00455         { mCloneable = c; }
    00456
    00460         OverlayContainer* getParent() ;
    00461         void _setParent(OverlayContainer* parent) { mParent = parent; }
    00462
    00466         inline ushort getZOrder() const
    00467         { return mZOrder; }
    00468
    00470         Real getSquaredViewDepth(const Camera* cam) const
    00471         {
    00472             (void)cam;
    00473             return 10000.0f - (Real)getZOrder();
    00474         }
    00475
    00477         const LightList& getLights(void) const
    00478         {
    00479             // Overlayelements should not be lit by the scene, this will not get called
    00480             static LightList ll;
    00481             return ll;
    00482         }
    00483
    00484         virtual void copyFromTemplate(OverlayElement* templateOverlay);
    00485         virtual OverlayElement* clone(const String& instanceName);
    00486
    00487         // Returns the SourceTemplate for this element
    00488         const OverlayElement* getSourceTemplate () const {
    00489           return mSourceTemplate ;
    00490         }
    00491     };
    00492
    00493
    00497 }
    00498
    00499
    00500 #endif
    00501

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:22