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

# OgreGuiElement.cpp

Go to the documentation of this file.

    00001
    00002 /*
    00003 -----------------------------------------------------------------------------
    00004 This source file is part of OGRE
    00005     (Object-oriented Graphics Rendering Engine)
    00006 For the latest info, see http://www.ogre3d.org/
    00007
    00008 Copyright © 2000-2002 The OGRE Team
    00009 Also see acknowledgements in Readme.html
    00010
    00011 This program is free software you can redistribute it and/or modify it under
    00012 the terms of the GNU Lesser General Public License as published by the Free Software
    00013 Foundation either version 2 of the License, or (at your option) any later
    00014 version.
    00015
    00016 This program is distributed in the hope that it will be useful, but WITHOUT
    00017 ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS
    00018 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00019
    00020 You should have received a copy of the GNU Lesser General Public License along with
    00021 this program if not, write to the Free Software Foundation, Inc., 59 Temple
    00022 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00023 http://www.gnu.org/copyleft/lesser.txt.
    00024 -----------------------------------------------------------------------------
    00025 */
    00026 #include "OgreStableHeaders.h"
    00027
    00028 #include "OgreGuiElement.h"
    00029 #include "OgreGuiManager.h"
    00030 #include "OgreMaterialManager.h"
    00031 #include "OgreOverlay.h"
    00032 #include "OgreGuiContainer.h"
    00033 #include "OgreMouseEvent.h"
    00034 #include "OgreEventMulticaster.h"
    00035 #include "OgreEventListeners.h"
    00036 #include "OgreOverlayManager.h"
    00037 #include "OgreException.h"
    00038 #include "OgreRenderQueue.h"
    00039
    00040 namespace Ogre {
    00041
    00042
    00043     //---------------------------------------------------------------------
    00044     // Define static members
    00045     GuiElementCommands::CmdLeft GuiElement::msLeftCmd;
    00046     GuiElementCommands::CmdTop GuiElement::msTopCmd;
    00047     GuiElementCommands::CmdWidth GuiElement::msWidthCmd;
    00048     GuiElementCommands::CmdHeight GuiElement::msHeightCmd;
    00049     GuiElementCommands::CmdMaterial GuiElement::msMaterialCmd;
    00050     GuiElementCommands::CmdCaption GuiElement::msCaptionCmd;
    00051     GuiElementCommands::CmdMetricsMode GuiElement::msMetricsModeCmd;
    00052     GuiElementCommands::CmdHorizontalAlign GuiElement::msHorizontalAlignCmd;
    00053     GuiElementCommands::CmdVerticalAlign GuiElement::msVerticalAlignCmd;
    00054     GuiElementCommands::CmdVisible GuiElement::msVisibleCmd;
    00055     //---------------------------------------------------------------------
    00056     GuiElement::GuiElement(const String& name)
    00057         : MouseTarget(),
    00058           MouseMotionTarget(),
    00059           mName(name)
    00060     {
    00061         mParent = 0;
    00062         mLeft = 0.0f;
    00063         mTop = 0.0f;
    00064         mWidth = 1.0f;
    00065         mHeight = 1.0f;
    00066         mMouseListener = 0;
    00067         mVisible = true;
    00068         mpMaterial = 0;
    00069         mDerivedOutOfDate = true;
    00070         mZOrder = 0;
    00071         mCloneable = true;
    00072         mMetricsMode = GMM_RELATIVE;
    00073         mHorzAlign = GHA_LEFT;
    00074         mVertAlign = GVA_TOP;
    00075         mGeomPositionsOutOfDate = true;
    00076         mEnabled = true;
    00077         mPixelLeft = 0.0;
    00078         mPixelTop = 0.0;
    00079         mPixelWidth = 1.0;
    00080         mPixelHeight = 1.0;
    00081         mPixelScaleX = 1.0;
    00082         mPixelScaleY = 1.0;
    00083         mSourceTemplate = NULL;
    00084     }
    00085     //---------------------------------------------------------------------
    00086     GuiElement::~GuiElement()
    00087     {
    00088     }
    00089     //---------------------------------------------------------------------
    00090     const String& GuiElement::getName(void) const
    00091     {
    00092         return mName;
    00093     }
    00094     //---------------------------------------------------------------------
    00095     void GuiElement::show(void)
    00096     {
    00097         mVisible = true;
    00098     }
    00099     //---------------------------------------------------------------------
    00100     void GuiElement::hide(void)
    00101     {
    00102         mVisible = false;
    00103     }
    00104     //---------------------------------------------------------------------
    00105     bool GuiElement::isVisible(void) const
    00106     {
    00107         return mVisible;
    00108     }
    00109     //---------------------------------------------------------------------
    00110     void GuiElement::setDimensions(Real width, Real height)
    00111     {
    00112         if (mMetricsMode != GMM_RELATIVE)
    00113         {
    00114             mPixelWidth = width;
    00115             mPixelHeight = height;
    00116         }
    00117         else
    00118         {
    00119             mWidth = width;
    00120             mHeight = height;
    00121         }
    00122         mDerivedOutOfDate = true;
    00123         _positionsOutOfDate();
    00124     }
    00125     //---------------------------------------------------------------------
    00126     void GuiElement::setPosition(Real left, Real top)
    00127     {
    00128         if (mMetricsMode != GMM_RELATIVE)
    00129         {
    00130             mPixelLeft = left;
    00131             mPixelTop = top;
    00132         }
    00133         else
    00134         {
    00135             mLeft = left;
    00136             mTop = top;
    00137         }
    00138         mDerivedOutOfDate = true;
    00139         _positionsOutOfDate();
    00140
    00141     }
    00142     //---------------------------------------------------------------------
    00143     void GuiElement::setWidth(Real width)
    00144     {
    00145         if (mMetricsMode != GMM_RELATIVE)
    00146         {
    00147             mPixelWidth = width;
    00148         }
    00149         else
    00150         {
    00151             mWidth = width;
    00152         }
    00153         mDerivedOutOfDate = true;
    00154         _positionsOutOfDate();
    00155     }
    00156     //---------------------------------------------------------------------
    00157     Real GuiElement::getWidth(void) const
    00158     {
    00159         if (mMetricsMode != GMM_RELATIVE)
    00160         {
    00161             return mPixelWidth;
    00162         }
    00163         else
    00164         {
    00165             return mWidth;
    00166         }
    00167     }
    00168     //---------------------------------------------------------------------
    00169     void GuiElement::setHeight(Real height)
    00170     {
    00171         if (mMetricsMode != GMM_RELATIVE)
    00172         {
    00173             mPixelHeight = height;
    00174         }
    00175         else
    00176         {
    00177             mHeight = height;
    00178         }
    00179         mDerivedOutOfDate = true;
    00180         _positionsOutOfDate();
    00181     }
    00182     //---------------------------------------------------------------------
    00183     Real GuiElement::getHeight(void) const
    00184     {
    00185         if (mMetricsMode != GMM_RELATIVE)
    00186         {
    00187             return mPixelHeight;
    00188         }
    00189         else
    00190         {
    00191             return mHeight;
    00192         }
    00193     }
    00194     //---------------------------------------------------------------------
    00195     void GuiElement::setLeft(Real left)
    00196     {
    00197         if (mMetricsMode != GMM_RELATIVE)
    00198         {
    00199             mPixelLeft = left;
    00200         }
    00201         else
    00202         {
    00203             mLeft = left;
    00204         }
    00205         mDerivedOutOfDate = true;
    00206         _positionsOutOfDate();
    00207     }
    00208     //---------------------------------------------------------------------
    00209     Real GuiElement::getLeft(void) const
    00210     {
    00211         if (mMetricsMode != GMM_RELATIVE)
    00212         {
    00213             return mPixelLeft;
    00214         }
    00215         else
    00216         {
    00217             return mLeft;
    00218         }
    00219     }
    00220     //---------------------------------------------------------------------
    00221     void GuiElement::setTop(Real top)
    00222     {
    00223         if (mMetricsMode != GMM_RELATIVE)
    00224         {
    00225             mPixelTop = top;
    00226         }
    00227         else
    00228         {
    00229             mTop = top;
    00230         }
    00231
    00232         mDerivedOutOfDate = true;
    00233         _positionsOutOfDate();
    00234     }
    00235     //---------------------------------------------------------------------
    00236     Real GuiElement::getTop(void) const
    00237     {
    00238         if (mMetricsMode != GMM_RELATIVE)
    00239         {
    00240             return mPixelTop;
    00241         }
    00242         else
    00243         {
    00244             return mTop;
    00245         }
    00246     }
    00247     //---------------------------------------------------------------------
    00248     void GuiElement::_setLeft(Real left)
    00249     {
    00250         mLeft = left;
    00251         mPixelLeft = left / mPixelScaleX;
    00252
    00253         mDerivedOutOfDate = true;
    00254         _positionsOutOfDate();
    00255     }
    00256     //---------------------------------------------------------------------
    00257     void GuiElement::_setTop(Real top)
    00258     {
    00259         mTop = top;
    00260         mPixelTop = top / mPixelScaleY;
    00261
    00262         mDerivedOutOfDate = true;
    00263         _positionsOutOfDate();
    00264     }
    00265     //---------------------------------------------------------------------
    00266     void GuiElement::_setWidth(Real width)
    00267     {
    00268         mWidth = width;
    00269         mPixelWidth = width / mPixelScaleX;
    00270
    00271         mDerivedOutOfDate = true;
    00272         _positionsOutOfDate();
    00273     }
    00274     //---------------------------------------------------------------------
    00275     void GuiElement::_setHeight(Real height)
    00276     {
    00277         mHeight = height;
    00278         mPixelHeight = height / mPixelScaleY;
    00279
    00280         mDerivedOutOfDate = true;
    00281         _positionsOutOfDate();
    00282     }
    00283     //---------------------------------------------------------------------
    00284     void GuiElement::_setPosition(Real left, Real top)
    00285     {
    00286         mLeft = left;
    00287         mTop  = top;
    00288         mPixelLeft = left / mPixelScaleX;
    00289         mPixelTop  = top / mPixelScaleY;
    00290
    00291         mDerivedOutOfDate = true;
    00292         _positionsOutOfDate();
    00293     }
    00294     //---------------------------------------------------------------------
    00295     void GuiElement::_setDimensions(Real width, Real height)
    00296     {
    00297         mWidth  = width;
    00298         mHeight = height;
    00299         mPixelWidth  = width / mPixelScaleX;
    00300         mPixelHeight = height / mPixelScaleY;
    00301
    00302         mDerivedOutOfDate = true;
    00303         _positionsOutOfDate();
    00304     }
    00305     //---------------------------------------------------------------------
    00306     const String& GuiElement::getMaterialName(void) const
    00307     {
    00308         return mMaterialName;
    00309
    00310     }
    00311     //---------------------------------------------------------------------
    00312     void GuiElement::setMaterialName(const String& matName)
    00313     {
    00314         mMaterialName = matName;
    00315         mpMaterial = (Material*)MaterialManager::getSingleton().getByName(matName);
    00316         if (!mpMaterial)
    00317             Except( Exception::ERR_ITEM_NOT_FOUND, "Could not find material " + matName,
    00318                 "GuiElement::setMaterialName" );
    00319         mpMaterial->load();
    00320         // Set some prerequisites to be sure
    00321         mpMaterial->setLightingEnabled(false);
    00322         mpMaterial->setDepthCheckEnabled(false);
    00323
    00324     }
    00325     //---------------------------------------------------------------------
    00326     Material* GuiElement::getMaterial(void) const
    00327     {
    00328         return mpMaterial;
    00329     }
    00330     //---------------------------------------------------------------------
    00331     void GuiElement::getWorldTransforms(Matrix4* xform) const
    00332     {
    00333         mOverlay->_getWorldTransforms(xform);
    00334     }
    00335     //-----------------------------------------------------------------------
    00336     const Quaternion& GuiElement::getWorldOrientation(void) const
    00337     {
    00338         return mOverlay->getWorldOrientation();
    00339     }
    00340     //-----------------------------------------------------------------------
    00341     const Vector3& GuiElement::getWorldPosition(void) const
    00342     {
    00343         return mOverlay->getWorldPosition();
    00344     }
    00345     //---------------------------------------------------------------------
    00346     bool GuiElement::useIdentityProjection(void) const
    00347     {
    00348         return true;
    00349     }
    00350     //---------------------------------------------------------------------
    00351     bool GuiElement::useIdentityView(void) const
    00352     {
    00353         return true;
    00354     }
    00355
    00356     //---------------------------------------------------------------------
    00357     void GuiElement::_positionsOutOfDate(void)
    00358     {
    00359         mGeomPositionsOutOfDate = true;
    00360     }
    00361
    00362     //---------------------------------------------------------------------
    00363     void GuiElement::_update(void)
    00364     {
    00365         // Check size if pixel-based
    00366         switch (mMetricsMode)
    00367         {
    00368         case GMM_PIXELS :
    00369             if (OverlayManager::getSingleton().hasViewportChanged() || mGeomPositionsOutOfDate)
    00370             {
    00371                 Real vpWidth, vpHeight;
    00372                 OverlayManager& oMgr = OverlayManager::getSingleton();
    00373                 vpWidth = (Real) (oMgr.getViewportWidth());
    00374                 vpHeight = (Real) (oMgr.getViewportHeight());
    00375
    00376                 mPixelScaleX = 1.0 / vpWidth;
    00377                 mPixelScaleY = 1.0 / vpHeight;
    00378
    00379                 mLeft = mPixelLeft * mPixelScaleX;
    00380                 mTop = mPixelTop * mPixelScaleY;
    00381                 mWidth = mPixelWidth * mPixelScaleX;
    00382                 mHeight = mPixelHeight * mPixelScaleY;
    00383             }
    00384             break;
    00385
    00386         case GMM_RELATIVE_ASPECT_ADJUSTED :
    00387             if (OverlayManager::getSingleton().hasViewportChanged() || mGeomPositionsOutOfDate)
    00388             {
    00389                 Real vpWidth, vpHeight;
    00390                 OverlayManager& oMgr = OverlayManager::getSingleton();
    00391                 vpWidth = (Real) (oMgr.getViewportWidth());
    00392                 vpHeight = (Real) (oMgr.getViewportHeight());
    00393
    00394                 mPixelScaleX = 1.0 / (10000.0 * (vpWidth / vpHeight));
    00395                 mPixelScaleY = 1.0 /  10000.0;
    00396
    00397                 mLeft = mPixelLeft * mPixelScaleX;
    00398                 mTop = mPixelTop * mPixelScaleY;
    00399                 mWidth = mPixelWidth * mPixelScaleX;
    00400                 mHeight = mPixelHeight * mPixelScaleY;
    00401             }
    00402             break;
    00403         default:
    00404             break;
    00405         }
    00406
    00407         _updateFromParent();
    00408         // NB container subclasses will update children too
    00409
    00410         // Tell self to update own position geometry
    00411         if (mGeomPositionsOutOfDate)
    00412         {
    00413             updatePositionGeometry();
    00414             mGeomPositionsOutOfDate = false;
    00415         }
    00416     }
    00417     //---------------------------------------------------------------------
    00418     void GuiElement::_updateFromParent(void)
    00419     {
    00420         Real parentLeft, parentTop, parentBottom, parentRight;
    00421
    00422         if (mParent)
    00423         {
    00424             parentLeft = mParent->_getDerivedLeft();
    00425             parentTop = mParent->_getDerivedTop();
    00426             if (mHorzAlign == GHA_CENTER || mHorzAlign == GHA_RIGHT)
    00427             {
    00428                 parentRight = parentLeft + mParent->getWidth();
    00429             }
    00430             if (mVertAlign == GVA_CENTER || mVertAlign == GVA_BOTTOM)
    00431             {
    00432                 parentBottom = parentTop + mParent->getHeight();
    00433             }
    00434
    00435         }
    00436         else
    00437         {
    00438             parentLeft = parentTop = 0.0f;
    00439             parentRight = parentBottom = 1.0f;
    00440         }
    00441
    00442         // Sort out position based on alignment
    00443         // NB all we do is derived the origin, we don't automatically sort out the position
    00444         // This is more flexible than forcing absolute right & middle
    00445         switch(mHorzAlign)
    00446         {
    00447         case GHA_CENTER:
    00448             mDerivedLeft = ((parentLeft + parentRight) * 0.5f) + mLeft;
    00449             break;
    00450         case GHA_LEFT:
    00451             mDerivedLeft = parentLeft + mLeft;
    00452             break;
    00453         case GHA_RIGHT:
    00454             mDerivedLeft = parentRight + mLeft;
    00455             break;
    00456         };
    00457         switch(mVertAlign)
    00458         {
    00459         case GVA_CENTER:
    00460             mDerivedTop = ((parentTop + parentBottom) * 0.5f) + mTop;
    00461             break;
    00462         case GVA_TOP:
    00463             mDerivedTop = parentTop + mTop;
    00464             break;
    00465         case GVA_BOTTOM:
    00466             mDerivedTop = parentBottom + mTop;
    00467             break;
    00468         };
    00469
    00470         mDerivedOutOfDate = false;
    00471
    00472         if (mParent != 0)
    00473         {
    00474             Rectangle parent;
    00475             Rectangle child;
    00476
    00477             mParent->_getClippingRegion(parent);
    00478
    00479             child.left   = mDerivedLeft;
    00480             child.top    = mDerivedTop;
    00481             child.right  = mDerivedLeft + mWidth;
    00482             child.bottom = mDerivedTop + mHeight;
    00483
    00484             mClippingRegion = intersect(parent, child);
    00485         }
    00486         else
    00487         {
    00488             mClippingRegion.left   = mDerivedLeft;
    00489             mClippingRegion.top    = mDerivedTop;
    00490             mClippingRegion.right  = mDerivedLeft + mWidth;
    00491             mClippingRegion.bottom = mDerivedTop + mHeight;
    00492         }
    00493     }
    00494     //---------------------------------------------------------------------
    00495     void GuiElement::_notifyParent(GuiContainer* parent, Overlay* overlay)
    00496     {
    00497         mParent = parent;
    00498         mOverlay = overlay;
    00499
    00500         mDerivedOutOfDate = true;
    00501     }
    00502     //---------------------------------------------------------------------
    00503     Real GuiElement::_getDerivedLeft(void)
    00504     {
    00505         if (mDerivedOutOfDate)
    00506         {
    00507             _updateFromParent();
    00508         }
    00509         return mDerivedLeft;
    00510     }
    00511     //---------------------------------------------------------------------
    00512     Real GuiElement::_getDerivedTop(void)
    00513     {
    00514         if (mDerivedOutOfDate)
    00515         {
    00516             _updateFromParent();
    00517         }
    00518         return mDerivedTop;
    00519     }
    00520     //---------------------------------------------------------------------
    00521     void GuiElement::_getClippingRegion(Rectangle &clippingRegion)
    00522     {
    00523         if (mDerivedOutOfDate)
    00524         {
    00525             _updateFromParent();
    00526         }
    00527         clippingRegion = mClippingRegion;
    00528     }
    00529     //---------------------------------------------------------------------
    00530     void GuiElement::_notifyZOrder(ushort newZOrder)
    00531     {
    00532         mZOrder = newZOrder;
    00533     }
    00534
    00535     //---------------------------------------------------------------------
    00536     void GuiElement::_notifyWorldTransforms(const Matrix4& xform)
    00537     {
    00538         mXForm = xform;
    00539     }
    00540
    00541     //---------------------------------------------------------------------
    00542     void GuiElement::_notifyViewport()
    00543     {
    00544         switch (mMetricsMode)
    00545         {
    00546         case GMM_PIXELS :
    00547             {
    00548                 Real vpWidth, vpHeight;
    00549                 OverlayManager& oMgr = OverlayManager::getSingleton();
    00550                 vpWidth = (Real) (oMgr.getViewportWidth());
    00551                 vpHeight = (Real) (oMgr.getViewportHeight());
    00552
    00553                 mPixelScaleX = 1.0 / vpWidth;
    00554                 mPixelScaleY = 1.0 / vpHeight;
    00555             }
    00556             break;
    00557
    00558         case GMM_RELATIVE_ASPECT_ADJUSTED :
    00559             {
    00560                 Real vpWidth, vpHeight;
    00561                 OverlayManager& oMgr = OverlayManager::getSingleton();
    00562                 vpWidth = (Real) (oMgr.getViewportWidth());
    00563                 vpHeight = (Real) (oMgr.getViewportHeight());
    00564
    00565                 mPixelScaleX = 1.0 / (10000.0 * (vpWidth / vpHeight));
    00566                 mPixelScaleY = 1.0 /  10000.0;
    00567             }
    00568             break;
    00569
    00570         case GMM_RELATIVE :
    00571             mPixelScaleX = 1.0;
    00572             mPixelScaleY = 1.0;
    00573             mPixelLeft = mLeft;
    00574             mPixelTop = mTop;
    00575             mPixelWidth = mWidth;
    00576             mPixelHeight = mHeight;
    00577             break;
    00578         }
    00579
    00580         mLeft = mPixelLeft * mPixelScaleX;
    00581         mTop = mPixelTop * mPixelScaleY;
    00582         mWidth = mPixelWidth * mPixelScaleX;
    00583         mHeight = mPixelHeight * mPixelScaleY;
    00584
    00585         mGeomPositionsOutOfDate = true;
    00586     }
    00587
    00588     //---------------------------------------------------------------------
    00589     void GuiElement::_updateRenderQueue(RenderQueue* queue)
    00590     {
    00591         if (mVisible)
    00592         {
    00593             queue->addRenderable(this, RENDER_QUEUE_OVERLAY, mZOrder);
    00594         }
    00595
    00596     }
    00597     //-----------------------------------------------------------------------
    00598     void GuiElement::addBaseParameters(void)
    00599     {
    00600         ParamDictionary* dict = getParamDictionary();
    00601
    00602         dict->addParameter(ParameterDef("left",
    00603             "The position of the left border of the gui element."
    00604             , PT_REAL),
    00605             &msLeftCmd);
    00606         dict->addParameter(ParameterDef("top",
    00607             "The position of the top border of the gui element."
    00608             , PT_REAL),
    00609             &msTopCmd);
    00610         dict->addParameter(ParameterDef("width",
    00611             "The width of the element."
    00612             , PT_REAL),
    00613             &msWidthCmd);
    00614         dict->addParameter(ParameterDef("height",
    00615             "The height of the element."
    00616             , PT_REAL),
    00617             &msHeightCmd);
    00618         dict->addParameter(ParameterDef("material",
    00619             "The name of the material to use."
    00620             , PT_STRING),
    00621             &msMaterialCmd);
    00622         dict->addParameter(ParameterDef("caption",
    00623             "The element caption, if supported."
    00624             , PT_STRING),
    00625             &msCaptionCmd);
    00626         dict->addParameter(ParameterDef("metrics_mode",
    00627             "The type of metrics to use, either 'relative' to the screen, 'pixels' or 'relative_aspect_adjusted'."
    00628             , PT_STRING),
    00629             &msMetricsModeCmd);
    00630         dict->addParameter(ParameterDef("horz_align",
    00631             "The horizontal alignment, 'left', 'right' or 'center'."
    00632             , PT_STRING),
    00633             &msHorizontalAlignCmd);
    00634         dict->addParameter(ParameterDef("vert_align",
    00635             "The vertical alignment, 'top', 'bottom' or 'center'."
    00636             , PT_STRING),
    00637             &msVerticalAlignCmd);
    00638         dict->addParameter(ParameterDef("visible",
    00639             "Initial visibility of element, either 'true' or 'false' (default true)."
    00640             , PT_STRING),
    00641             &msVisibleCmd);
    00642     }
    00643     //-----------------------------------------------------------------------
    00644     void GuiElement::setCaption( const String& caption )
    00645     {
    00646         mCaption = caption;
    00647         _positionsOutOfDate();
    00648     }
    00649     //-----------------------------------------------------------------------
    00650     const String& GuiElement::getCaption() const
    00651     {
    00652         return mCaption;
    00653     }
    00654     //-----------------------------------------------------------------------
    00655     void GuiElement::setColour(const ColourValue& col)
    00656     {
    00657         mColour = col;
    00658     }
    00659     //-----------------------------------------------------------------------
    00660     const ColourValue& GuiElement::getColour(void) const
    00661     {
    00662         return mColour;
    00663     }
    00664     //-----------------------------------------------------------------------
    00665     void GuiElement::setMetricsMode(GuiMetricsMode gmm)
    00666     {
    00667         switch (gmm)
    00668         {
    00669         case GMM_PIXELS :
    00670             {
    00671                 Real vpWidth, vpHeight;
    00672                 OverlayManager& oMgr = OverlayManager::getSingleton();
    00673                 vpWidth = (Real) (oMgr.getViewportWidth());
    00674                 vpHeight = (Real) (oMgr.getViewportHeight());
    00675
    00676                 mPixelScaleX = 1.0 / vpWidth;
    00677                 mPixelScaleY = 1.0 / vpHeight;
    00678
    00679                 if (mMetricsMode == GMM_RELATIVE)
    00680                 {
    00681                     mPixelLeft = mLeft;
    00682                     mPixelTop = mTop;
    00683                     mPixelWidth = mWidth;
    00684                     mPixelHeight = mHeight;
    00685                 }
    00686             }
    00687             break;
    00688
    00689         case GMM_RELATIVE_ASPECT_ADJUSTED :
    00690             {
    00691                 Real vpWidth, vpHeight;
    00692                 OverlayManager& oMgr = OverlayManager::getSingleton();
    00693                 vpWidth = (Real) (oMgr.getViewportWidth());
    00694                 vpHeight = (Real) (oMgr.getViewportHeight());
    00695
    00696                 mPixelScaleX = 1.0 / (10000.0 * (vpWidth / vpHeight));
    00697                 mPixelScaleY = 1.0 /  10000.0;
    00698
    00699                 if (mMetricsMode == GMM_RELATIVE)
    00700                 {
    00701                     mPixelLeft = mLeft;
    00702                     mPixelTop = mTop;
    00703                     mPixelWidth = mWidth;
    00704                     mPixelHeight = mHeight;
    00705                 }
    00706             }
    00707             break;
    00708
    00709         case GMM_RELATIVE :
    00710             mPixelScaleX = 1.0;
    00711             mPixelScaleY = 1.0;
    00712             mPixelLeft = mLeft;
    00713             mPixelTop = mTop;
    00714             mPixelWidth = mWidth;
    00715             mPixelHeight = mHeight;
    00716             break;
    00717         }
    00718
    00719         mLeft = mPixelLeft * mPixelScaleX;
    00720         mTop = mPixelTop * mPixelScaleY;
    00721         mWidth = mPixelWidth * mPixelScaleX;
    00722         mHeight = mPixelHeight * mPixelScaleY;
    00723
    00724         mMetricsMode = gmm;
    00725         mDerivedOutOfDate = true;
    00726         _positionsOutOfDate();
    00727     }
    00728     //-----------------------------------------------------------------------
    00729     GuiMetricsMode GuiElement::getMetricsMode(void) const
    00730     {
    00731         return mMetricsMode;
    00732     }
    00733     //-----------------------------------------------------------------------
    00734     void GuiElement::setHorizontalAlignment(GuiHorizontalAlignment gha)
    00735     {
    00736         mHorzAlign = gha;
    00737         _positionsOutOfDate();
    00738     }
    00739     //-----------------------------------------------------------------------
    00740     GuiHorizontalAlignment GuiElement::getHorizontalAlignment(void) const
    00741     {
    00742         return mHorzAlign;
    00743     }
    00744     //-----------------------------------------------------------------------
    00745     void GuiElement::setVerticalAlignment(GuiVerticalAlignment gva)
    00746     {
    00747         mVertAlign = gva;
    00748         _positionsOutOfDate();
    00749     }
    00750     //-----------------------------------------------------------------------
    00751     GuiVerticalAlignment GuiElement::getVerticalAlignment(void) const
    00752     {
    00753         return mVertAlign;
    00754     }
    00755     //-----------------------------------------------------------------------
    00756
    00757
    00758     //-----------------------------------------------------------------------
    00759     bool GuiElement::contains(Real x, Real y) const
    00760     {
    00761         return mClippingRegion.inside(x, y);
    00762     }
    00763
    00764     //-----------------------------------------------------------------------
    00765     GuiElement* GuiElement::findElementAt(Real x, Real y)       // relative to parent
    00766     {
    00767         GuiElement* ret = NULL;
    00768         if (contains(x , y ))
    00769         {
    00770             ret = this;
    00771         }
    00772         return ret;
    00773     }
    00774
    00775     //-----------------------------------------------------------------------
    00776     void GuiElement::processEvent(InputEvent* e)
    00777     {
    00778
    00779         if (!mEnabled || e->isConsumed())
    00780         {
    00781             return;
    00782         }
    00783         switch(e->getID())
    00784         {
    00785         case ActionEvent::AE_ACTION_PERFORMED:
    00786             processActionEvent(static_cast<ActionEvent*>(e));
    00787             break;
    00788         case MouseEvent::ME_MOUSE_PRESSED:
    00789         case MouseEvent::ME_MOUSE_RELEASED:
    00790         case MouseEvent::ME_MOUSE_CLICKED:
    00791         case MouseEvent::ME_MOUSE_ENTERED:
    00792         case MouseEvent::ME_MOUSE_EXITED:
    00793         case MouseEvent::ME_MOUSE_DRAGENTERED:
    00794         case MouseEvent::ME_MOUSE_DRAGEXITED:
    00795         case MouseEvent::ME_MOUSE_DRAGDROPPED:
    00796             processMouseEvent(static_cast<MouseEvent*>(e));
    00797             break;
    00798         case MouseEvent::ME_MOUSE_MOVED:
    00799         case MouseEvent::ME_MOUSE_DRAGGED:
    00800         case MouseEvent::ME_MOUSE_DRAGMOVED:
    00801             processMouseMotionEvent(static_cast<MouseEvent*>(e));
    00802             break;
    00803         }
    00804     }
    00805
    00806     //-----------------------------------------------------------------------
    00807     PositionTarget* GuiElement::getPositionTargetParent() const
    00808     {
    00809         return static_cast<MouseTarget*> (mParent);     // need to choose 1 parent of the EventTarget
    00810     }
    00811     //-----------------------------------------------------------------------
    00812     GuiContainer* GuiElement::getParent()
    00813     {
    00814         return mParent;
    00815     }
    00816
    00817     void GuiElement::copyFromTemplate(GuiElement* templateGui)
    00818     {
    00819         templateGui->copyParametersTo(this);
    00820     mSourceTemplate = templateGui ;
    00821         return;
    00822     }
    00823
    00824     GuiElement* GuiElement::clone(const String& instanceName)
    00825     {
    00826         GuiElement* newElement;
    00827
    00828         newElement = GuiManager::getSingleton().createGuiElement(getTypeName(), instanceName + "/" + mName);
    00829         copyParametersTo(newElement);
    00830
    00831         return newElement;
    00832     }
    00833
    00834     //-----------------------------------------------------------------------
    00835     bool GuiElement::isEnabled() const
    00836     {
    00837         return mEnabled;
    00838     }
    00839
    00840     //-----------------------------------------------------------------------
    00841     void GuiElement::setEnabled(bool b)
    00842     {
    00843         mEnabled = b;
    00844     }
    00845
    00846
    00847 }
    00848

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