Download - GUI I I
![Page 1: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/1.jpg)
GUI II.Ogre3D GUI with MyGUI
![Page 2: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/2.jpg)
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 !!
![Page 3: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/3.jpg)
Ghost Game with Overlays
![Page 4: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/4.jpg)
MyGUI• free, open source library• targeted at Ogre3D• relatively simple and flexible• visual tools for GUI editing• dismal documentation for coding
2012. 11. 8.
![Page 5: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/5.jpg)
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
2012. 11. 8.
![Page 6: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/6.jpg)
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 OgrePlatform2012. 11. 8.
![Page 7: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/7.jpg)
MyGUI includes• include directories– ..\..\..\MyGUI_3.2.0\MyGUIEngine\include– ..\..\..\MyGUI_3.2.0\Platforms\Ogre\
OgrePlatform\include
2012. 11. 8.
main.cpp
#include "MyGUI.h"#include "MyGUI_OgrePlatform.h"
![Page 8: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/8.jpg)
Channeling events to the GUI
2012. 11. 8.
class GuiInputHandler : public OIS::MouseListener , public OIS::KeyListener { public:bool mouseMoved( const OIS::MouseEvent &arg ) {return MyGUI::InputManager::getInstance().injectMouseMove(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs); }bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ){return MyGUI::InputManager::getInstance().injectMousePress( arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); }bool mouseReleased( const OIS::MouseEvent &arg,OIS::MouseButtonID id ) {return MyGUI::InputManager::getInstance().injectMouseRelease( arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); }bool keyPressed( const OIS::KeyEvent &arg ) {return MyGUI::InputManager::getInstance().injectKeyPress( MyGUI::KeyCode::Enum(arg.key), arg.text); }bool keyReleased( const OIS::KeyEvent &arg ) {return MyGUI::InputManager::getInstance().injectKeyRelease( MyGUI::KeyCode::Enum(arg.key)); } };
![Page 9: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/9.jpg)
InputManager modification (inputs.h)
2012. 11. 8.
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 ));
![Page 10: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/10.jpg)
Listener registrationin main.cpp: setupListeners
2012. 11. 8.
GuiInputHandler* guiInputHander = new GuiInputHandler();inputManager->mMouse->
setEventCallback(guiInputHander);inputManager->mKeyboard->
setEventCallback(guiInputHander);
![Page 11: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/11.jpg)
GUI initializationmain.cpp: setupScene
2012. 11. 8.
platform = new MyGUI::OgrePlatform();platform->initialise(renderWindow, sceneManager); gui = new MyGUI::Gui();gui->initialise();
// GUI element creation may commence here
![Page 12: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/12.jpg)
Let us create a progress bar!
2012. 11. 8.
//globalMyGUI::ProgressPtr progressBar;
// in setupScene()// GUI element creation may commence hereprogressBar = 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);
![Page 13: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/13.jpg)
Indicate progress in every frame!
2012. 11. 8.
progressBar->setProgressPosition(animTime);
![Page 14: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/14.jpg)
Result
2012. 11. 8.
![Page 15: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/15.jpg)
Add checkbox to toggle music on/off!
2012. 11. 8.
MyGUI::ButtonPtr button = gui->createWidget<MyGUI::Button> ("CheckBox", 10, 40, 300, 26, MyGUI::Align::Default, "Main");
button->setCaption("Music");
![Page 16: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/16.jpg)
Result
2012. 11. 8.
![Page 17: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/17.jpg)
GameAudio.h: new method
2012. 11. 8.
void setMusicVolume(float musicVolume) {this->musicVolume = musicVolume;AL_SAFE_CALL(
alSourcef (ambientSource, AL_GAIN, musicVolume),
"unable to set ambient volume");}
![Page 18: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/18.jpg)
Global function
2012. 11. 8.
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);}
}
![Page 19: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/19.jpg)
Add event listener
2012. 11. 8.
button->eventMouseButtonClick +=MyGUI::newDelegate(
guiToggleMusic);
![Page 20: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/20.jpg)
Result
2012. 11. 8.
![Page 21: GUI I I](https://reader035.vdocument.in/reader035/viewer/2022062520/568163f3550346895dd57995/html5/thumbnails/21.jpg)
The End
2012. 11. 8.