In this example we will show how to add a text and a button to CEGUI::FrameWindow.
FrameWindow is just a wrapper for other elements. It holds text, buttons and other items within it.
CEGUI::WindowManager* m_WindowManager; CEGUI::FrameWindow* frame = static_cast<CEGUI::FrameWindow*>( m_WindowManager->createWindow( "GlossySerpentFHD/FrameWindow" ) );
In order to add some text to the frame window we need to create a “static text” of type CEGUI:DefaultWindow:
CEGUI::WindowManager* m_WindowManager; Window* statictext = static_cast<CEGUI::DefaultWindow*>(m_WindowManager->createWindow("Vanilla/StaticText"));
By default the static text window will render frame border and background.
These settings may be changed by giving the window special properties:
statictext->setText("My DEMO\nWelcome to our game DEMO"); statictext->setProperty("FrameEnabled", "false"); statictext->setProperty("BackgroundEnabled", "false");
Next step is to add the text window to the frame:
frame->addChild(statictext);
The result is one visible frame with text and a button:
The button is it’s own element in cegui: CEGUI:PushButton. Here is how to create it:
CEGUI::PushButton* button = static_cast<CEGUI::PushButton*>( m_WindowManager->createWindow("GlossySerpentFHD/Button" ) ); button->setPosition(CEGUI::UVector2(cegui_reldim(0.38f), cegui_reldim( 0.2f))); button->setSize(CEGUI::USize(cegui_reldim(0.3f), cegui_reldim( 0.08f))); button->setText("View Demo");
The button can be added either to the Frame or the text. The size will than be relative to either of them. Here we add the button to the frame:
frame->addChild(button);
CEGUI is a very flexible GUI system for use in games and other graphical environments.