1 / 21

GUI I I .

GUI I I . Ogre3D GUI with MyGUI. Project initialization. http://cg.iit.bme.hu/gamedev/KIC/06_GUI/ 06_02_Ogre3D_ MyGui _ Base.zip Extract Run: Ogre MyGui . sln Set include and library paths (if not correct) Set working directory (if not $( SolutionDir )/bin) Compile Run Play !!.

duncan
Télécharger la présentation

GUI I I .

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GUI II. Ogre3D GUI with MyGUI

  2. Project initialization • http://cg.iit.bme.hu/gamedev/KIC/06_GUI/ • 06_02_Ogre3D_MyGui_Base.zip • Extract • Run: OgreMyGui.sln • Set include and library paths (if not correct) • Set working directory (if not $(SolutionDir)/bin) • Compile • Run • Play!!

  3. Ghost Game with Overlays

  4. MyGUI • free, open source library • targeted at Ogre3D • relatively simple and flexible • visual tools for GUI editing • dismal documentation for coding

  5. MyGUI compilation • there is no downloadable SDK • but included in guibase.zip for you • if code had to be compiled • requires Ogre3D SDK • requires FreeType library • for Windows, install FreeType for Windows from gnuwin32.sourceforge.net • requires CMake build tool

  6. MyGUI configuration • in CMake specify Ogre and FreeType directories as dependencies • click “Generate” • open generated MyGUI.sln in Visual Studio • verify that boost version of the Ogre SDK is included (addition include dirs) • compile MyGUIEngine and OgrePlatform

  7. MyGUI includes • include directories • ..\..\..\MyGUI_3.2.0\MyGUIEngine\include • ..\..\..\MyGUI_3.2.0\Platforms\Ogre\OgrePlatform\include main.cpp #include "MyGUI.h" #include "MyGUI_OgrePlatform.h"

  8. Channeling events to the GUI class GuiInputHandler : public OIS::MouseListener , public OIS::KeyListener { public: boolmouseMoved( const OIS::MouseEvent &arg ) { return MyGUI::InputManager::getInstance().injectMouseMove( arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs); } boolmousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ){ return MyGUI::InputManager::getInstance().injectMousePress( arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); } boolmouseReleased( const OIS::MouseEvent &arg,OIS::MouseButtonID id ) { return MyGUI::InputManager::getInstance().injectMouseRelease( arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); } boolkeyPressed( const OIS::KeyEvent &arg ) { return MyGUI::InputManager::getInstance().injectKeyPress( MyGUI::KeyCode::Enum(arg.key), arg.text); } boolkeyReleased( const OIS::KeyEvent &arg ) { return MyGUI::InputManager::getInstance().injectKeyRelease( MyGUI::KeyCode::Enum(arg.key)); } };

  9. InputManager modification (inputs.h) public: OIS::Keyboard* mKeyboard; OIS::Mouse* mMouse; mKeyboard = static_cast<OIS::Keyboard*>( OISInputManager->createInputObject( OIS::OISKeyboard, true )); mMouse = static_cast<OIS::Mouse*>( OISInputManager->createInputObject( OIS::OISMouse, true ));

  10. Listener registrationin main.cpp: setupListeners GuiInputHandler* guiInputHander = new GuiInputHandler(); inputManager->mMouse-> setEventCallback(guiInputHander); inputManager->mKeyboard-> setEventCallback(guiInputHander);

  11. GUI initializationmain.cpp: setupScene platform = new MyGUI::OgrePlatform(); platform->initialise(renderWindow, sceneManager); gui = new MyGUI::Gui(); gui->initialise(); // GUI element creation may commence here

  12. Let us create a progress bar! //global MyGUI::ProgressPtrprogressBar; // in setupScene() // GUI element creation may commence here progressBar = gui->createWidget<MyGUI::ProgressBar> ("ProgressBar",100,10,500,30,MyGUI::Align::Center,"Main"); // skin^ position^ progressBar->setEnabled(true); progressBar->setProgressRange(stopTimes[numStops-1]); progressBar->setProgressPosition(0);

  13. Indicate progress in every frame! progressBar->setProgressPosition(animTime);

  14. Result

  15. Add checkbox to toggle music on/off! MyGUI::ButtonPtr button = gui->createWidget<MyGUI::Button> ("CheckBox", 10, 40, 300, 26, MyGUI::Align::Default, "Main"); button->setCaption("Music");

  16. Result

  17. GameAudio.h: new method void setMusicVolume(float musicVolume) { this->musicVolume = musicVolume; AL_SAFE_CALL( alSourcef (ambientSource, AL_GAIN, musicVolume), "unable to set ambient volume"); }

  18. Global function • void guiToggleMusic(MyGUI::Widget* _sender) { • MyGUI::ButtonPtr checkbox = • _sender->castType<MyGUI::Button>(); • if(checkbox->getStateSelected()) { • checkbox->setStateSelected(false); • gameAudio->setMusicVolume(0); • } else { • checkbox->setStateSelected(true); • gameAudio->setMusicVolume(10); • } • }

  19. Add event listener button->eventMouseButtonClick += MyGUI::newDelegate( guiToggleMusic);

  20. Result

  21. The End

More Related