首页 > 学院 > 开发设计 > 正文

Ogre SdkTrays UI c++ code override with c# (.net2.0)

2019-11-17 02:20:23
字体:
来源:转载
供稿:网友

Ogre SdkTrays UI c++ code override with c# (.net2.0)

c++ snap code

    /*     -----------------------------------------------------------------------------     This source file is part of OGRE     -----------------------------------------------------------------------------     */    #ifndef __SdkTrays_H__    #define __SdkTrays_H__    #include "Ogre.h"    #include "OgreFontManager.h"    #include "OgreBorderPanelOverlayElement.h"    #include "OgreTextAreaOverlayElement.h"    #include <math.h>    #if OGRE_COMPILER == OGRE_COMPILER_MSVC    // TODO - remove this    #   PRagma warning (disable : 4244)    #endif    namespace OgreBites    {       enum TrayLocation   // enumerator values for widget tray anchoring locations       {          TL_TOPLEFT,          TL_TOP,          TL_TOPRIGHT,          TL_LEFT,          TL_CENTER,          TL_RIGHT,          TL_BOTTOMLEFT,          TL_BOTTOM,          TL_BOTTOMRIGHT,          TL_NONE       };       enum ButtonState   // enumerator values for button states       {          BS_UP,          BS_OVER,          BS_DOWN       };       // forward widget class declarations       class Widget;       class Button;       class SelectMenu;       class Label;       class Slider;       class CheckBox;       /*=============================================================================       | Listener class for responding to tray events.       =============================================================================*/       /*=============================================================================       | Abstract base class for all widgets.       =============================================================================*/       class Widget       {       public:                       Widget()          {             mTrayLoc = TL_NONE;             mElement = 0;             mListener = 0;          }          virtual ~Widget() {}          void cleanup()          {             if (mElement) nukeOverlayElement(mElement);             mElement = 0;          }          /*-----------------------------------------------------------------------------          | Static utility method to recursively delete an overlay element plus          | all of its children from the system.          -----------------------------------------------------------------------------*/          static void nukeOverlayElement(Ogre::OverlayElement* element)          {             Ogre::OverlayContainer* container = dynamic_cast<Ogre::OverlayContainer*>(element);             if (container)             {                std::vector<Ogre::OverlayElement*> toDelete;                Ogre::OverlayContainer::ChildIterator children = container->getChildIterator();                while (children.hasMoreElements())                {                   toDelete.push_back(children.getNext());                }                for (unsigned int i = 0; i < toDelete.size(); i++)                {                   nukeOverlayElement(toDelete[i]);                }             }             if (element)             {                Ogre::OverlayContainer* parent = element->getParent();                if (parent) parent->removeChild(element->getName());                Ogre::OverlayManager::getSingleton().destroyOverlayElement(element);             }          }          /*-----------------------------------------------------------------------------          | Static utility method to check if the cursor is over an overlay element.          -----------------------------------------------------------------------------*/          static bool isCursorOver(Ogre::OverlayElement* element, const Ogre::Vector2& cursorPos, Ogre::Real voidBorder = 0)          {             Ogre::OverlayManager& om = Ogre::OverlayManager::getSingleton();                Ogre::Real l = element->_getDerivedLeft() * om.getViewportWidth();                Ogre::Real t = element->_getDerivedTop() * om.getViewportHeight();                Ogre::Real r = l + element->getWidth();                Ogre::Real b = t + element->getHeight();             return (cursorPos.x >= l + voidBorder && cursorPos.x <= r - voidBorder &&                cursorPos.y >= t + voidBorder && cursorPos.y <= b - voidBorder);          }          /*-----------------------------------------------------------------------------          | Static utility method used to get the cursor's offset from the center          | of an overlay element in pixels.          -----------------------------------------------------------------------------*/          static Ogre::Vector2 cursorOffset(Ogre::OverlayElement* element, const Ogre::Vector2& cursorPos)          {             Ogre::OverlayManager& om = Ogre::OverlayManager::getSingleton();             return Ogre::Vector2(cursorPos.x - (element->_getDerivedLeft() * om.getViewportWidth() + element->getWidth() / 2),                cursorPos.y - (element->_getDerivedTop() * om.getViewportHeight() + element->getHeight() / 2));          }                 void resourceGroupLoadStarted(const Ogre::String& groupName, size_t resourceCount)          {             mLoadInc = mGroupLoadProportion / resourceCount;             mLoadBar->setCaption("Loading...");    #if OGRE_PLATFORM != OGRE_PLATFORM_ipHONE             mWindow->update();    #endif          }          void resourceLoadStarted(const Ogre::ResourcePtr& resource)          {             mLoadBar->setComment(resource->getName());    #if OGRE_PLATFORM != OGRE_PLATFORM_IPHONE             mWindow->update();    #endif          }          void resourceLoadEnded()          {             mLoadBar->setProgress(mLoadBar->getProgress() + mLoadInc);    #if OGRE_PLATFORM != OGRE_PLATFORM_IPHONE             mWindow->update();    #endif          }          void worldGeometryStageStarted(const Ogre::String& description)          {             mLoadBar->setComment(description);    #if OGRE_PLATFORM != OGRE_PLATFORM_IPHONE             mWindow->update();    #endif          }          void worldGeometryStageEnded()          {             mLoadBar->setProgress(mLoadBar->getProgress() + mLoadInc);    #if OGRE_PLATFORM != OGRE_PLATFORM_IPHONE             mWindow->update();    #endif          }          void resourceGroupLoadEnded(const Ogre::String& groupName) {}          /*-----------------------------------------------------------------------------          | Toggles visibility of advanced statistics.          -----------------------------------------------------------------------------*/          void labelHit(Label* label)          {             if (mStatsPanel->getOverlayElement()->isVisible())             {                mStatsPanel->getOverlayElement()->hide();                mFpsLabel->getOverlayElement()->setWidth(150);                removeWidgetFromTray(mStatsPanel);             }             else             {                mStatsPanel->getOverlayElement()->show();                mFpsLabel->getOverlayElement()->setWidth(180);                moveWidgetToTray(mStatsPanel, mFpsLabel->getTrayLocation(), locateWidgetInTray(mFpsLabel) + 1);             }          }          /*-----------------------------------------------------------------------------          | Destroys dialog widgets, notifies listener, and ends high priority session.          -----------------------------------------------------------------------------*/          void buttonHit(Button* button)          {             if (mListener)             {                if (button == mOk) mListener->okDialogClosed(mDialog->getText());                else mListener->yesNoDialogClosed(mDialog->getText(), button == mYes);             }             closeDialog();          }          /*-----------------------------------------------------------------------------          | Processes mouse button down events. Returns true if the event was          | consumed and should not be passed on to other handlers.          -----------------------------------------
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表