-1.工程配置:
包含目录:
(PathToMyGUI)\MyGUIEngine\include
(PathToMyGUI)\Platforms\Ogre\OgrePlatform\include
库目录:
(PathToMyGUI)\lib\Release
(PathToMyGUI)\lib\Debug
附加连接依赖库
MyGUIEngine.lib MyGUI.OgrePlatform.lib or MyGUIEngine_d.lib MyGUI.OgrePlatform_d.lib
下面是MyGUI 3.0+快速开始指南.
拷贝MyGUI_Media目录,然后在ogre的resources.cfg中添加该目录。
编译MyGUI,并把MyGUIEngine_d.dll拷贝的你程序的工作目录,并添加MyGUIEngine_d.lib到工程设置的附加依赖库。
你也需要编译MyGUI.OgrePlatform作为MyGUI库到ogre渲染引擎的一个接口,并添加MyGUI.OgrePlatform_d.lib到附加依赖库。
If MyGUI was built as a static library, freetype####(_d).lib is also required (#### - your freetype version).
Code
includes:
你需要添加包含目录,并在源文件里添加下面包含:
#include "MyGUI.h" #include "MyGUI_OgrePlatform.h"
在你初始化GUI前,确定创建了 一个视口viewport。因为这将被送到OgrePlatform类来存储它,之后调用initialize的时候用。
declaration:
MyGUI::Gui* mGUI;
initialisation:
MyGUI::OgrePlatform* mPlatform = new MyGUI::OgrePlatform(); mPlatform->initialise(mWindow, mSceneManager); // mWindow is Ogre::RenderWindow*, mSceneManager is Ogre::SceneManager* mGUI = new MyGUI::Gui(); mGUI->initialise();
Note: 确定在ogre的ResourceManager中初始化它的资源组resource group(或调用initializeResourceGroups如果你不关心资源组)后再初始化MyGUI。否则MyGUI不会显示任何东西,尽管MyGUI.log会显示所有的xml文件都找到了且工作正常。
mouse and keyboard input:
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); //... } 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)); //... } 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)); //... } bool CLASS_NAME::keyPressed( const OIS::KeyEvent &arg ) { MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(arg.key), arg.text); //... } bool CLASS_NAME::keyReleased( const OIS::KeyEvent &arg ) { MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(arg.key)); //... }
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: 如果你不能在渲染区域移动你的鼠标,你可能需要添加下面的代码到你的程序初始化处(也要到你的“窗口改变大小事件resize”的回调函数去):
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().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);
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) { //... }
destruction:
mGUI->shutdown(); delete mGUI; mGUI = 0; mPlatform->shutdown(); delete mPlatform; mPlatform = 0;
后记:
用最新版有问题的,看看这个链接吧:http://blog.csdn.net/augusdi/article/details/8868917
配套测试代码:http://download.csdn.net/detail/adfansong/5960819