TGUI  0.8.9
tgui::Gui Class Reference

Gui class. More...

#include <TGUI/Gui.hpp>

Public Member Functions

 Gui ()
 Default constructor. More...
 
 Gui (sf::RenderTarget &target)
 Constructs the gui and set the target on which the gui should be drawn. More...
 
void setTarget (sf::RenderTarget &target)
 Sets the target on which the gui should be drawn. More...
 
sf::RenderTarget * getTarget () const
 Returns the render target on which the gui is being drawn. More...
 
void setView (const sf::View &view)
 Changes the view that is used by the gui. More...
 
const sf::View & getView () const
 Returns the view that is currently used by the gui. More...
 
bool handleEvent (sf::Event event)
 Passes the event to the widgets. More...
 
void enableTabKeyUsage ()
 While tab key usage is enabled (default), pressing tab will focus another widget.
 
void disableTabKeyUsage ()
 When disabling the tab key usage, pressing tab will no longer focus another widget.
 
void setTabKeyUsageEnabled (bool enabled)
 When the tab key usage is enabled, pressing tab will focus another widget.
 
bool isTabKeyUsageEnabled () const
 Returns whether the tab key usage is enabled (if so, pressing tab will focus another widget)
 
void draw ()
 Draws all the widgets that were added to the gui.
 
GuiContainer::Ptr getContainer () const
 Returns the internal container of the Gui. More...
 
void setFont (const Font &font)
 Changes the global font. More...
 
std::shared_ptr< sf::Font > getFont () const
 Returns the global font. More...
 
const std::vector< Widget::Ptr > & getWidgets () const
 Returns a list of all the widgets. More...
 
const std::vector< sf::String > getWidgetNames () const
 Returns a list of the names of all the widgets. More...
 
void add (const Widget::Ptr &widgetPtr, const sf::String &widgetName="")
 Adds a widget to the container. More...
 
Widget::Ptr get (const sf::String &widgetName) const
 Returns a pointer to an earlier created widget. More...
 
template<class T >
T::Ptr get (const sf::String &widgetName) const
 Returns a pointer to an earlier created widget. More...
 
bool remove (const Widget::Ptr &widget)
 Removes a single widget that was added to the container. More...
 
void removeAllWidgets ()
 Removes all widgets that were added to the container.
 
Widget::Ptr getFocusedChild () const
 Returns the child widget that is focused inside this container. More...
 
Widget::Ptr getFocusedLeaf () const
 Returns the leaf child widget that is focused inside this container. More...
 
Widget::Ptr getWidgetAtPosition (sf::Vector2f pos) const
 Returns the leaf child widget that is located at the given position. More...
 
Widget::Ptr getWidgetBelowMouseCursor (sf::Vector2i mousePos) const
 Returns the leaf child widget below the mouse. More...
 
bool setWidgetName (const Widget::Ptr &widget, const std::string &name)
 Changes the name of a widget. More...
 
std::string getWidgetName (const Widget::Ptr &widget) const
 Returns the name of a widget. More...
 
bool focusNextWidget (bool recursive=true)
 Focuses the next widget in the gui. More...
 
bool focusPreviousWidget (bool recursive=true)
 Focuses the previous widget in the gui. More...
 
void unfocusAllWidgets ()
 Unfocus all the widgets.
 
void moveWidgetToFront (const Widget::Ptr &widget)
 Places a widget before all other widgets, to the front of the z-order. More...
 
void moveWidgetToBack (const Widget::Ptr &widget)
 Places a widget behind all other widgets, to the back of the z-order. More...
 
std::size_t moveWidgetForward (const Widget::Ptr &widget)
 Places a widget one step forward in the z-order. More...
 
std::size_t moveWidgetBackward (const Widget::Ptr &widget)
 Places a widget one step backward in the z-order. More...
 
void uncheckRadioButtons ()
 Unchecks all the radio buttons.
 
void setOpacity (float opacity)
 Changes the opacity of all widgets. More...
 
