Skip to main content

History: Creating Overlays via Code

Preview of version: 1

This code snippet demonstrates how to create Overlays using code.

You'll need to include OgreTextAreaOverlayElement.h and OgreFontManager.h for this snippet to compile.

OverlayManager& overlayManager = OverlayManager::getSingleton();

// Create a panel
OverlayContainer* panel = static_cast<OverlayContainer*>(
    overlayManager.createOverlayElement("Panel", "PanelName"));
panel->setMetricsMode(Ogre::GMM_PIXELS);
panel->setPosition(10, 10);
panel->setDimensions(100, 100);
//panel->setMaterialName("MaterialName"); // Optional background material

// Create a text area
TextAreaOverlayElement* textArea = static_cast<TextAreaOverlayElement*>(
    overlayManager.createOverlayElement("TextArea", "TextAreaName"));
textArea->setMetricsMode(Ogre::GMM_PIXELS);
textArea->setPosition(0, 0);
textArea->setDimensions(100, 100);
textArea->setCaption("Hello, World!");
textArea->setCharHeight(16);
textArea->setFontName("TrebuchetMSBold");
textArea->setColourBottom(ColourValue(0.3, 0.5, 0.3));
textArea->setColourTop(ColourValue(0.5, 0.7, 0.5));

// Create an overlay, and add the panel
Overlay* overlay = overlayManager.create("OverlayName");
overlay->add2D(panel);

// Add the text area to the panel
panel->addChild(textArea);

// Show the overlay
overlay->show();

See also


Category:Code Snippet (GUI)
Category:Overlay

History

Information Version
Wed 30 of May, 2012 14:53 GMT-0000 Shinigami Added the "Ogre::Overlay*" type to the overlay identifier to allow for direct copy&paste of the code 7
Mon 07 of May, 2012 18:09 GMT-0000 uzik more minimal example that works included. Bug in Ogre release noted. 6
Tue 31 of Aug, 2010 20:13 GMT-0000 DragonM Add Ogre compatibility tag. 5
Tue 29 of Jun, 2010 14:05 GMT-0000 JustBoo 4
Sat 02 of Jan, 2010 20:26 GMT-0000 jacmoe 3
Fri 25 of Dec, 2009 13:36 GMT-0000 jacmoe 2
Wed 06 of May, 2009 19:24 GMT-0000 Spacegaier 1