Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreGuiElement.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 © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 
00026 #ifndef __GuiElement_H__
00027 #define __GuiElement_H__
00028 
00029 #include "OgrePrerequisites.h"
00030 #include "OgreString.h"
00031 #include "OgreRenderable.h"
00032 #include "OgreStringInterface.h"
00033 #include "OgreGuiElementCommands.h"
00034 
00035 #include "OgreActionTarget.h"
00036 #include "OgreMouseTarget.h"
00037 #include "OgreMouseMotionTarget.h"
00038 #include "OgreColourValue.h"
00039 #include "OgreRectangle.h"
00040 
00041 namespace Ogre {
00042 
00043 
00046     enum GuiMetricsMode
00047     {
00049         GMM_RELATIVE,
00051         GMM_PIXELS,
00053         GMM_RELATIVE_ASPECT_ADJUSTED
00054     };
00055 
00059     enum GuiHorizontalAlignment
00060     {
00061         GHA_LEFT,
00062         GHA_CENTER,
00063         GHA_RIGHT
00064     };
00068     enum GuiVerticalAlignment
00069     {
00070         GVA_TOP,
00071         GVA_CENTER,
00072         GVA_BOTTOM
00073     };
00074 
00096     class _OgreExport GuiElement : public StringInterface, public Renderable, public MouseTarget, public MouseMotionTarget, public ActionTarget
00097     {
00098     public:
00099 
00100     protected:
00101         // Command object for setting / getting parameters
00102         static GuiElementCommands::CmdLeft msLeftCmd;
00103         static GuiElementCommands::CmdTop msTopCmd;
00104         static GuiElementCommands::CmdWidth msWidthCmd;
00105         static GuiElementCommands::CmdHeight msHeightCmd;
00106         static GuiElementCommands::CmdMaterial msMaterialCmd;
00107         static GuiElementCommands::CmdCaption msCaptionCmd;
00108         static GuiElementCommands::CmdMetricsMode msMetricsModeCmd;
00109         static GuiElementCommands::CmdHorizontalAlign msHorizontalAlignCmd;
00110         static GuiElementCommands::CmdVerticalAlign msVerticalAlignCmd;
00111         static GuiElementCommands::CmdVisible msVisibleCmd;
00112 
00113 
00114         String mName;
00115         bool mVisible;
00116         bool mCloneable;
00117         Real mLeft;
00118         Real mTop;
00119         Real mWidth;
00120         Real mHeight;
00121         String mMaterialName;
00122         Material* mpMaterial;
00123         String mCaption;
00124         ColourValue mColour;
00125         Rectangle mClippingRegion;
00126 
00127         GuiMetricsMode mMetricsMode;
00128         GuiHorizontalAlignment mHorzAlign;
00129         GuiVerticalAlignment mVertAlign;
00130 
00131         // metric-mode positions, used in GMM_PIXELS & GMM_RELATIVE_ASPECT_ADJUSTED mode.
00132         Real mPixelTop;
00133         Real mPixelLeft;
00134         Real mPixelWidth;
00135         Real mPixelHeight;
00136         Real mPixelScaleX;
00137         Real mPixelScaleY;
00138 
00139         // Parent pointer
00140         GuiContainer* mParent;
00141         // Overlay attached to
00142         Overlay* mOverlay;
00143 
00144         // Derived positions from parent
00145         Real mDerivedLeft;
00146         Real mDerivedTop;
00147         bool mDerivedOutOfDate;
00148 
00150         bool mGeomPositionsOutOfDate;
00151 
00152         // Zorder for when sending to render queue
00153         // Derived from parent
00154         ushort mZOrder;
00155 
00156         // world transforms
00157         Matrix4 mXForm;
00158 
00159         // is element enabled
00160         bool mEnabled;
00161 
00162         // Used to see if this element is created from a Template
00163         GuiElement* mSourceTemplate ;
00164 
00169         virtual void updatePositionGeometry(void) = 0;
00170 
00179         virtual void addBaseParameters(void);
00180 
00181     public:
00183         GuiElement(const String& name);
00184         virtual ~GuiElement();
00185 
00187         virtual void initialise(void) = 0;
00188 
00190         const String& getName(void) const;
00191 
00192 
00194         virtual void show(void);
00195 
00197         virtual void hide(void);
00198 
00200         bool isVisible(void) const;
00201 
00202         bool isEnabled() const;
00203         virtual void setEnabled(bool b);
00204 
00205 
00207         void setDimensions(Real width, Real height);
00208 
00211         void setPosition(Real left, Real top);
00212 
00214         void setWidth(Real width);
00216         Real getWidth(void) const;
00217 
00219         void setHeight(Real height);
00221         Real getHeight(void) const;
00222 
00224         void setLeft(Real left);
00226         Real getLeft(void) const;
00227 
00229         void setTop(Real Top);
00231         Real getTop(void) const;
00232 
00234         Real _getLeft(void) const { return mLeft; }
00236         Real _getTop(void) const { return mTop; }
00238         Real _getWidth(void) const { return mWidth; }
00240         Real _getHeight(void) const { return mHeight; }
00242         void _setLeft(Real left);
00244         void _setTop(Real top);
00246         void _setWidth(Real width);
00248         void _setHeight(Real height);
00250         void _setPosition(Real left, Real top);
00252         void _setDimensions(Real width, Real height);
00253 
00255         virtual const String& getMaterialName(void) const;
00256 
00267         virtual void setMaterialName(const String& matName);
00268 
00269 
00270         // --- Renderable Overrides ---
00272         Material* getMaterial(void) const;
00273 
00274         // NB getRenderOperation not implemented, still abstract here
00275 
00277         void getWorldTransforms(Matrix4* xform) const;
00279         const Quaternion& getWorldOrientation(void) const;
00281         const Vector3& getWorldPosition(void) const;
00282 
00284         bool useIdentityProjection(void) const;
00285 
00287         bool useIdentityView(void) const;
00288 
00290         virtual void _positionsOutOfDate(void);
00291 
00293         virtual void _update(void);
00294 
00296         virtual void _updateFromParent(void);
00297 
00299         virtual void _notifyParent(GuiContainer* parent, Overlay* overlay);
00300 
00302         virtual Real _getDerivedLeft(void);
00303 
00305         virtual Real _getDerivedTop(void);
00306 
00308         virtual void _getClippingRegion(Rectangle &clippingRegion);
00309 
00319         virtual void _notifyZOrder(ushort newZOrder);
00320 
00324         virtual void _notifyWorldTransforms(const Matrix4& xform);
00325 
00329         virtual void _notifyViewport();
00330 
00332         virtual void _updateRenderQueue(RenderQueue* queue);
00333 
00335         virtual const String& getTypeName(void) const = 0;
00336 
00343         virtual void setCaption(const String& text);
00344 
00346         virtual const String& getCaption(void) const;
00347 
00354         virtual void setColour(const ColourValue& col);
00355 
00357         virtual const ColourValue& getColour(void) const;
00358 
00369         virtual void setMetricsMode(GuiMetricsMode gmm);
00371         virtual GuiMetricsMode getMetricsMode(void) const;
00387         virtual void setHorizontalAlignment(GuiHorizontalAlignment gha);
00389         virtual GuiHorizontalAlignment getHorizontalAlignment(void) const;
00405         virtual void setVerticalAlignment(GuiVerticalAlignment gva);
00407         virtual GuiVerticalAlignment getVerticalAlignment(void) const;
00408 
00409 
00410 
00411 
00413         virtual bool contains(Real x, Real y) const;
00414 
00416         virtual GuiElement* findElementAt(Real x, Real y);      // relative to parent
00417 
00422         virtual void processEvent(InputEvent* e);
00423 
00427         inline virtual bool isContainer() const
00428         { return false; }
00429 
00430         inline virtual bool isKeyEnabled() const
00431         { return false; }
00432 
00433         inline virtual bool isCloneable() const
00434         { return mCloneable; }
00435 
00436         inline virtual void setCloneable(bool c)
00437         { mCloneable = c; }
00438 
00442         PositionTarget* getPositionTargetParent() const;
00443 
00447         GuiContainer* getParent() ;
00448         void _setParent(GuiContainer* parent) { mParent = parent; }
00449 
00453         inline ushort getZOrder() const
00454         { return mZOrder; }
00455 
00457         Real getSquaredViewDepth(const Camera* cam) const 
00458         { 
00459             return 10000 - getZOrder(); 
00460         }
00461 
00463         const LightList& getLights(void) const
00464         {
00465             // Guielements should not be lit by the scene, this will not get called
00466             static LightList ll;
00467             return ll;
00468         }
00469 
00470         void copyFromTemplate(GuiElement* templateGui);
00471         virtual GuiElement* clone(const String& instanceName);
00472 
00473         // Returns the SourceTemplate for this element
00474         const GuiElement* getSourceTemplate () const {
00475           return mSourceTemplate ;
00476         }
00477     };
00478 
00479 
00480 
00481 }
00482 
00483 
00484 #endif
00485 

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:28 2004