QuickGUI编辑器系列---从文件中读取并解析
QuickGUI是Ogre引擎下的一种用户界面,如果你使用的Ogre,而Ogre自带的Overlay无法满足你的需求时,你可以考虑QuickGUI,相对于CEGUI,他小巧,并且完全基于Ogre设计,这点比CEGUI要好,但是没有CEGUI支持那么多的控件,不过对于一般的用户,QuickGUI提供的控件还是够用的,下面是QuickGUI目前支持的控件『V0.97版本』。
Button
CheckBox
ComboBox
Console
Image
Label
List
ListItem
Menu
MenuList
NStateButton
Panel
ProgressBar
RadioButton
Sheet
TextBox
TrackBar (Horizontal/Vertical)
ScrollBar (Horizontal/Vertical)
Window (with TitleBar)
目前QuickGUI编辑器还没有开始做,主要是想使用C#来做UI,C++只负责解析,这样的话会比较容易,虽然C#UI那部分要重写读取和保存模块,比直接用C++多了一个步骤,但是C#开发UI的简便还是让我选择了这样做。
了解了这些,就可以知道,现在一定先做C++的XML解析部分,现在让我们把目光集中在QuickGUI XML的文件格式上。
1
<?xml version="1.0" ?>
2
3
<QuickGUILayout ActiveSheet="MainSheet">
4
5
<Widget Type="Sheet" Name="MainSheet" Skin="qgui">
6
7
<Widget Type="Window" Name="MainWindow">
8
9
<Property Dimension="10 10 320 180" />
10
11
</Widget>
12
13
<Widget Type="Window" Name="TestWindow">
14
15
<Property Dimension="10 220 320 180" />
16
17
</Widget>
18
19
</Widget>
20
21
</QuickGUILayout>
22
23
<?xml version="1.0" ?>2

3
<QuickGUILayout ActiveSheet="MainSheet">4

5
<Widget Type="Sheet" Name="MainSheet" Skin="qgui">6

7
<Widget Type="Window" Name="MainWindow">8

9
<Property Dimension="10 10 320 180" />10

11
</Widget>12

13
<Widget Type="Window" Name="TestWindow">14

15
<Property Dimension="10 220 320 180" />16

17
</Widget>18

19
</Widget>20

21
</QuickGUILayout>22

23

xml解析使用了tinyXML库,目前只支持Sheet和Window,以后会逐渐增加对其他控件的支持,其它的控件格式是类似的,XML文件描述很简单,下面放上一张截图:
最后再简单说一下QuickGUI的事件绑定和注入:
QuickGUI支持事件绑定,用法和CEGUI类似:
1
mCloseButton->addEventHandler(QuickGUI::EVENT_MOUSE_CLICK,&Window::hide,dynamic_cast<Window*>(mParentWidget));
2
3
mCloseButton->addEventHandler(QuickGUI::EVENT_MOUSE_BUTTON_UP,&Window::hide,dynamic_cast<Window*>(mParentWidget));
4
mCloseButton->addEventHandler(QuickGUI::EVENT_MOUSE_CLICK,&Window::hide,dynamic_cast<Window*>(mParentWidget)); 2

3
mCloseButton->addEventHandler(QuickGUI::EVENT_MOUSE_BUTTON_UP,&Window::hide,dynamic_cast<Window*>(mParentWidget)); 4

QuickGUI可以和OIS共用,支持注入:
1
2
bool injectChar(char c);
3
4
bool injectKeyDown(const KeyCode& kc);
5
6
bool injectKeyUp(const KeyCode& kc);
7
8
9
10
bool injectMouseButtonDown(const MouseButtonID& button);
11
12
bool injectMouseButtonUp(const MouseButtonID& button);
13
14
bool injectMouseLeaves(void);
15
16
bool injectMouseMove(const int& xPixelOffset, const int& yPixelOffset);
17
18
bool injectMousePosition(const int& xPixelPosition, const int& yPixelPosition);
19
20
bool injectMouseWheelChange(float delta);
21
22
void injectTime(Ogre::Real time);
23
24

2
bool injectChar(char c); 3

4
bool injectKeyDown(const KeyCode& kc); 5

6
bool injectKeyUp(const KeyCode& kc); 7

8
9

10
bool injectMouseButtonDown(const MouseButtonID& button); 11

12
bool injectMouseButtonUp(const MouseButtonID& button); 13

14
bool injectMouseLeaves(void); 15

16
bool injectMouseMove(const int& xPixelOffset, const int& yPixelOffset); 17

18
bool injectMousePosition(const int& xPixelPosition, const int& yPixelPosition); 19

20
bool injectMouseWheelChange(float delta); 21

22
void injectTime(Ogre::Real time); 23

24

posted on 2008-04-24 18:14 gogoplayer 阅读(3377) 评论(3) 收藏 举报
浙公网安备 33010602011771号