Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
orxonox::GUIManager Class Reference

Provides a simple interface to CEGUI with tolua methods and console commands.
More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/GUIManager.h>

Inheritance diagram for orxonox::GUIManager:
orxonox::Singleton< GUIManager > orxonox::InputHandler orxonox::WindowEventListener orxonox::Listable orxonox::Identifiable

Public Member Functions

 GUIManager (const std::pair< int, int > &mousePosition)
 Constructs the GUIManager by starting up CEGUI. More...
 
 ~GUIManager ()=default
 Leave empty and use cleanup() instead. More...
 
void changedGUIScheme (void)
 
const std::string & createInputState (const std::string &name, tribool showCursor=tribool(true), tribool useKeyboard=tribool(true), bool bBlockJoyStick=false)
 Creates a new InputState to be used with a GUI Sheet. More...
 
void destroy ()
 Destructor that also executes when object fails to construct. More...
 
Ogre::Camera * getCamera ()
 
CEGUI::Window * getHUDRootWindow ()
 Returns the root window for all HUD sheets. More...
 
std::vector< std::string > getLoadedGUIs ()
 
LuaStategetLuaState (void)
 
CEGUI::Window * getMenuRootWindow ()
 Returns the root window for all menu sheets. More...
 
orxonox::PlayerInfogetPlayer (const std::string &guiname) const
 
void keyESC ()
 
void loadGUI (const std::string &name)
 Loads a GUI sheet by Lua script. More...
 
void preUpdate (const Clock &time)
 used to tick the GUI More...
 
void setBackgroundImage (const std::string &imageSet, const std::string imageName)
 
void setBackgroundImage (const std::string &image)
 
void setCamera (Ogre::Camera *camera)
 Tells the GUIManager which SceneManager to use. More...
 
void setConfigValues (void)
 
void setPlayer (const std::string &guiname, PlayerInfo *player)
 
void showGUIExtra (const std::string &name, const std::string &ptr, bool bHidePrevious=false, bool bNoInput=false)
 Hack-ish. More...
 
void toggleGUIHelper (const std::string &name, bool bHidePrevious, bool bNoInput, bool show)
 Helper method to toggle a specified GUI. More...
 
bool usingOldCEGUI (void)
 Check whether CEGUI is version < 0.7. More...
 
- Public Member Functions inherited from orxonox::InputHandler
virtual ~InputHandler ()=default
 
virtual void allDevicesUpdated (float dt)
 
virtual void axisMoved (unsigned int joyStick, unsigned int axis, float value)
 
template<class T >
void buttonEvent (unsigned int device, T button, ButtonEvent::TPress)
 
template<class T >
void buttonEvent (unsigned int device, T button, ButtonEvent::TRelease)
 
template<class T >
void buttonEvent (unsigned int device, T button, ButtonEvent::THold)
 
virtual void buttonHeld (const KeyEvent &evt)
 
virtual void buttonHeld (MouseButtonCode::ByEnum button)
 
virtual void buttonHeld (unsigned int joyStick, JoyStickButtonCode::ByEnum button)
 
virtual void buttonPressed (unsigned int joyStick, JoyStickButtonCode::ByEnum button)
 
virtual void buttonReleased (unsigned int joyStick, JoyStickButtonCode::ByEnum button)
 
virtual void joyStickUpdated (unsigned int joyStick, float dt)
 
virtual void keyboardUpdated (float dt)
 
virtual void mouseUpdated (float dt)
 
- Public Member Functions inherited from orxonox::Listable
 Listable ()
 Constructor: Allocates space in the element list. More...
 
 Listable (Context *context)
 Constructor: Allocates space in the element list and assigns the context. More...
 
virtual ~Listable ()
 Destructor: Removes the object from the object-lists. More...
 
ContextgetContext () const
 
void setContext (Context *context)
 Changes the context. More...
 
void unregisterObject ()
 Removes this object from the object-lists. More...
 
- Public Member Functions inherited from orxonox::Identifiable
 Identifiable ()
 Constructor: Sets the default values. More...
 
