在CEGUI中使用layout文件(1) CEGUI支持两种方式的资源使用,一种就是在前文可见的直接在c++文件当中创建窗体,使用窗体;另一种方式就是在layout文件当中定制窗体。从理论上讲,两种方式都能达到相同的目的。 在不使用layout文件时,CEGUI是不太方便的,因为要定位控件,常常得修改文件当中的参数,如果在c++文件当中修改,每次都编译,很恶心(尤其是在有编辑器的情况下,使用c++就不能使用了)。 所以如果你要使用CEGUI,对layout文件的使用和编辑都是必修课。 下面这个就是一个简单的使用layout文件的例子,作的仅仅是把文件读进来、显示在窗口里了。 #include "TDemo1.h" #include "CEGUI.h" #include "CEGuiBaseApplication.h" #include <cstdlib> int main(int argc, char *argv[]) ...{ TDemo1 app; return app.run(); } /**//************************************************************************* *************************************************************************/ bool TDemo1::initialiseSample() ...{ using namespace CEGUI; // 窗体管理器 WindowManager& winMgr = WindowManager::getSingleton(); // 载入资源 SchemeManager::getSingleton().loadScheme("TaharezLook.scheme"); System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow"); FontManager::getSingleton().createFont("Commonwealth-10.font"); // 在此载入layout文件 // 这个就是要在实际当中经常使用的 Window* sheet = winMgr.loadWindowLayout("TDemo1.layout"); System::getSingleton().setGUISheet(sheet); return true; } /**//************************************************************************* *************************************************************************/ void TDemo1::cleanupSample() ...{ // 啥也不做 } TDemo1.layout <?xml version="1.0" encoding="UTF-8"?> <GUILayout> <Window Type="DefaultWindow" Name="root"> <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" /> <Window Type="TaharezLook/FrameWindow" Name="TDemo1/Window1" > <Property Name="Text" Value="TDemo 1" /> <Property Name="UnifiedMaxSize" Value="{{0.8,0},{0.8,0}}" /> <Property Name="UnifiedMinSize" Value="{{0.2,0},{0.2,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.1,0},{0.9,0},{0.7,0}}" /> <Property Name="CloseButtonEnabled" Value="False" /> </Window> </Window> </GUILayout>
学习CEGUI(CELayoutEditor,CEImagesetEditor)之四
最新推荐文章于 2011-08-16 13:34:44 发布