History: MyGUI quickstart
Preview of version: 6
This is quickstart for MyGUI 3.0. If you want to use earlier version of MyGUI use this page.
Copy MyGUI_Media folder from downloaded package (or from svn) and add the path to it in your resources.cfg.
Compile MyGUI and put MyGUIEngine(_d).dll near the executable file and add MyGUIEngine(_d).lib to additional dependencies.
You will also need to compile MyGUI.OgrePlatform as an interface for the MyGui library to the Ogre rendering engine and add MyGUI.OgrePlatform(_d).lib to additional dependencies.
Code
includes:
You need to have additional include folder for this - path_to_MyGUI/MyGUIEngine/include and path_to_MyGUI/Platforms/Ogre/OgrePlatform/include and add to your code next includes:
#include "MyGUI.h" #include "MyGUI_OgrePlatform.h"
Before you initialize the GUI, be sure to create a viewport. This is sent to the OgrePlatform class and stores it for use later during the "initialise" method call.
declaration:
MyGUI::Gui * mGUI;
create Code:
MyGUI::OgrePlatform* mPlatform = new MyGUI::OgrePlatform(); mPlatform->initialise(mWindow, mSceneManager); // mWindow is Ogre::RenderWindow*, mSceneManager is Ogre::SceneManager* mGUI = new MyGUI::Gui(); mGUI->initialise(); class CLASS_NAME : public OIS::MouseListener , public OIS::KeyListener bool CLASS_NAME::mouseMoved( const OIS::MouseEvent &arg ) { mGUI->injectMouseMove(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs); //... } bool CLASS_NAME::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) { mGUI->injectMousePress(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); //... } bool CLASS_NAME::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) { mGUI->injectMouseRelease(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); //... } bool CLASS_NAME::keyPressed( const OIS::KeyEvent &arg ) { mGUI->injectKeyPress(MyGUI::KeyCode::Enum(arg.key), arg.text); //... } bool CLASS_NAME::keyReleased( const OIS::KeyEvent &arg ) { mGUI->injectKeyRelease(MyGUI::KeyCode::Enum(arg.key)); //... }
Note: for those who used previous versions of MyGUI: you don't need to call injectFrameEntered every frame in MyGUI 3.0 (now renderer do this)
Note: if you can't move your cursor all over the rendering area, you may need to add the following code to your app's initialization (and also to your "window resize event" callback):
const OIS::MouseState &mouseState = mMouse->getMouseState(); // mMouse is type of OIS::Mouse* mouseState.width = 1024; // your rendering area width mouseState.height = 768; // your rendering area height
create button and set callback:
MyGUI::ButtonPtr button = mGUI->createWidget<MyGUI::Button>("Button", 10, 10, 300, 26, MyGUI::Align::Default, "Main"); button->setCaption("exit"); // set callback button->eventMouseButtonClick = MyGUI::newDelegate(CLASS_POINTER, &CLASS_NAME::METHOD_NAME); // CLASS_POINTER is pointer to instance of a CLASS_NAME (usually '''this''') // or //button->eventMouseButtonClick = MyGUI::newDelegate(STATIC_METHOD_NAME); //button->eventMouseButtonClick = MyGUI::newDelegate(GLOBAL_FUNC_NAME);
another way of creating button and setting callback:
in sample.layout:
<?xml version="1.0" encoding="UTF-8"?> <MyGUI type="Layout"> <Widget type="Button" skin="Button" position="10 10 300 26" align="Default" layer="Main" name="MyFirstButton" > <Property key="Widget_Caption" value="exit" /> </Widget> </MyGUI>
code:
// load layout MyGUI::LayoutManager::getInstance().load("sample.layout"); // set callback MyGUI::ButtonPtr button = mGUI->findWidget<MyGUI::Button>("MyFirstButton"); button->eventMouseButtonClick = MyGUI::newDelegate(CLASS_POINTER, &CLASS_NAME::METHOD_NAME); // CLASS_POINTER is pointer to CLASS_NAME ('''this''') // or //button->eventMouseButtonClick = MyGUI::newDelegate(STATIC_METHOD_NAME); //button->eventMouseButtonClick = MyGUI::newDelegate(GLOBAL_FUNC_NAME);
method signature for eventMouseButtonClick:
void CLASS_NAME::METHOD_NAME(MyGUI::WidgetPtr _sender) { //... } void CLASS_NAME::STATIC_METHOD_NAME(MyGUI::WidgetPtr _sender) { //... } void GLOBAL_FUNC_NAME(MyGUI::WidgetPtr _sender) { //... }
destroy:
mGUI->shutdown(); delete mGUI; mGUI = 0; mPlatform->shutdown(); delete mPlatform; mPlatform = 0;