MyGUI_Orge官网教程_2.快速在工程中使用MyGUI
来源:互联网 发布:黑客破解软件 编辑:程序博客网 时间:2024/05/08 13:02
-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 widthmouseState.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 callbackbutton->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 layoutMyGUI::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 callbackMyGUI::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
- MyGUI_Orge官网教程_2.快速在工程中使用MyGUI
- MyGUI_Orge官网教程_3.在windows皮肤中添加按钮
- MyGUI_Orge官网教程_4.使用委托delegate
- MyGUI_Orge官网教程_7.使用按钮图像皮肤ButtonImage Skin
- MyGUI_Orge官网教程_1.Widgets窗口部件
- MyGUI_Orge官网教程_5.窗口部件控制
- MyGUI_Orge官网教程_6.启用工具提示tooltip
- MyGUI_Orge官网教程_8.改变文本颜色_多列表
- 在Xcode工程中集成Cocos教程
- 在工程中使用SQLite3
- 快速教程:在2D空间中使用四叉树实现碰撞检测
- (二)线程同步_2---在同步代码块中使用条件
- 在weblogic 8.x中快速部署工程
- 在工程中使用ATL向导
- 在symbian工程中使用mk文件
- 在symbian工程中使用mk文件
- 在Win32工程中使用GdiPlus
- 怎样在一个工程中使用sqlite
- Makefile经典教程(掌握这些足够)
- C++观察者模式
- 【算法】最短路径之SPFA
- 容斥
- DDMS的使用、内存溢出的调试
- MyGUI_Orge官网教程_2.快速在工程中使用MyGUI
- riak delete entire bucket
- SQLServer——聚集索引结构
- QQ2013导致adb不能使用问题的修复
- 实现listView滑动删除
- DOM删除添加节点小例子
- Android核心分析(26)-----Android GDI之SurfaceFlinger
- 用ICSharpCode.SharpZipLib进行压缩
- 网页设计-云ide