OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: MyGUI quickstart
View page
Source of version: 30
(current)
This is a quick start for __MyGUI 3.0+__. If you want to use an earlier version of MyGUI, use ((MyGUI quickstart old|this page)). Copy the ''MyGUI_Media'' folder from the 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__'' as an additional dependency. 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__'' as an additional dependency. If MyGUI was built as a static library, freetype####(_d).lib is also required (#### - your freetype version). !!Code __includes:__ You need to add these to the included folders: - ''path_to_MyGUI/MyGUIEngine/include'' and ''path_to_MyGUI/Platforms/Ogre/OgrePlatform/include'', and add to your code the following includes: {CODE(wrap="1", colors="c++")} #include "MyGUI.h" #include "MyGUI_OgrePlatform.h" {CODE} Before you initialize the GUI, be sure to create a viewport. This is sent to the OgrePlatform class and stores it for later use in the "initialise" method call. __declaration:__ {CODE(wrap="1", colors="c++")} MyGUI::Gui* mGUI; MyGUI::OgrePlatform* mPlatform; {CODE} __initialisation:__ {CODE(wrap="1", colors="c++")} mPlatform = new MyGUI::OgrePlatform(); mPlatform->initialise(mWindow, mSceneManager); // mWindow is Ogre::RenderWindow*, mSceneManager is Ogre::SceneManager* mGUI = new MyGUI::Gui(); mGUI->initialise(); {CODE} %note% __Note:__ Make sure you init MyGUI ''after'' you've initialized it's resource group in Ogre's ResourceManager (or called initialiseAllResourceGroups() if you don't care about resource groups). Otherwise MyGUI will not display anything, even though MyGUI.log will indicate that all .xml files were found and everything is working fine. %note% __Note:__ Also be aware that resource paths specified in the resources.cfg file need to be under the [[general]] section or MyGui will by default not see those resources. __mouse and keyboard input:__ {CODE(wrap="1", colors="c++")} class CLASS_NAME : public OIS::MouseListener , public OIS::KeyListener bool CLASS_NAME::mouseMoved( const OIS::MouseEvent &arg ) { MyGUI::InputManager::getInstance().injectMouseMove(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs); //... return true; } bool CLASS_NAME::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) { MyGUI::InputManager::getInstance().injectMousePress(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); //... return true; } bool CLASS_NAME::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) { MyGUI::InputManager::getInstance().injectMouseRelease(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); //... return true; } bool CLASS_NAME::keyPressed( const OIS::KeyEvent &arg ) { MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(arg.key), arg.text); //... return true; } bool CLASS_NAME::keyReleased( const OIS::KeyEvent &arg ) { MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(arg.key)); //... return true; } {CODE} %note% __Note:__ For those who have used previous versions of MyGUI: you don't need to call injectFrameEntered every frame in MyGUI 3.0+ (the renderer does this now.) %note% __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): {CODE(wrap="1", colors="c++")}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{CODE} __create button and set callback:__ {CODE(wrap="1", colors="c++")} 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); {CODE} Note: the "CLASS_NAME::METHOD_NAME" function need to be of the following prototype function: {CODE(wrap="1", colors="c++")} void CLASS_NAME::METHOD_NAME(MyGUI::WidgetPtr _sender) {CODE} __Another way of creating button and setting callback:__ In ''sample.layout'': {CODE(wrap="1", colors="xml")} <?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} __code:__ {CODE(wrap="1", colors="c++")} // load layout MyGUI::LayoutManager::getInstance().loadLayout("sample.layout"); //MyGUI::LayerManager::getInstancePtr()->resizeView(MyGUI::RenderManager::getInstancePtr()->getViewSize()); //Uncomment this line if you want to align worked immediately after loading 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); {CODE} __method signature for eventMouseButtonClick:__ {CODE(wrap="1", colors="c++")} void CLASS_NAME::METHOD_NAME(MyGUI::WidgetPtr _sender) { //... } void CLASS_NAME::STATIC_METHOD_NAME(MyGUI::WidgetPtr _sender) { //... } void GLOBAL_FUNC_NAME(MyGUI::WidgetPtr _sender) { //... } {CODE} __destruction:__ {CODE(wrap="1", colors="c++")} mGUI->shutdown(); delete mGUI; mGUI = 0; mPlatform->shutdown(); delete mPlatform; mPlatform = 0; {CODE}
Search by Tags
Search Wiki by Freetags
Latest Changes
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
...more
Search
Find
Advanced
Search Help
Online Users
129 online users