virtual ~Identifiable ()
 
ORX_FORCEINLINE voidgetDerivedPointer (unsigned int classID)
 Returns a valid pointer of any derived type that is registered in the class hierarchy. More...
 
template<class T >
ORX_FORCEINLINE T * getDerivedPointer (unsigned int classID)
 Version of getDerivedPointer with template. More...
 
template<class T >
ORX_FORCEINLINE const T * getDerivedPointer (unsigned int classID) const
 Const version of getDerivedPointer with template. More...
 
IdentifiergetIdentifier () const
 Returns the Identifier of the object. More...
 
bool isA (const Identifier *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
template<class B >
bool isA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isA (const Identifiable *object)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isChildOf (const Identifier *identifier)
 Returns true if the object's class is a child of the given type. More...
 
template<class B >
bool isChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a child of the given type. More...
 
bool isChildOf (const Identifiable *object)
 Returns true if the object's class is a child of the given type. More...
 
bool isDirectChildOf (const Identifier *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
template<class B >
bool isDirectChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectChildOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectParentOf (const Identifier *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
template<class B >
bool isDirectParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
bool isDirectParentOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isExactlyA (const Identifier *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
template<class B >
bool isExactlyA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
bool isExactlyA (const Identifiable *object)
 Returns true if the object's class is exactly of the given type. More...
 
bool isParentOf (const Identifier *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
template<class B >
bool isParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
bool isParentOf (const Identifiable *object)
 Returns true if the object's class is a parent of the given type. More...
 

Static Public Member Functions

static void addFontHelper (const std::string &name, int size, const std::string &fontName)
 Adds a new freetype font to the CEGUI system. More...
 
static float getFontTextExtent (const CEGUI::Font *font, const std::string &text, float x_scale=1.0f)
 
static GUIManagergetInstance ()
 
static void hideGUI (const std::string &name)
 Hides specified GUI. More...
 
static bool inDevMode (void)
 Helper method to get the developer's mode without having to export Core.h. More...
 
static bool preloadMenuSheets ()
 
static void setItemTooltipsEnabledHelper (CEGUI::Listbox *listbox, bool enabled)
 Set whether the tooltips for the input Listbox are enabled. More...
 
static void setTooltipTextHelper (CEGUI::ListboxItem *item, const std::string &toooltip)
 Set the input tooltip text for the input ListboxItem. More...
 
static void showGUI (const std::string &name, bool bHidePrevious=false, bool bNoInput=false)
 Displays specified GUI on screen. More...
 
static void subscribeEventHelper (CEGUI::Window *window, const std::string &event, const std::string &function)
 Subscribe the input function to the input event for the input window. More...
 
static void toggleGUI (const std::string &name, bool bHidePrevious=false, bool bNoInput=false)
 Toggles specified GUI. More...
 
- Static Public Member Functions inherited from orxonox::Singleton< GUIManager >
static bool exists ()
 Tells whether the singleton has been created. More...
 
static GUIManagergetInstance ()
 Returns a reference to the singleton instance. More...
 

Private Member Functions

 GUIManager (const GUIManager &)=delete
 
virtual void buttonPressed (const KeyEvent &evt) override
 
virtual void buttonPressed (MouseButtonCode::ByEnum id) override
 Function receiving a mouse button pressed event. More...
 
virtual void buttonReleased (const KeyEvent &evt) override
 
virtual void buttonReleased (MouseButtonCode::ByEnum id) override
 Function receiving a mouse button released event. More...
 
void changedCeguiOutputLevel ()
 
void executeCode (const std::string &str)
 Executes Lua code. More...
 
void mouseLeft ()
 Indicates that the mouse left the application's window. More...
 
virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) override
 
virtual void mouseScrolled (int abs, int rel) override
 
GUIManageroperator= (const GUIManager &)=delete
 
template<typename FunctionType , typename ObjectType >
bool protectedCall (FunctionType function, ObjectType object)
 Executes a CEGUI function normally, but catches CEGUI::ScriptException. More...
 
template<typename FunctionType >
bool protectedCeguiSystemCall (FunctionType function)
 Executes a CEGUI function normally, but catches CEGUI::ScriptException. More...
 
virtual void windowFocusChanged (bool bFocus) override
 Notify CEGUI if the windows loses the focus (stops highlighting of menu items, etc). More...
 
virtual void windowResized (unsigned int newWidth, unsigned int newHeight) override
 Callback of window event listener, called if the window is resized. More...
 

Private Attributes

bool bPreloadMenuSheets_
 If true, menu sheets are pre-loaded during startup. More...
 
Ogre::Camera * camera_
 Camera used to render the scene with the GUI. More...
 
CEGUI::Logger * ceguiLogger_
 CEGUI's logger to be able to log CEGUI errors in our log. More...
 
DestructionHelper< GUIManagerdestructionHelper_
 Helper object that executes the surrogate destructor destroy() More...
 
CEGUI::OgreCEGUIRendererguiRenderer_
 CEGUI's interface to the Ogre Engine. More...
 
std::string guiScheme_
 
CEGUI::System * guiSystem_
 CEGUI's main system. More...
 
CEGUI::Window * hudRootWindow_
 Root node for the HUD sheets. More...
 
LuaStateluaState_
 LuaState, access point to the Lua engine. More...
 
CEGUI::Window * menuRootWindow_
 Root node for the menu sheets (used by Lua) More...
 
int numScrollLines_
 How many lines to scroll in a list if the scroll wheel is used. More...
 
bool oldCEGUI_
 
int outputLevelCeguiLog_
 CEGUI's log level. More...
 
std::map< std::string, PlayerInfo * > players_
 Stores the player (owner) for each GUI. More...
 
CEGUI::ResourceProvider * resourceProvider_
 CEGUI's resource provider. More...
 
std::shared_ptr< ResourceInforootFileInfo_
 Resource information about the root script. More...
 
CEGUI::Window * rootWindow_
 Root node for all windows. More...
 
CEGUI::LuaScriptModule * scriptModule_
 CEGUI's script module to use Lua. More...
 

Static Private Attributes

static const std::string defaultScheme_ = "TaharezGreen"
 
static GUIManagersingletonPtr_s = nullptr
 Singleton reference to GUIManager. More...
 

Friends

class Singleton< GUIManager >
 

Additional Inherited Members

- Static Public Attributes inherited from orxonox::InputHandler
static InputHandler EMPTY
 Use this input handler if you want to occupy a device in an input state. More...
 
- Protected Member Functions inherited from orxonox::Singleton< GUIManager >
 Singleton ()
 Constructor sets the singleton instance pointer. More...
 
virtual ~Singleton ()
 Destructor resets the singleton instance pointer. More...
 
- Protected Member Functions inherited from orxonox::WindowEventListener
 WindowEventListener ()
 
virtual ~WindowEventListener ()=default
 
unsigned int getWindowHeight () const
 Returns the current render window height. More...
 
unsigned int getWindowWidth () const
 Returns the current render window width. More...
 

Detailed Description

Provides a simple interface to CEGUI with tolua methods and console commands.

It also acts as a key and mouse handler.

The GUIManager is a singleton and can be called anywhere when access on the GUI is needed.

Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler. Those input events are then injected into CEGUI in Lua.

Constructor & Destructor Documentation

orxonox::GUIManager::GUIManager ( const std::pair< int, int > &  mousePosition)

Constructs the GUIManager by starting up CEGUI.

Creates the interface to Ogre, sets up the CEGUI renderer and the Lua script module together with the Lua engine. The log is set up and connected to the CEGUILogger. After Lua setup tolua++-elements are linked to Lua-state to give Lua access to C++-code. Finally initial Lua code is executed (maybe we can do this with the CEGUI startup script automatically).

Returns
true if success, otherwise false
orxonox::GUIManager::~GUIManager ( )
default

Leave empty and use cleanup() instead.

orxonox::GUIManager::GUIManager ( const GUIManager )
privatedelete

Member Function Documentation

void orxonox::GUIManager::addFontHelper ( const std::string &  name,
int  size,
const std::string &  fontName 
)
static

Adds a new freetype font to the CEGUI system.

Parameters
nameThe name of the new font.
sizeThe font size of the new font in pixels.
fontNameThe filename of the font.
void orxonox::GUIManager::buttonPressed ( const KeyEvent evt)
overrideprivatevirtual

Reimplemented from orxonox::InputHandler.

void orxonox::GUIManager::buttonPressed ( MouseButtonCode::ByEnum  id)
overrideprivatevirtual

Function receiving a mouse button pressed event.

Parameters
idID of the mouse button which got pressed

This function is inherited by MouseHandler and injects the event into CEGUI. It is for CEGUI to process the event.

Reimplemented from orxonox::InputHandler.

void orxonox::GUIManager::buttonReleased ( const KeyEvent evt)
overrideprivatevirtual

Reimplemented from orxonox::InputHandler.

void orxonox::GUIManager::buttonReleased ( MouseButtonCode::ByEnum  id)
overrideprivatevirtual

Function receiving a mouse button released event.

Parameters
idID of the mouse button which got released

This function is inherited by MouseHandler and injects the event into CEGUI. It is for CEGUI to process the event.

Reimplemented from orxonox::InputHandler.

void orxonox::GUIManager::changedCeguiOutputLevel ( )
private
void orxonox::GUIManager::changedGUIScheme ( void  )
const std::string & orxonox::GUIManager::createInputState ( const std::string &  name,
tribool  showCursor = tribool(true),
tribool  useKeyboard = tribool(true),
bool  bBlockJoyStick = false 
)

Creates a new InputState to be used with a GUI Sheet.

void orxonox::GUIManager::destroy ( )

Destructor that also executes when object fails to construct.

void orxonox::GUIManager::executeCode ( const std::string &  str)
private

Executes Lua code.

Parameters
strreference to string object holding the Lua code which is to be executed
Ogre::Camera* orxonox::GUIManager::getCamera ( )
inline
float orxonox::GUIManager::getFontTextExtent ( const CEGUI::Font *  font,
const std::string &  text,
float  x_scale = 1.0f 
)
static
CEGUI::Window* orxonox::GUIManager::getHUDRootWindow ( )
inline

Returns the root window for all HUD sheets.

static GUIManager& orxonox::GUIManager::getInstance ( )
inlinestatic
std::vector< std::string > orxonox::GUIManager::getLoadedGUIs ( )
LuaState* orxonox::GUIManager::getLuaState ( void  )
inline
CEGUI::Window* orxonox::GUIManager::getMenuRootWindow ( )
inline

Returns the root window for all menu sheets.

orxonox::PlayerInfo* orxonox::GUIManager::getPlayer ( const std::string &  guiname) const
inline
void orxonox::GUIManager::hideGUI ( const std::string &  name)
static

Hides specified GUI.

Parameters
nameThe name of the GUI.
bool orxonox::GUIManager::inDevMode ( void  )
static

Helper method to get the developer's mode without having to export Core.h.

See also
Core::inDevMode
void orxonox::GUIManager::keyESC ( )
void orxonox::GUIManager::loadGUI ( const std::string &  name)

Loads a GUI sheet by Lua script.

Parameters
nameThe name of the GUI (like the script name, but without the extension)
void orxonox::GUIManager::mouseLeft ( )
private

Indicates that the mouse left the application's window.

void orxonox::GUIManager::mouseMoved ( IntVector2  abs,
IntVector2  rel,
IntVector2  clippingSize 
)
overrideprivatevirtual

Reimplemented from orxonox::InputHandler.

void orxonox::GUIManager::mouseScrolled ( int  abs,
int  rel 
)
overrideprivatevirtual

Reimplemented from orxonox::InputHandler.

GUIManager& orxonox::GUIManager::operator= ( const GUIManager )
privatedelete
static bool orxonox::GUIManager::preloadMenuSheets ( )
inlinestatic
void orxonox::GUIManager::preUpdate ( const Clock time)

used to tick the GUI

Parameters
timeclock which provides time value for the GUI System

Ticking the GUI means updating it with a certain regularity. The elapsed time since the last call is given in the time value provided by the clock. This time value is then used to provide a fluent animation of the GUI.

template<typename FunctionType , typename ObjectType >
bool orxonox::GUIManager::protectedCall ( FunctionType  function,
ObjectType  object 
)
private

Executes a CEGUI function normally, but catches CEGUI::ScriptException.

When a ScriptException occurs, the error message will be displayed and the program carries on.

Remarks
The exception behaviour may pose problems if the code is not written exception-safe (and you can forget about that in Lua). The program might be left in an undefined state. But otherwise one script error would terminate the whole program...
Note
Your life gets easier if you use std::bind to create the object/function.
Parameters
functionAny callable object/function that takes this->guiSystem_ as its only parameter.
Returns
True if input was handled, false otherwise. A caught exception yields true.
Parameters
functionAny callable object/function that takes one parameter.
objectObject to be used as an argument for the function
Returns
True if input was handled, false otherwise. A caught exception yields true.
template<typename FunctionType >
bool orxonox::GUIManager::protectedCeguiSystemCall ( FunctionType  function)
private

Executes a CEGUI function normally, but catches CEGUI::ScriptException.

When a ScriptException occurs, the error message will be displayed and the program carries on.

Remarks
The exception behaviour may pose problems if the code is not written exception-safe (and you can forget about that in Lua). The program might be left in an undefined state. But otherwise one script error would terminate the whole program...
Note
Your life gets easier if you use std::bind to create the object/function.
Parameters
functionAny callable object/function that takes this->guiSystem_ as its only parameter.
Returns
True if input was handled, false otherwise. A caught exception yields true.
void orxonox::GUIManager::setBackgroundImage ( const std::string &  imageSet,
const std::string  imageName 
)
void orxonox::GUIManager::setBackgroundImage ( const std::string &  image)
void orxonox::GUIManager::setCamera ( Ogre::Camera *  camera)

Tells the GUIManager which SceneManager to use.

Parameters
cameraThe current camera on which the GUI should be displayed on.

In fact the GUIManager needs the SceneManager and not the Camera to display the GUI. This means the GUI is not bound to a camera but rather to the SceneManager. Hiding the GUI when needed can therefore not be resolved by just NOT setting the current camera.

void orxonox::GUIManager::setConfigValues ( void  )
void orxonox::GUIManager::setItemTooltipsEnabledHelper ( CEGUI::Listbox *  listbox,
bool  enabled 
)
static

Set whether the tooltips for the input Listbox are enabled.

Parameters
listboxThe Listbox for which to enable (or disable) tooltips.
enabledWhether to enable or disable the tooltips.
void orxonox::GUIManager::setPlayer ( const std::string &  guiname,
PlayerInfo player 
)
inline
void orxonox::GUIManager::setTooltipTextHelper ( CEGUI::ListboxItem *  item,
const std::string &  tooltip 
)
static

Set the input tooltip text for the input ListboxItem.

Parameters
itemThe ListboxItem for which the tooltip should be set.
tooltipThe tooltip text that should be set.
void orxonox::GUIManager::showGUI ( const std::string &  name,
bool  bHidePrevious = false,
bool  bNoInput = false 
)
static

Displays specified GUI on screen.

Parameters
nameThe name of the GUI
bHidePreviousIf true all displayed GUIs on the stack, that are below this GUI are hidden.
bNoInputIf true the GUI is transparent to input.

The function executes the Lua function with the same name in case the GUIManager is ready.

void orxonox::GUIManager::showGUIExtra ( const std::string &  name,
const std::string &  ptr,
bool  bHidePrevious = false,
bool  bNoInput = false 
)

Hack-ish.

Needed for GUIOverlay.

void orxonox::GUIManager::subscribeEventHelper ( CEGUI::Window *  window,
const std::string &  event,
const std::string &  function 
)
static

Subscribe the input function to the input event for the input window.

This is a helper to be used in lua, because subscribeScriptedEvent() doesn't work in lua.

Parameters
windowThe window for which the event is subscribed.
eventThe type of event to which we subscribe.
functionThe function that is called when the event occurs.
void orxonox::GUIManager::toggleGUI ( const std::string &  name,
bool  bHidePrevious = false,
bool  bNoInput = false 
)
static

Toggles specified GUI.

If the GUI with the input name is already shown and on the top, it is hidden, else it is shown.

void orxonox::GUIManager::toggleGUIHelper ( const std::string &  name,
bool  bHidePrevious,
bool  bNoInput,
bool  show 
)

Helper method to toggle a specified GUI.

Is called by lua.

bool orxonox::GUIManager::usingOldCEGUI ( void  )
inline

Check whether CEGUI is version < 0.7.

Returns
Returns true if the CEGUI version is < 0.7. False otherwise.
void orxonox::GUIManager::windowFocusChanged ( bool  bFocus)
overrideprivatevirtual

Notify CEGUI if the windows loses the focus (stops highlighting of menu items, etc).

Reimplemented from orxonox::WindowEventListener.

void orxonox::GUIManager::windowResized ( unsigned int  newWidth,
unsigned int  newHeight 
)
overrideprivatevirtual

Callback of window event listener, called if the window is resized.

Sets the display size of CEGUI.

Reimplemented from orxonox::WindowEventListener.

Friends And Related Function Documentation

friend class Singleton< GUIManager >
friend

Member Data Documentation

bool orxonox::GUIManager::bPreloadMenuSheets_
private

If true, menu sheets are pre-loaded during startup.

Ogre::Camera* orxonox::GUIManager::camera_
private

Camera used to render the scene with the GUI.

CEGUI::Logger* orxonox::GUIManager::ceguiLogger_
private

CEGUI's logger to be able to log CEGUI errors in our log.

const std::string orxonox::GUIManager::defaultScheme_ = "TaharezGreen"
staticprivate
DestructionHelper<GUIManager> orxonox::GUIManager::destructionHelper_
private

Helper object that executes the surrogate destructor destroy()

CEGUI::OgreCEGUIRenderer* orxonox::GUIManager::guiRenderer_
private

CEGUI's interface to the Ogre Engine.

std::string orxonox::GUIManager::guiScheme_
private
CEGUI::System* orxonox::GUIManager::guiSystem_
private

CEGUI's main system.

CEGUI::Window* orxonox::GUIManager::hudRootWindow_
private

Root node for the HUD sheets.

LuaState* orxonox::GUIManager::luaState_
private

LuaState, access point to the Lua engine.

CEGUI::Window* orxonox::GUIManager::menuRootWindow_
private

Root node for the menu sheets (used by Lua)

int orxonox::GUIManager::numScrollLines_
private

How many lines to scroll in a list if the scroll wheel is used.

bool orxonox::GUIManager::oldCEGUI_
private
int orxonox::GUIManager::outputLevelCeguiLog_
private

CEGUI's log level.

std::map<std::string, PlayerInfo*> orxonox::GUIManager::players_
private

Stores the player (owner) for each GUI.

CEGUI::ResourceProvider* orxonox::GUIManager::resourceProvider_
private

CEGUI's resource provider.

std::shared_ptr<ResourceInfo> orxonox::GUIManager::rootFileInfo_
private

Resource information about the root script.

CEGUI::Window* orxonox::GUIManager::rootWindow_
private

Root node for all windows.

CEGUI::LuaScriptModule* orxonox::GUIManager::scriptModule_
private

CEGUI's script module to use Lua.

GUIManager * orxonox::GUIManager::singletonPtr_s = nullptr
staticprivate

Singleton reference to GUIManager.


The documentation for this class was generated from the following files: