CEGUI Text on FrameWindow example

By , last updated December 15, 2019

In this example we will show how to add a text and a button to CEGUI::FrameWindow.

cegui text frame window preview

  1. Create the frame window instance.

    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" ) );
    
  2. Add text

    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.

    cegui frame window text button example with border

    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:

    cegui frame window inline text and button example

  3. Add 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.