float getOpacity () const
 Returns the opacity of all the widgets. More...
 
void setTextSize (unsigned int size)
 Changes the character size of all existing and future child widgets. More...
 
unsigned int getTextSize () const
 Returns the character size for future child widgets (and for existing widgets where the size wasn't changed) More...
 
void loadWidgetsFromFile (const std::string &filename, bool replaceExisting=true)
 Loads the child widgets from a text file. More...
 
void saveWidgetsToFile (const std::string &filename)
 Saves the child widgets to a text file. More...
 
void loadWidgetsFromStream (std::stringstream &stream, bool replaceExisting=true)
 Loads the child widgets from a string stream. More...
 
void loadWidgetsFromStream (std::stringstream &&stream, bool replaceExisting=true)
 Loads the child widgets from a string stream. More...
 
void saveWidgetsToStream (std::stringstream &stream) const
 Saves this the child widgets to a text file. More...
 
void setDrawingUpdatesTime (bool drawUpdatesTime)
 Sets whether drawing the gui will automatically update the internal clock or whether the user does it manually. More...
 
bool updateTime ()
 Updates the internal clock (for animations and blinking edit cursors) More...
 

Detailed Description

Gui class.

Constructor & Destructor Documentation

◆ Gui() [1/2]

tgui::Gui::Gui ( )

Default constructor.

If you use this constructor then you will still have to call the setTarget yourself.

◆ Gui() [2/2]

tgui::Gui::Gui ( sf::RenderTarget &  target)

Constructs the gui and set the target on which the gui should be drawn.

Parameters
targetThe render target (typically sf::RenderWindow) that will be used by the gui

If you use this constructor then you will no longer have to call setTarget yourself.

Member Function Documentation

◆ add()

void tgui::Gui::add ( const Widget::Ptr widgetPtr,
const sf::String &  widgetName = "" 
)

Adds a widget to the container.

Parameters
widgetPtrPointer to the widget you would like to add
widgetNameIf you want to access the widget later then you must do this with this name
Warning
The widget name should not contain whitespace

◆ focusNextWidget()

bool tgui::Gui::focusNextWidget ( bool  recursive = true)

Focuses the next widget in the gui.

Parameters
recursiveIf the focused widget is a container, should the next widget inside it be focused instead of focusing the sibling of the container?
Returns
Whether a new widget was focused

◆ focusPreviousWidget()

bool tgui::Gui::focusPreviousWidget ( bool  recursive = true)

Focuses the previous widget in the gui.

Parameters
recursiveIf the focused widget is a container, should the next widget inside it be focused instead of focusing the sibling of the container?
Returns
Whether a new widget was focused

◆ get() [1/2]

Widget::Ptr tgui::Gui::get ( const sf::String &  widgetName) const

Returns a pointer to an earlier created widget.

Parameters
widgetNameThe name that was given to the widget when it was added to the container
Returns
Pointer to the earlier created widget

The gui will first search for widgets that are direct children of it, but when none of the child widgets match the given name, a recursive search will be performed.

Warning
This function will return nullptr when an unknown widget name was passed

◆ get() [2/2]

template<class T >
T::Ptr tgui::Gui::get ( const sf::String &  widgetName) const
inline

Returns a pointer to an earlier created widget.

Parameters
widgetNameThe name that was given to the widget when it was added to the container
Returns
Pointer to the earlier created widget. The pointer will already be casted to the desired type

The gui will first search for widgets that are direct children of it, but when none of the child widgets match the given name, a recursive search will be performed.

Warning
This function will return nullptr when an unknown widget name was passed

◆ getContainer()

GuiContainer::Ptr tgui::Gui::getContainer ( ) const

Returns the internal container of the Gui.

This could be useful when having a function that should accept both the gui and e.g. a child window as parameter.

Warning
Not all functions in the Container class make sense for the Gui (which is the reason that the Gui does not inherit from Container). So calling some functions (e.g. setSize) will have no effect.
Returns
Reference to the internal Container class

◆ getFocusedChild()

Widget::Ptr tgui::Gui::getFocusedChild ( ) const

Returns the child widget that is focused inside this container.

Returns
Focused child widget or nullptr if none of the widgets are currently focused

If the focused widget is a container then a pointer to that container is returned. If you want to know which widget is focused inside that container (recursively) then you should use the getFocusedLeaf() function.

◆ getFocusedLeaf()

Widget::Ptr tgui::Gui::getFocusedLeaf ( ) const

Returns the leaf child widget that is focused inside this container.

Returns
Focused leaf child widget or nullptr if none of the widgets are currently focused

If the focused widget is a container then the getFocusedLeaf() is recursively called on that container. If you want to limit the search to only direct children of this container then you should use the getFocusedChild() function.

◆ getFont()

std::shared_ptr< sf::Font > tgui::Gui::getFont ( ) const

Returns the global font.

Returns
global font

◆ getOpacity()

float tgui::Gui::getOpacity ( ) const

Returns the opacity of all the widgets.

Returns
The opacity of the widgets. 0 means completely transparent, while 1 (default) means fully opaque

◆ getTarget()

sf::RenderTarget * tgui::Gui::getTarget ( ) const

Returns the render target on which the gui is being drawn.

Returns
The sfml render target that is used by the gui

◆ getTextSize()

unsigned int tgui::Gui::getTextSize ( ) const

Returns the character size for future child widgets (and for existing widgets where the size wasn't changed)

Returns
The current text size or 0 when no size was explicitly set in this gui

◆ getView()

const sf::View & tgui::Gui::getView ( ) const

Returns the view that is currently used by the gui.

Returns
Currently set view

◆ getWidgetAtPosition()

Widget::Ptr tgui::Gui::getWidgetAtPosition ( sf::Vector2f  pos) const

Returns the leaf child widget that is located at the given position.

Parameters
posThe location where the widget will be searched, relative to the gui view
Returns
Widget at the queried position, or nullptr when there is no widget at that location
See also
getWidgetBelowMouseCursor

◆ getWidgetBelowMouseCursor()

Widget::Ptr tgui::Gui::getWidgetBelowMouseCursor ( sf::Vector2i  mousePos) const

Returns the leaf child widget below the mouse.

Parameters
mousePosPosition of the mouse, in pixel coordinates, relative the the window
Returns
Widget below the mouse, or nullptr when the mouse isn't on top of any widgets
See also
getWidgetAtPosition

◆ getWidgetName()

std::string tgui::Gui::getWidgetName ( const Widget::Ptr widget) const

Returns the name of a widget.

Parameters
widgetWidget of which the name should be retrieved
Returns
Name of the widget or an empty string when the widget didn't exist or wasn't given a name

◆ getWidgetNames()

const std::vector< sf::String > tgui::Gui::getWidgetNames ( ) const

Returns a list of the names of all the widgets.

Returns
Vector of all widget names

◆ getWidgets()

const std::vector< Widget::Ptr > & tgui::Gui::getWidgets ( ) const

Returns a list of all the widgets.

Returns
Vector of all widget pointers

◆ handleEvent()

bool tgui::Gui::handleEvent ( sf::Event  event)

Passes the event to the widgets.

Parameters
eventThe event that was polled from the gui
Returns
Has the event been consumed? When this function returns false, then the event was ignored by all widgets.

You should call this function in your event loop.

◆ loadWidgetsFromFile()

void tgui::Gui::loadWidgetsFromFile ( const std::string &  filename,
bool  replaceExisting = true 
)

Loads the child widgets from a text file.

Parameters
filenameFilename of the widget file
replaceExistingRemove existing widgets first if there are any

◆ loadWidgetsFromStream() [1/2]

void tgui::Gui::loadWidgetsFromStream ( std::stringstream &&  stream,
bool  replaceExisting = true 
)

Loads the child widgets from a string stream.

Parameters
streamstringstream that contains the widget file
replaceExistingRemove existing widgets first if there are any

◆ loadWidgetsFromStream() [2/2]

void tgui::Gui::loadWidgetsFromStream ( std::stringstream &  stream,
bool  replaceExisting = true 
)

Loads the child widgets from a string stream.

Parameters
streamstringstream that contains the widget file
replaceExistingRemove existing widgets first if there are any

◆ moveWidgetBackward()

std::size_t tgui::Gui::moveWidgetBackward ( const Widget::Ptr widget)

Places a widget one step backward in the z-order.

Parameters
widgetThe widget that should be moved one step backward
Returns
New index in the widgets list (one lower than the old index or the same if the widget was already at back), or getWidgets().size() if the widget was never added to this container.
See also
moveWidgetToBack

◆ moveWidgetForward()

std::size_t tgui::Gui::moveWidgetForward ( const Widget::Ptr widget)

Places a widget one step forward in the z-order.

Parameters
widgetThe widget that should be moved one step forward
Returns
New index in the widgets list (one higher than the old index or the same if the widget was already in front), or getWidgets().size() if the widget was never added to this container.
See also
moveWidgetToFront

◆ moveWidgetToBack()

void tgui::Gui::moveWidgetToBack ( const Widget::Ptr widget)

Places a widget behind all other widgets, to the back of the z-order.

Parameters
widgetThe widget that should be moved to the back

◆ moveWidgetToFront()

void tgui::Gui::moveWidgetToFront ( const Widget::Ptr widget)

Places a widget before all other widgets, to the front of the z-order.

Parameters
widgetThe widget that should be moved to the front

◆ remove()

bool tgui::Gui::remove ( const Widget::Ptr widget)

Removes a single widget that was added to the container.

Parameters
widgetPointer to the widget to remove

◆ saveWidgetsToFile()

void tgui::Gui::saveWidgetsToFile ( const std::string &  filename)

Saves the child widgets to a text file.

Parameters
filenameFilename of the widget file

◆ saveWidgetsToStream()

void tgui::Gui::saveWidgetsToStream ( std::stringstream &  stream) const

Saves this the child widgets to a text file.

Parameters
streamstringstream to which the widget file will be added

◆ setDrawingUpdatesTime()

void tgui::Gui::setDrawingUpdatesTime ( bool  drawUpdatesTime)

Sets whether drawing the gui will automatically update the internal clock or whether the user does it manually.

Parameters
drawUpdatesTimeTrue if gui.draw() updates the clock (default), false if gui.updateTime() has to be called

◆ setFont()

void tgui::Gui::setFont ( const Font font)

Changes the global font.

Parameters
fontFont to use

◆ setOpacity()

void tgui::Gui::setOpacity ( float  opacity)

Changes the opacity of all widgets.

Parameters
opacityThe opacity of the widgets. 0 means completely transparent, while 1 (default) means fully opaque

◆ setTarget()

void tgui::Gui::setTarget ( sf::RenderTarget &  target)

Sets the target on which the gui should be drawn.

Parameters
targetThe render target (typically sf::RenderWindow) that will be used by the gui

◆ setTextSize()

void tgui::Gui::setTextSize ( unsigned int  size)

Changes the character size of all existing and future child widgets.

Parameters
sizeThe new text size

The text size specified in this function overrides the global text size property. By default, the gui does not pass any text size to the widgets and the widgets will use the global text size as default value.

◆ setView()

void tgui::Gui::setView ( const sf::View &  view)

Changes the view that is used by the gui.

Parameters
viewThe new view

◆ setWidgetName()

bool tgui::Gui::setWidgetName ( const Widget::Ptr widget,
const std::string &  name 
)

Changes the name of a widget.

Parameters
widgetWidget of which the name should be changed
nameNew name for the widget
Returns
True when the name was changed, false when the widget wasn't part of this container

◆ updateTime()

bool tgui::Gui::updateTime ( )

Updates the internal clock (for animations and blinking edit cursors)

Returns
True if the the contents of the screen changed, false if nothing changed

You do not need to call this function unless you set DrawingUpdatesTime to false (it is true by default).


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