[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | You may use this sample code for anything you like, it is not covered by the
|
---|
| 11 | LGPL like the rest of the engine.
|
---|
| 12 | -----------------------------------------------------------------------------
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | /**
|
---|
| 16 | \file
|
---|
| 17 | Gui.cpp
|
---|
| 18 | \brief
|
---|
| 19 | An example of CEGUI's features
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #include <CEGUI/CEGUIImageset.h>
|
---|
| 23 | #include <CEGUI/CEGUISystem.h>
|
---|
| 24 | #include <CEGUI/CEGUILogger.h>
|
---|
| 25 | #include <CEGUI/CEGUISchemeManager.h>
|
---|
| 26 | #include <CEGUI/CEGUIWindowManager.h>
|
---|
| 27 | #include <CEGUI/CEGUIWindow.h>
|
---|
| 28 | #include <CEGUI/elements/CEGUICombobox.h>
|
---|
| 29 | #include <CEGUI/elements/CEGUIListbox.h>
|
---|
| 30 | #include <CEGUI/elements/CEGUIListboxTextItem.h>
|
---|
| 31 | #include <CEGUI/elements/CEGUIPushButton.h>
|
---|
| 32 | #include <CEGUI/elements/CEGUIScrollbar.h>
|
---|
| 33 | #include <CEGUI/elements/CEGUIStaticImage.h>
|
---|
| 34 | #include "OgreCEGUIRenderer.h"
|
---|
| 35 | #include "OgreCEGUIResourceProvider.h"
|
---|
| 36 |
|
---|
| 37 | #include "ExampleApplication.h"
|
---|
| 38 |
|
---|
| 39 | CEGUI::MouseButton convertOgreButtonToCegui(int buttonID)
|
---|
| 40 | {
|
---|
| 41 | switch (buttonID)
|
---|
| 42 | {
|
---|
| 43 | case MouseEvent::BUTTON0_MASK:
|
---|
| 44 | return CEGUI::LeftButton;
|
---|
| 45 | case MouseEvent::BUTTON1_MASK:
|
---|
| 46 | return CEGUI::RightButton;
|
---|
| 47 | case MouseEvent::BUTTON2_MASK:
|
---|
| 48 | return CEGUI::MiddleButton;
|
---|
| 49 | case MouseEvent::BUTTON3_MASK:
|
---|
| 50 | return CEGUI::X1Button;
|
---|
| 51 | default:
|
---|
| 52 | return CEGUI::LeftButton;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | class GuiFrameListener : public ExampleFrameListener, public MouseMotionListener, public MouseListener
|
---|
| 57 | {
|
---|
| 58 | private:
|
---|
| 59 | CEGUI::Renderer* mGUIRenderer;
|
---|
| 60 | bool mShutdownRequested;
|
---|
| 61 |
|
---|
| 62 | public:
|
---|
| 63 | // NB using buffered input, this is the only change
|
---|
| 64 | GuiFrameListener(RenderWindow* win, Camera* cam, CEGUI::Renderer* renderer)
|
---|
| 65 | : ExampleFrameListener(win, cam, true, true),
|
---|
| 66 | mGUIRenderer(renderer),
|
---|
| 67 | mShutdownRequested(false)
|
---|
| 68 | {
|
---|
| 69 | mEventProcessor->addMouseMotionListener(this);
|
---|
| 70 | mEventProcessor->addMouseListener(this);
|
---|
| 71 | mEventProcessor->addKeyListener(this);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | /// Tell the frame listener to exit at the end of the next frame
|
---|
| 75 | void requestShutdown(void)
|
---|
| 76 | {
|
---|
| 77 | mShutdownRequested = true;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool frameEnded(const FrameEvent& evt)
|
---|
| 81 | {
|
---|
| 82 | if (mShutdownRequested)
|
---|
| 83 | return false;
|
---|
| 84 | else
|
---|
| 85 | return ExampleFrameListener::frameEnded(evt);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | void mouseMoved (MouseEvent *e)
|
---|
| 89 | {
|
---|
| 90 | CEGUI::System::getSingleton().injectMouseMove(
|
---|
| 91 | e->getRelX() * mGUIRenderer->getWidth(),
|
---|
| 92 | e->getRelY() * mGUIRenderer->getHeight());
|
---|
| 93 | e->consume();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | void mouseDragged (MouseEvent *e)
|
---|
| 97 | {
|
---|
| 98 | mouseMoved(e);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void mousePressed (MouseEvent *e)
|
---|
| 102 | {
|
---|
| 103 | CEGUI::System::getSingleton().injectMouseButtonDown(
|
---|
| 104 | convertOgreButtonToCegui(e->getButtonID()));
|
---|
| 105 | e->consume();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | void mouseReleased (MouseEvent *e)
|
---|
| 109 | {
|
---|
| 110 | CEGUI::System::getSingleton().injectMouseButtonUp(
|
---|
| 111 | convertOgreButtonToCegui(e->getButtonID()));
|
---|
| 112 | e->consume();
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | void mouseClicked(MouseEvent* e) {}
|
---|
| 116 | void mouseEntered(MouseEvent* e) {}
|
---|
| 117 | void mouseExited(MouseEvent* e) {}
|
---|
| 118 |
|
---|
| 119 | void keyPressed(KeyEvent* e)
|
---|
| 120 | {
|
---|
| 121 | if(e->getKey() == KC_ESCAPE)
|
---|
| 122 | {
|
---|
| 123 | mShutdownRequested = true;
|
---|
| 124 | e->consume();
|
---|
| 125 | return;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | CEGUI::System::getSingleton().injectKeyDown(e->getKey());
|
---|
| 129 | CEGUI::System::getSingleton().injectChar(e->getKeyChar());
|
---|
| 130 | e->consume();
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | void keyReleased(KeyEvent* e)
|
---|
| 134 | {
|
---|
| 135 | CEGUI::System::getSingleton().injectKeyUp(e->getKey());
|
---|
| 136 | e->consume();
|
---|
| 137 | }
|
---|
| 138 | void keyClicked(KeyEvent* e)
|
---|
| 139 | {
|
---|
| 140 | // Do nothing
|
---|
| 141 | e->consume();
|
---|
| 142 | }
|
---|
| 143 | };
|
---|
| 144 |
|
---|
| 145 | class GuiApplication : public ExampleApplication
|
---|
| 146 | {
|
---|
| 147 | private:
|
---|
| 148 | CEGUI::OgreCEGUIRenderer* mGUIRenderer;
|
---|
| 149 | CEGUI::System* mGUISystem;
|
---|
| 150 | CEGUI::Window* mEditorGuiSheet;
|
---|
| 151 | CEGUI::Scrollbar* mRed;
|
---|
| 152 | CEGUI::Scrollbar* mGreen;
|
---|
| 153 | CEGUI::Scrollbar* mBlue;
|
---|
| 154 | CEGUI::StaticImage* mPreview;
|
---|
| 155 | CEGUI::Window* mTip;
|
---|
| 156 | CEGUI::Listbox* mList;
|
---|
| 157 | CEGUI::Window* mEditBox;
|
---|
| 158 | typedef std::map<CEGUI::String, CEGUI::String> DescriptionMap;
|
---|
| 159 | DescriptionMap mDescriptionMap;
|
---|
| 160 |
|
---|
| 161 | public:
|
---|
| 162 | GuiApplication()
|
---|
| 163 | : mGUIRenderer(0),
|
---|
| 164 | mGUISystem(0),
|
---|
| 165 | mEditorGuiSheet(0)
|
---|
| 166 | {
|
---|
| 167 | mDescriptionMap[(CEGUI::utf8*)"Demo8"] =
|
---|
| 168 | (CEGUI::utf8*)"The main containing panel";
|
---|
| 169 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1"] =
|
---|
| 170 | (CEGUI::utf8*)"A test window";
|
---|
| 171 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Listbox"] =
|
---|
| 172 | (CEGUI::utf8*)"A list box";
|
---|
| 173 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Controls/Red"] =
|
---|
| 174 | (CEGUI::utf8*)"A colour slider";
|
---|
| 175 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Controls/Green"] =
|
---|
| 176 | (CEGUI::utf8*)"A colour slider";
|
---|
| 177 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Controls/Blue"] =
|
---|
| 178 | (CEGUI::utf8*)"A colour slider";
|
---|
| 179 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Controls/ColourSample"] =
|
---|
| 180 | (CEGUI::utf8*)"The colour that will be used for the selection when added to the list";
|
---|
| 181 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Controls/Editbox"] =
|
---|
| 182 | (CEGUI::utf8*)"An edit box; this text will be added to the list";
|
---|
| 183 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Controls/Add"] =
|
---|
| 184 | (CEGUI::utf8*)"Adds the text to the list";
|
---|
| 185 | mDescriptionMap[(CEGUI::utf8*)"Demo8/Window1/Controls/ins1"] =
|
---|
| 186 | (CEGUI::utf8*)"Some static text";
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | ~GuiApplication()
|
---|
| 192 | {
|
---|
| 193 | if(mEditorGuiSheet)
|
---|
| 194 | {
|
---|
| 195 | CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet);
|
---|
| 196 | }
|
---|
| 197 | if(mGUISystem)
|
---|
| 198 | {
|
---|
| 199 | delete mGUISystem;
|
---|
| 200 | mGUISystem = 0;
|
---|
| 201 | }
|
---|
| 202 | if(mGUIRenderer)
|
---|
| 203 | {
|
---|
| 204 | delete mGUIRenderer;
|
---|
| 205 | mGUIRenderer = 0;
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | protected:
|
---|
| 210 | // Just override the mandatory create scene method
|
---|
| 211 | void createScene(void)
|
---|
| 212 | {
|
---|
| 213 | // Set ambient light
|
---|
| 214 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
| 215 |
|
---|
| 216 | // Create a skydome
|
---|
| 217 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
| 218 |
|
---|
| 219 | // Create a light
|
---|
| 220 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
| 221 | // Accept default settings: point light, white diffuse, just set position
|
---|
| 222 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
| 223 | // other objects, but I don't
|
---|
| 224 | l->setPosition(20,80,50);
|
---|
| 225 |
|
---|
| 226 | // setup GUI system
|
---|
| 227 | mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow,
|
---|
| 228 | Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
|
---|
| 229 |
|
---|
| 230 | mGUISystem = new CEGUI::System(mGUIRenderer);
|
---|
| 231 |
|
---|
| 232 | CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
|
---|
| 233 |
|
---|
| 234 | Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
|
---|
| 235 |
|
---|
| 236 | SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
| 237 | headNode->attachObject(ogreHead);
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | // Setup Render To Texture for preview window
|
---|
| 241 | RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "RttTex", 512, 512, TEX_TYPE_2D, PF_R8G8B8 );
|
---|
| 242 | {
|
---|
| 243 | Camera* rttCam = mSceneMgr->createCamera("RttCam");
|
---|
| 244 | SceneNode* camNode =
|
---|
| 245 | mSceneMgr->getRootSceneNode()->createChildSceneNode("rttCamNode");
|
---|
| 246 | camNode->attachObject(rttCam);
|
---|
| 247 | rttCam->setPosition(0,0,200);
|
---|
| 248 | //rttCam->setVisible(true);
|
---|
| 249 |
|
---|
| 250 | Viewport *v = rttTex->addViewport( rttCam );
|
---|
| 251 | v->setOverlaysEnabled(false);
|
---|
| 252 | v->setClearEveryFrame( true );
|
---|
| 253 | v->setBackgroundColour( ColourValue::Black );
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | // Retrieve CEGUI texture for the RTT
|
---|
| 257 | CEGUI::Texture* rttTexture = mGUIRenderer->createTexture((CEGUI::utf8*)"RttTex");
|
---|
| 258 |
|
---|
| 259 | CEGUI::Imageset* rttImageSet =
|
---|
| 260 | CEGUI::ImagesetManager::getSingleton().createImageset(
|
---|
| 261 | (CEGUI::utf8*)"RttImageset", rttTexture);
|
---|
| 262 |
|
---|
| 263 | rttImageSet->defineImage((CEGUI::utf8*)"RttImage",
|
---|
| 264 | CEGUI::Point(0.0f, 0.0f),
|
---|
| 265 | CEGUI::Size(rttTexture->getWidth(), rttTexture->getHeight()),
|
---|
| 266 | CEGUI::Point(0.0f,0.0f));
|
---|
| 267 |
|
---|
| 268 | // load scheme and set up defaults
|
---|
| 269 | CEGUI::SchemeManager::getSingleton().loadScheme(
|
---|
| 270 | (CEGUI::utf8*)"TaharezLookSkin.scheme");
|
---|
| 271 | mGUISystem->setDefaultMouseCursor(
|
---|
| 272 | (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
|
---|
| 273 | mGUISystem->setDefaultFont((CEGUI::utf8*)"Tahoma-12");
|
---|
| 274 |
|
---|
| 275 | CEGUI::Window* sheet =
|
---|
| 276 | CEGUI::WindowManager::getSingleton().loadWindowLayout(
|
---|
| 277 | (CEGUI::utf8*)"ogregui.layout");
|
---|
| 278 | mGUISystem->setGUISheet(sheet);
|
---|
| 279 |
|
---|
| 280 | CEGUI::Combobox* objectComboBox = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("OgreGuiDemo/TabCtrl/Page2/ObjectTypeList");
|
---|
| 281 |
|
---|
| 282 | CEGUI::ListboxTextItem* item = new CEGUI::ListboxTextItem((CEGUI::utf8*)"FrameWindow", 0);
|
---|
| 283 | objectComboBox->addItem(item);
|
---|
| 284 | item = new CEGUI::ListboxTextItem((CEGUI::utf8*)"Horizontal Scrollbar", 1);
|
---|
| 285 | objectComboBox->addItem(item);
|
---|
| 286 | item = new CEGUI::ListboxTextItem((CEGUI::utf8*)"Vertical Scrollbar", 2);
|
---|
| 287 | objectComboBox->addItem(item);
|
---|
| 288 | item = new CEGUI::ListboxTextItem((CEGUI::utf8*)"StaticText", 3);
|
---|
| 289 | objectComboBox->addItem(item);
|
---|
| 290 | item = new CEGUI::ListboxTextItem((CEGUI::utf8*)"StaticImage", 4);
|
---|
| 291 | objectComboBox->addItem(item);
|
---|
| 292 | item = new CEGUI::ListboxTextItem((CEGUI::utf8*)"Render to Texture", 5);
|
---|
| 293 | objectComboBox->addItem(item);
|
---|
| 294 |
|
---|
| 295 | setupEventHandlers();
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | // Create new frame listener
|
---|
| 299 | void createFrameListener(void)
|
---|
| 300 | {
|
---|
| 301 | mFrameListener= new GuiFrameListener(mWindow, mCamera, mGUIRenderer);
|
---|
| 302 | mRoot->addFrameListener(mFrameListener);
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | void setupEventHandlers(void)
|
---|
| 306 | {
|
---|
| 307 | CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
|
---|
| 308 | wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo/TabCtrl/Page1/QuitButton")
|
---|
| 309 | ->subscribeEvent(
|
---|
| 310 | CEGUI::PushButton::EventClicked,
|
---|
| 311 | CEGUI::Event::Subscriber(&GuiApplication::handleQuit, this));
|
---|
| 312 | wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo/TabCtrl/Page1/NewButton")
|
---|
| 313 | ->subscribeEvent(
|
---|
| 314 | CEGUI::PushButton::EventClicked,
|
---|
| 315 | CEGUI::Event::Subscriber(&GuiApplication::handleNew, this));
|
---|
| 316 | wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo/TabCtrl/Page1/LoadButton")
|
---|
| 317 | ->subscribeEvent(
|
---|
| 318 | CEGUI::PushButton::EventClicked,
|
---|
| 319 | CEGUI::Event::Subscriber(&GuiApplication::handleLoad, this));
|
---|
| 320 | wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo/TabCtrl/Page2/ObjectTypeList")
|
---|
| 321 | ->subscribeEvent(
|
---|
| 322 | CEGUI::Combobox::EventListSelectionAccepted,
|
---|
| 323 | CEGUI::Event::Subscriber(&GuiApplication::handleObjectSelection, this));
|
---|
| 324 |
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | void setupEnterExitEvents(CEGUI::Window* win)
|
---|
| 328 | {
|
---|
| 329 | win->subscribeEvent(
|
---|
| 330 | CEGUI::Window::EventMouseEnters,
|
---|
| 331 | CEGUI::Event::Subscriber(&GuiApplication::handleMouseEnters, this));
|
---|
| 332 | win->subscribeEvent(
|
---|
| 333 | CEGUI::Window::EventMouseLeaves,
|
---|
| 334 | CEGUI::Event::Subscriber(&GuiApplication::handleMouseLeaves, this));
|
---|
| 335 | for (unsigned int i = 0; i < win->getChildCount(); ++i)
|
---|
| 336 | {
|
---|
| 337 | CEGUI::Window* child = win->getChildAtIdx(i);
|
---|
| 338 | setupEnterExitEvents(child);
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | void setupLoadedLayoutHandlers(void)
|
---|
| 344 | {
|
---|
| 345 | CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
|
---|
| 346 | mRed = static_cast<CEGUI::Scrollbar*>(
|
---|
| 347 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window1/Controls/Red"));
|
---|
| 348 | mGreen = static_cast<CEGUI::Scrollbar*>(
|
---|
| 349 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window1/Controls/Green"));
|
---|
| 350 | mBlue = static_cast<CEGUI::Scrollbar*>(
|
---|
| 351 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window1/Controls/Blue"));
|
---|
| 352 | mPreview = static_cast<CEGUI::StaticImage*>(
|
---|
| 353 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window1/Controls/ColourSample"));
|
---|
| 354 | mList = static_cast<CEGUI::Listbox*>(
|
---|
| 355 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window1/Listbox"));
|
---|
| 356 | mEditBox =
|
---|
| 357 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window1/Controls/Editbox");
|
---|
| 358 | mTip =
|
---|
| 359 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window2/Tips");
|
---|
| 360 |
|
---|
| 361 | mRed->subscribeEvent(
|
---|
| 362 | CEGUI::Scrollbar::EventScrollPositionChanged,
|
---|
| 363 | CEGUI::Event::Subscriber(&GuiApplication::handleColourChanged, this));
|
---|
| 364 | mGreen->subscribeEvent(
|
---|
| 365 | CEGUI::Scrollbar::EventScrollPositionChanged,
|
---|
| 366 | CEGUI::Event::Subscriber(&GuiApplication::handleColourChanged, this));
|
---|
| 367 | mBlue->subscribeEvent(
|
---|
| 368 | CEGUI::Scrollbar::EventScrollPositionChanged,
|
---|
| 369 | CEGUI::Event::Subscriber(&GuiApplication::handleColourChanged, this));
|
---|
| 370 |
|
---|
| 371 | wmgr.getWindow((CEGUI::utf8*)"Demo8/Window1/Controls/Add")
|
---|
| 372 | ->subscribeEvent(
|
---|
| 373 | CEGUI::PushButton::EventClicked,
|
---|
| 374 | CEGUI::Event::Subscriber(&GuiApplication::handleAdd, this));
|
---|
| 375 |
|
---|
| 376 | CEGUI::Window* root = wmgr.getWindow("Demo8");
|
---|
| 377 | setupEnterExitEvents(root);
|
---|
| 378 |
|
---|
| 379 |
|
---|
| 380 |
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | CEGUI::Window* createRttGuiObject(void)
|
---|
| 384 | {
|
---|
| 385 | static unsigned int rttCounter = 0;
|
---|
| 386 | String guiObjectName = "NewRttImage" + StringConverter::toString(rttCounter);
|
---|
| 387 |
|
---|
| 388 | CEGUI::Imageset* rttImageSet =
|
---|
| 389 | CEGUI::ImagesetManager::getSingleton().getImageset(
|
---|
| 390 | (CEGUI::utf8*)"RttImageset");
|
---|
| 391 | CEGUI::StaticImage* si = (CEGUI::StaticImage*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/StaticImage", (CEGUI::utf8*)guiObjectName.c_str());
|
---|
| 392 | si->setSize(CEGUI::Size(0.5f, 0.4f));
|
---|
| 393 | si->setImage(&rttImageSet->getImage((CEGUI::utf8*)"RttImage"));
|
---|
| 394 |
|
---|
| 395 | rttCounter++;
|
---|
| 396 |
|
---|
| 397 | return si;
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | CEGUI::Window* createStaticImageObject(void)
|
---|
| 401 | {
|
---|
| 402 | static unsigned int siCounter = 0;
|
---|
| 403 | String guiObjectName = "NewStaticImage" + StringConverter::toString(siCounter);
|
---|
| 404 |
|
---|
| 405 | CEGUI::Imageset* imageSet =
|
---|
| 406 | CEGUI::ImagesetManager::getSingleton().getImageset(
|
---|
| 407 | (CEGUI::utf8*)"TaharezLook");
|
---|
| 408 |
|
---|
| 409 | CEGUI::StaticImage* si = (CEGUI::StaticImage*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/StaticImage", (CEGUI::utf8*)guiObjectName.c_str());
|
---|
| 410 | si->setSize(CEGUI::Size(0.2f, 0.2f));
|
---|
| 411 | si->setImage(&imageSet->getImage((CEGUI::utf8*)"ClientBrush"));
|
---|
| 412 |
|
---|
| 413 | siCounter++;
|
---|
| 414 |
|
---|
| 415 | return si;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | bool handleQuit(const CEGUI::EventArgs& e)
|
---|
| 419 | {
|
---|
| 420 | static_cast<GuiFrameListener*>(mFrameListener)->requestShutdown();
|
---|
| 421 | return true;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | bool handleNew(const CEGUI::EventArgs& e)
|
---|
| 425 | {
|
---|
| 426 | if(mEditorGuiSheet)
|
---|
| 427 | CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet);
|
---|
| 428 |
|
---|
| 429 | mEditorGuiSheet = CEGUI::WindowManager::getSingleton().createWindow("DefaultGUISheet", "NewLayout");
|
---|
| 430 |
|
---|
| 431 | CEGUI::Window* editorWindow = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"OgreGuiDemo2/MainWindow");
|
---|
| 432 | editorWindow->addChildWindow(mEditorGuiSheet);
|
---|
| 433 |
|
---|
| 434 | return true;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | bool handleLoad(const CEGUI::EventArgs& e)
|
---|
| 438 | {
|
---|
| 439 | if(mEditorGuiSheet)
|
---|
| 440 | CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet);
|
---|
| 441 |
|
---|
| 442 | mEditorGuiSheet =
|
---|
| 443 | CEGUI::WindowManager::getSingleton().loadWindowLayout(
|
---|
| 444 | (CEGUI::utf8*)"cegui8.layout");
|
---|
| 445 | setupLoadedLayoutHandlers();
|
---|
| 446 |
|
---|
| 447 | CEGUI::Window* editorWindow = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"OgreGuiDemo2/MainWindow");
|
---|
| 448 | editorWindow->addChildWindow(mEditorGuiSheet);
|
---|
| 449 |
|
---|
| 450 | return true;
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 |
|
---|
| 454 | bool handleObjectSelection(const CEGUI::EventArgs& e)
|
---|
| 455 | {
|
---|
| 456 | static unsigned int windowNumber = 0;
|
---|
| 457 | static unsigned int vertScrollNumber = 0;
|
---|
| 458 | static unsigned int horizScrollNumber = 0;
|
---|
| 459 | static unsigned int textScrollNumber = 0;
|
---|
| 460 | String guiObjectName;
|
---|
| 461 | CEGUI::Window* window = 0;
|
---|
| 462 |
|
---|
| 463 | // Set a random position to place this object.
|
---|
| 464 | Real posX = Math::RangeRandom(0.0, 0.7);
|
---|
| 465 | Real posY = Math::RangeRandom(0.1, 0.7);
|
---|
| 466 |
|
---|
| 467 | const CEGUI::WindowEventArgs& windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
|
---|
| 468 | CEGUI::ListboxItem* item = static_cast<CEGUI::Combobox*>(windowEventArgs.window)->getSelectedItem();
|
---|
| 469 |
|
---|
| 470 | CEGUI::Window* editorWindow = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"OgreGuiDemo2/MainWindow");
|
---|
| 471 |
|
---|
| 472 | switch(item->getID())
|
---|
| 473 | {
|
---|
| 474 | case 0:
|
---|
| 475 | guiObjectName = "NewWindow" + StringConverter::toString(windowNumber);
|
---|
| 476 | window = CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/FrameWindow", (CEGUI::utf8*)guiObjectName.c_str());
|
---|
| 477 | window->setSize(CEGUI::Size(0.3f, 0.3f));
|
---|
| 478 | window->setText((CEGUI::utf8*)"New Window");
|
---|
| 479 | windowNumber++;
|
---|
| 480 | break;
|
---|
| 481 | case 1:
|
---|
| 482 | guiObjectName = "NewHorizScroll" + StringConverter::toString(horizScrollNumber);
|
---|
| 483 | window = CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/HorizontalScrollbar", (CEGUI::utf8*)guiObjectName.c_str());
|
---|
| 484 | window->setSize(CEGUI::Size(0.75f, 0.03f));
|
---|
| 485 | horizScrollNumber++;
|
---|
| 486 | break;
|
---|
| 487 | case 2:
|
---|
| 488 | guiObjectName = "NewVertScroll" + StringConverter::toString(vertScrollNumber);
|
---|
| 489 | window = CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/VerticalScrollbar", (CEGUI::utf8*)guiObjectName.c_str());
|
---|
| 490 | window->setSize(CEGUI::Size(0.03f, 0.75f));
|
---|
| 491 | vertScrollNumber++;
|
---|
| 492 | break;
|
---|
| 493 | case 3:
|
---|
| 494 | guiObjectName = "NewStaticText" + StringConverter::toString(textScrollNumber);
|
---|
| 495 | window = CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/StaticText", (CEGUI::utf8*)guiObjectName.c_str());
|
---|
| 496 | window->setSize(CEGUI::Size(0.25f, 0.1f));
|
---|
| 497 | window->setText((CEGUI::utf8*)"Example static text");
|
---|
| 498 | textScrollNumber++;
|
---|
| 499 | break;
|
---|
| 500 | case 4:
|
---|
| 501 | window = createStaticImageObject();
|
---|
| 502 | break;
|
---|
| 503 | case 5:
|
---|
| 504 | window = createRttGuiObject();
|
---|
| 505 | break;
|
---|
| 506 | };
|
---|
| 507 |
|
---|
| 508 | editorWindow->addChildWindow(window);
|
---|
| 509 | window->setPosition(CEGUI::Point(posX, posY));
|
---|
| 510 |
|
---|
| 511 | return true;
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | bool handleColourChanged(const CEGUI::EventArgs& e)
|
---|
| 515 | {
|
---|
| 516 | mPreview->setImageColours(CEGUI::colour(
|
---|
| 517 | mRed->getScrollPosition() / 255.0f,
|
---|
| 518 | mGreen->getScrollPosition() / 255.0f,
|
---|
| 519 | mBlue->getScrollPosition() / 255.0f));
|
---|
| 520 |
|
---|
| 521 | return true;
|
---|
| 522 |
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | bool handleAdd(const CEGUI::EventArgs& e)
|
---|
| 526 | {
|
---|
| 527 | CEGUI::ListboxTextItem *listboxitem =
|
---|
| 528 | new CEGUI::ListboxTextItem (mEditBox->getText());
|
---|
| 529 | listboxitem->setSelectionBrushImage("TaharezLook", "ListboxSelectionBrush");
|
---|
| 530 | listboxitem->setSelected(mList->getItemCount() == 0);
|
---|
| 531 | listboxitem->setSelectionColours(mPreview->getImageColours());
|
---|
| 532 | mList->addItem(listboxitem);
|
---|
| 533 | return true;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | bool handleMouseEnters(const CEGUI::EventArgs& e)
|
---|
| 537 | {
|
---|
| 538 | CEGUI::WindowEventArgs& we = ((CEGUI::WindowEventArgs&)e);
|
---|
| 539 | DescriptionMap::iterator i =
|
---|
| 540 | mDescriptionMap.find(we.window->getName());
|
---|
| 541 | if (i != mDescriptionMap.end())
|
---|
| 542 | {
|
---|
| 543 | mTip->setText(i->second);
|
---|
| 544 | }
|
---|
| 545 | else
|
---|
| 546 | {
|
---|
| 547 | mTip->setText((CEGUI::utf8*)"");
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | return true;
|
---|
| 551 | }
|
---|
| 552 | bool handleMouseLeaves(const CEGUI::EventArgs& e)
|
---|
| 553 | {
|
---|
| 554 | mTip->setText((CEGUI::utf8*)"");
|
---|
| 555 | return true;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | };
|
---|
| 559 |
|
---|
| 560 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 561 | #define WIN32_LEAN_AND_MEAN
|
---|
| 562 | #include "windows.h"
|
---|
| 563 |
|
---|
| 564 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
|
---|
| 565 | #else
|
---|
| 566 | int main(int argc, char *argv[])
|
---|
| 567 | #endif
|
---|
| 568 | {
|
---|
| 569 |
|
---|
| 570 | // Create application object
|
---|
| 571 | GuiApplication app;
|
---|
| 572 |
|
---|
| 573 | try {
|
---|
| 574 | app.go();
|
---|
| 575 | } catch( Ogre::Exception& e ) {
|
---|
| 576 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 577 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
---|
| 578 | #else
|
---|
| 579 | std::cerr << "An exception has occured: " <<
|
---|
| 580 | e.getFullDescription().c_str() << std::endl;
|
---|
| 581 | #endif
|
---|
| 582 | }
|
---|
| 583 |
|
---|
| 584 |
|
---|
| 585 | return 0;
|
---|
| 586 | }
|
---|
| 587 |
|
---|