TGUI
0.8.9
|
#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... | |
Gui class.
tgui::Gui::Gui | ( | ) |
Default constructor.
If you use this constructor then you will still have to call the setTarget yourself.
tgui::Gui::Gui | ( | sf::RenderTarget & | target | ) |
Constructs the gui and set the target on which the gui should be drawn.
target | The 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.
void tgui::Gui::add | ( | const Widget::Ptr & | widgetPtr, |
const sf::String & | widgetName = "" |
||
) |
Adds a widget to the container.
widgetPtr | Pointer to the widget you would like to add |
widgetName | If you want to access the widget later then you must do this with this name |
bool tgui::Gui::focusNextWidget | ( | bool | recursive = true | ) |
Focuses the next widget in the gui.
recursive | If the focused widget is a container, should the next widget inside it be focused instead of focusing the sibling of the container? |
bool tgui::Gui::focusPreviousWidget | ( | bool | recursive = true | ) |
Focuses the previous widget in the gui.
recursive | If the focused widget is a container, should the next widget inside it be focused instead of focusing the sibling of the container? |
Widget::Ptr tgui::Gui::get | ( | const sf::String & | widgetName | ) | const |
Returns a pointer to an earlier created widget.
widgetName | The name that was given to the widget when it was added to the container |
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.
|
inline |
Returns a pointer to an earlier created widget.
widgetName | The name that was given to the widget when it was added to the container |
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.
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.
Widget::Ptr tgui::Gui::getFocusedChild | ( | ) | const |
Returns the child widget that is focused inside this container.
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.
Widget::Ptr tgui::Gui::getFocusedLeaf | ( | ) | const |
Returns the leaf child widget that is focused inside this container.
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.
std::shared_ptr< sf::Font > tgui::Gui::getFont | ( | ) | const |
Returns the global font.
float tgui::Gui::getOpacity | ( | ) | const |
Returns the opacity of all the widgets.
sf::RenderTarget * tgui::Gui::getTarget | ( | ) | const |
Returns the render target on which the gui is being drawn.
unsigned int tgui::Gui::getTextSize | ( | ) | const |
Returns the character size for future child widgets (and for existing widgets where the size wasn't changed)
const sf::View & tgui::Gui::getView | ( | ) | const |
Returns the view that is currently used by the gui.
Widget::Ptr tgui::Gui::getWidgetAtPosition | ( | sf::Vector2f | pos | ) | const |
Returns the leaf child widget that is located at the given position.
pos | The location where the widget will be searched, relative to the gui view |
Widget::Ptr tgui::Gui::getWidgetBelowMouseCursor | ( | sf::Vector2i | mousePos | ) | const |
Returns the leaf child widget below the mouse.
mousePos | Position of the mouse, in pixel coordinates, relative the the window |
std::string tgui::Gui::getWidgetName | ( | const Widget::Ptr & | widget | ) | const |
Returns the name of a widget.
widget | Widget of which the name should be retrieved |
const std::vector< sf::String > tgui::Gui::getWidgetNames | ( | ) | const |
Returns a list of the names of all the widgets.
const std::vector< Widget::Ptr > & tgui::Gui::getWidgets | ( | ) | const |
Returns a list of all the widgets.
bool tgui::Gui::handleEvent | ( | sf::Event | event | ) |
Passes the event to the widgets.
event | The event that was polled from the gui |
You should call this function in your event loop.
void tgui::Gui::loadWidgetsFromFile | ( | const std::string & | filename, |
bool | replaceExisting = true |
||
) |
Loads the child widgets from a text file.
filename | Filename of the widget file |
replaceExisting | Remove existing widgets first if there are any |
void tgui::Gui::loadWidgetsFromStream | ( | std::stringstream && | stream, |
bool | replaceExisting = true |
||
) |
Loads the child widgets from a string stream.
stream | stringstream that contains the widget file |
replaceExisting | Remove existing widgets first if there are any |
void tgui::Gui::loadWidgetsFromStream | ( | std::stringstream & | stream, |
bool | replaceExisting = true |
||
) |
Loads the child widgets from a string stream.
stream | stringstream that contains the widget file |
replaceExisting | Remove existing widgets first if there are any |
std::size_t tgui::Gui::moveWidgetBackward | ( | const Widget::Ptr & | widget | ) |
Places a widget one step backward in the z-order.
widget | The widget that should be moved one step backward |
std::size_t tgui::Gui::moveWidgetForward | ( | const Widget::Ptr & | widget | ) |
Places a widget one step forward in the z-order.
widget | The widget that should be moved one step forward |
void tgui::Gui::moveWidgetToBack | ( | const Widget::Ptr & | widget | ) |
Places a widget behind all other widgets, to the back of the z-order.
widget | The widget that should be moved to the back |
void tgui::Gui::moveWidgetToFront | ( | const Widget::Ptr & | widget | ) |
Places a widget before all other widgets, to the front of the z-order.
widget | The widget that should be moved to the front |
bool tgui::Gui::remove | ( | const Widget::Ptr & | widget | ) |
Removes a single widget that was added to the container.
widget | Pointer to the widget to remove |
void tgui::Gui::saveWidgetsToFile | ( | const std::string & | filename | ) |
Saves the child widgets to a text file.
filename | Filename of the widget file |
void tgui::Gui::saveWidgetsToStream | ( | std::stringstream & | stream | ) | const |
Saves this the child widgets to a text file.
stream | stringstream to which the widget file will be added |
void tgui::Gui::setDrawingUpdatesTime | ( | bool | drawUpdatesTime | ) |
Sets whether drawing the gui will automatically update the internal clock or whether the user does it manually.
drawUpdatesTime | True if gui.draw() updates the clock (default), false if gui.updateTime() has to be called |
void tgui::Gui::setOpacity | ( | float | opacity | ) |
Changes the opacity of all widgets.
opacity | The opacity of the widgets. 0 means completely transparent, while 1 (default) means fully opaque |
void tgui::Gui::setTarget | ( | sf::RenderTarget & | target | ) |
Sets the target on which the gui should be drawn.
target | The render target (typically sf::RenderWindow) that will be used by the gui |
void tgui::Gui::setTextSize | ( | unsigned int | size | ) |
Changes the character size of all existing and future child widgets.
size | The 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.
void tgui::Gui::setView | ( | const sf::View & | view | ) |
Changes the view that is used by the gui.
view | The new view |
bool tgui::Gui::setWidgetName | ( | const Widget::Ptr & | widget, |
const std::string & | name | ||
) |
Changes the name of a widget.
widget | Widget of which the name should be changed |
name | New name for the widget |
bool tgui::Gui::updateTime | ( | ) |
Updates the internal clock (for animations and blinking edit cursors)
You do not need to call this function unless you set DrawingUpdatesTime to false (it is true by default).