MyGUI quickstart old        

Copy MyGUI_Media folder from downloaded package (or from svn) and add the path to it in your resources.cfg.

Compile MyGUI and put MyGUI(_d).dll near the executable file and add MyGUI(_d).lib to additional dependencies.


includes code:

#include "MyGUI.h"


create Code:

MyGUI::Gui * mGUI = new MyGUI::Gui();
   mGUI->initialise(mWindow);

 class CLASS_NAME : public Ogre::FrameListener, public OIS::MouseListener , public OIS::KeyListener

 bool CLASS_NAME::frameStarted(const Ogre::FrameEvent& evt)
 {
 	mGUI->injectFrameEntered(evt.timeSinceLastFrame);
 	//...
 }
 
 bool CLASS_NAME::mouseMoved( const OIS::MouseEvent &arg )
 {
 	mGUI->injectMouseMove(arg);
 	//...
 }
 
 bool CLASS_NAME::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
 {
 	mGUI->injectMousePress(arg, id);
 	//...
 }
 
 bool CLASS_NAME::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
 {
 	mGUI->injectMouseRelease(arg, id);
 	//...
 }
 
 bool CLASS_NAME::keyPressed( const OIS::KeyEvent &arg )
 {
 	mGUI->injectKeyPress(arg);
 	//...
 }
 
 bool CLASS_NAME::keyReleased( const OIS::KeyEvent &arg )
 {
 	mGUI->injectKeyRelease(arg);
 	//...
 }


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="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;