00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 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 "OgreMouseTarget.h" 00036 #include "OgreMouseMotionTarget.h" 00037 00038 namespace Ogre { 00039 00040 00043 enum GuiMetricsMode 00044 { 00046 GMM_RELATIVE, 00048 GMM_PIXELS 00049 }; 00050 00054 enum GuiHorizontalAlignment 00055 { 00056 GHA_LEFT, 00057 GHA_CENTER, 00058 GHA_RIGHT 00059 }; 00063 enum GuiVerticalAlignment 00064 { 00065 GVA_TOP, 00066 GVA_CENTER, 00067 GVA_BOTTOM 00068 }; 00069 00070 00092 class _OgreExport GuiElement : public StringInterface, public Renderable, public MouseTarget, public MouseMotionTarget 00093 { 00094 public: 00095 00096 protected: 00097 // Command object for setting / getting parameters 00098 static GuiElementCommands::CmdLeft msLeftCmd; 00099 static GuiElementCommands::CmdTop msTopCmd; 00100 static GuiElementCommands::CmdWidth msWidthCmd; 00101 static GuiElementCommands::CmdHeight msHeightCmd; 00102 static GuiElementCommands::CmdMaterial msMaterialCmd; 00103 static GuiElementCommands::CmdCaption msCaptionCmd; 00104 static GuiElementCommands::CmdMetricsMode msMetricsModeCmd; 00105 static GuiElementCommands::CmdHorizontalAlign msHorizontalAlignCmd; 00106 static GuiElementCommands::CmdVerticalAlign msVerticalAlignCmd; 00107 00108 00109 String mName; 00110 bool mVisible; 00111 bool mCloneable; 00112 Real mLeft; 00113 Real mTop; 00114 Real mWidth; 00115 Real mHeight; 00116 String mMaterialName; 00117 Material* mpMaterial; 00118 String mCaption; 00119 00120 GuiMetricsMode mMetricsMode; 00121 GuiHorizontalAlignment mHorzAlign; 00122 GuiVerticalAlignment mVertAlign; 00123 00124 // Pixel-mode positions, used in GMM_PIXELS mode. 00125 short mPixelTop; 00126 short mPixelLeft; 00127 short mPixelWidth; 00128 short mPixelHeight; 00129 00130 // Parent pointer 00131 GuiContainer* mParent; 00132 // Overlay attached to 00133 Overlay* mOverlay; 00134 00135 // Derived positions from parent 00136 Real mDerivedLeft; 00137 Real mDerivedTop; 00138 bool mDerivedOutOfDate; 00139 00141 bool mGeomPositionsOutOfDate; 00142 00143 // Zorder for when sending to render queue 00144 // Derived from parent 00145 ushort mZOrder; 00146 00151 virtual void updatePositionGeometry(void) = 0; 00152 00161 virtual void addBaseParameters(void); 00162 00163 public: 00165 GuiElement(const String& name); 00166 virtual ~GuiElement(); 00167 00169 const String& getName(void) const; 00170 00171 00173 void show(void); 00174 00176 void hide(void); 00177 00179 bool isVisible(void); 00180 00181 00183 void setDimensions(Real width, Real height); 00184 00187 void setPosition(Real left, Real top); 00188 00190 void setWidth(Real width); 00192 Real getWidth(void) const; 00193 00195 void setHeight(Real height); 00197 Real getHeight(void) const; 00198 00200 void setLeft(Real left); 00202 Real getLeft(void) const; 00203 00205 void setTop(Real Top); 00207 Real getTop(void) const; 00208 00209 00211 virtual const String& getMaterialName(void) const; 00212 00223 virtual void setMaterialName(const String& matName); 00224 00225 00226 // --- Renderable Overrides --- 00228 Material* getMaterial(void) const; 00229 00230 // NB getRenderOperation not implemented, still abstract here 00231 00233 void getWorldTransforms(Matrix4* xform); 00234 00236 bool useIdentityProjection(void); 00237 00239 bool useIdentityView(void); 00240 00242 virtual void _update(void); 00243 00245 virtual void _updateFromParent(void); 00246 00248 virtual void _notifyParent(GuiContainer* parent, Overlay* overlay); 00249 00251 virtual Real _getDerivedLeft(void); 00252 00254 virtual Real _getDerivedTop(void); 00255 00265 virtual void _notifyZOrder(ushort newZOrder); 00266 00268 virtual void _updateRenderQueue(RenderQueue* queue); 00269 00271 virtual const String& getTypeName(void) = 0; 00272 00279 virtual void setCaption(const String& text); 00280 00282 virtual const String& getCaption(void) const; 00283 00294 virtual void setMetricsMode(GuiMetricsMode gmm); 00296 virtual GuiMetricsMode getMetricsMode(void); 00312 virtual void setHorizontalAlignment(GuiHorizontalAlignment gha); 00314 virtual GuiHorizontalAlignment getHorizontalAlignment(void); 00330 virtual void setVerticalAlignment(GuiVerticalAlignment gva); 00332 virtual GuiVerticalAlignment getVerticalAlignment(void); 00333 00334 00335 00336 00338 virtual bool contains(Real x, Real y) const; 00339 00341 virtual GuiElement* findElementAt(Real x, Real y); // relative to parent 00342 00347 virtual void processEvent(InputEvent* e); 00348 00352 inline virtual bool isContainer() 00353 { return false; } 00354 00355 inline virtual bool isCloneable() 00356 { return mCloneable; } 00357 00358 inline virtual void setCloneable(bool c) 00359 { mCloneable = c; } 00360 00364 PositionTarget* getPositionTargetParent() ; 00365 00369 GuiContainer* getParent() ; 00370 00374 inline ushort getZOrder() const 00375 { return mZOrder; } 00376 00378 Real getSquaredViewDepth(const Camera* cam) const 00379 { 00380 return 10000 - getZOrder(); 00381 } 00382 00383 00384 void copyFromTemplate(GuiElement* templateGui); 00385 00386 }; 00387 00388 00389 00390 } 00391 00392 00393 #endif 00394
Copyright © 2002 by The OGRE Team