TGUI
v0.6.10
|
Public Member Functions | |
Gui () | |
Default constructor. More... | |
Gui (sf::RenderWindow &window) | |
Construct the gui and set the window on which the gui should be drawn. More... | |
Gui (sf::RenderTarget &window) | |
Construct the gui and set the target on which the gui should be drawn. More... | |
void | setWindow (sf::RenderWindow &window) |
Set the window on which the gui should be drawn. More... | |
void | setWindow (sf::RenderTarget &window) |
Set the target on which the gui should be drawn. More... | |
sf::RenderTarget * | getWindow () const |
Returns the window on which the gui is being drawn. More... | |
bool | handleEvent (sf::Event event, bool resetView=true) |
Passes the event to the widgets. More... | |
void | draw (bool resetView=true) |
Draws all the widgets that were added to the gui. More... | |
bool | pollCallback (Callback &callback) |
Get the next callback from the callback queue. More... | |
bool | hasFocus () const |
Check if the window is focused. More... | |
sf::Vector2f | getSize () const |
Returns the size of the container. More... | |
Container & | getContainer () |
Returns the internal container of the Gui. More... | |
bool | setGlobalFont (const std::string &filename) |
Changes the global font. More... | |
void | setGlobalFont (const sf::Font &font) |
Changes the global font. More... | |
const sf::Font & | getGlobalFont () const |
Returns the global font. More... | |
const std::vector< Widget::Ptr > & | getWidgets () |
Returns a list of all the widgets. More... | |
const std::vector< sf::String > & | getWidgetNames () |
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, bool recursive=false) const |
Returns a pointer to an earlier created widget. More... | |
template<class T > | |
T::Ptr | get (const sf::String &widgetName, bool recursive=false) const |
Returns a pointer to an earlier created widget. More... | |
Widget::Ptr | copy (const Widget::Ptr &oldWidget, const sf::String &newWidgetName="") |
Makes a copy of any existing widget and returns the pointer to the new widget. More... | |
void | 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. More... | |
bool | setWidgetName (const Widget::Ptr &widget, const std::string &name) |
Changes the name of a widget. More... | |
bool | getWidgetName (const Widget::Ptr &widget, std::string &name) const |
Returns the name of a widget. More... | |
void | focusWidget (Widget::Ptr &widget) |
Focuses a widget. More... | |
void | focusNextWidget () |
Focuses the next widget. More... | |
void | focusPreviousWidget () |
Focuses the previous widget. More... | |
void | unfocusWidgets () |
Unfocus all the widgets. More... | |
void | uncheckRadioButtons () |
Uncheck all the radio buttons. More... | |
void | moveWidgetToFront (Widget::Ptr &widget) |
Places a widget before all other widgets. More... | |
void | moveWidgetToBack (Widget::Ptr &widget) |
Places a widget behind all other widgets. More... | |
void | bindGlobalCallback (std::function< void(const Callback &)> func) |
Bind a function to the callbacks of all child widgets. More... | |
template<typename T > | |
void | bindGlobalCallback (void(T::*func)(const Callback &), const T *const classPtr) |
Bind a function to the callbacks of all child widgets. More... | |
void | unbindGlobalCallback () |
Unbind the global callback function(s). More... | |
bool | loadWidgetsFromFile (const std::string &filename) |
Loads a form from a file. More... | |
bool | saveWidgetsToFile (const std::string &filename) |
Save the widgets to a file. More... | |
tgui::Gui::Gui | ( | ) |
Default constructor.
If you use this constructor then you will still have to call the setWindow yourself.
tgui::Gui::Gui | ( | sf::RenderWindow & | window | ) |
Construct the gui and set the window on which the gui should be drawn.
window | The sfml window that will be used by the gui. |
If you use this constructor then you will no longer have to call setWindow yourself.
tgui::Gui::Gui | ( | sf::RenderTarget & | window | ) |
Construct the gui and set the target on which the gui should be drawn.
window | The render target that will be used by the gui. |
If you use this constructor then you will no longer have to call setWindow 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 |
Usage example:
void tgui::Gui::bindGlobalCallback | ( | std::function< void(const Callback &)> | func | ) |
Bind a function to the callbacks of all child widgets.
When a child widget tells this widget about the callback then the global callback function(s) will be called. If no global callback function has been bound then the callback is passed to the parent of this widget.
func | Pointer to a free function with a reference to a Callback widget as parameter. |
|
inline |
Bind a function to the callbacks of all child widgets.
When a child widget tells this widget about the callback then the global callback function(s) will be called. If no global callback function has been bound then the callback is passed to the parent of this widget.
func | Pointer to a member function with a reference to a Callback widget as parameter. |
classPtr | Pointer to the widget of the class. |
Widget::Ptr tgui::Gui::copy | ( | const Widget::Ptr & | oldWidget, |
const sf::String & | newWidgetName = "" |
||
) |
Makes a copy of any existing widget and returns the pointer to the new widget.
oldWidget | A pointer to the old widget. |
newWidgetName | If you want to access the widget later then you must do this with this name |
Usage example:
void tgui::Gui::draw | ( | bool | resetView = true | ) |
Draws all the widgets that were added to the gui.
resetView | Reset the view of the window while drawing the gui. This parameter must be the same as the one passed to the handleEvent function. If false, the current view will be used, otherwise the view will be reset. If false then make sure the same view is set when calling this function and when calling handleEvent. |
When this function ends, the view will never be changed. Any changes to the view are temporary.
void tgui::Gui::focusNextWidget | ( | ) |
Focuses the next widget.
The currently focused widget will be unfocused, even if it was the only widget. When no widget was focused, the first widget in the container will be focused.
void tgui::Gui::focusPreviousWidget | ( | ) |
Focuses the previous widget.
The currently focused widget will be unfocused, even if it was the only widget. When no widget was focused, the last widget in the container will be focused.
void tgui::Gui::focusWidget | ( | Widget::Ptr & | widget | ) |
Focuses a widget.
The previously focused widget will be unfocused.
widget | The widget that has to be focused. |
Widget::Ptr tgui::Gui::get | ( | const sf::String & | widgetName, |
bool | recursive = false |
||
) | 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. |
recursive | Should the function also search for widgets inside containers that are inside this container? |
Usage example:
|
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. |
recursive | Should the function also search for widgets inside containers that are inside this container? |
Usage example:
Container& tgui::Gui::getContainer | ( | ) |
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.
const sf::Font& tgui::Gui::getGlobalFont | ( | ) | const |
Returns the global font.
This is the font that is used for newly created widget by default.
sf::Vector2f tgui::Gui::getSize | ( | ) | const |
Returns the size of the container.
This size will equal the size of the window.
bool tgui::Gui::getWidgetName | ( | const Widget::Ptr & | widget, |
std::string & | name | ||
) | const |
Returns the name of a widget.
widget | Widget of which the name should be retrieved |
name | Name for the widget |
const std::vector<sf::String>& tgui::Gui::getWidgetNames | ( | ) |
Returns a list of the names of all the widgets.
const std::vector< Widget::Ptr >& tgui::Gui::getWidgets | ( | ) |
Returns a list of all the widgets.
sf::RenderTarget* tgui::Gui::getWindow | ( | ) | const |
Returns the window on which the gui is being drawn.
bool tgui::Gui::handleEvent | ( | sf::Event | event, |
bool | resetView = true |
||
) |
Passes the event to the widgets.
event | The event that was polled from the gui |
resetView | Reset the view of the window while calculation the mouse coordinates. This parameter must be the same as the one passed to the draw function. If false, the current view will be used, otherwise the view will be reset. If false then make sure the same view is set when calling this function and when calling draw. |
You should call this function in your event loop.
bool tgui::Gui::hasFocus | ( | ) | const |
Check if the window is focused.
When the window is unfocused, animations (e.g. flashing caret of an edit box) will be paused.
bool tgui::Gui::loadWidgetsFromFile | ( | const std::string & | filename | ) |
Loads a form from a file.
The widgets will be loaded and added to the container. Note that even when this function fails, some widgets might have been loaded already.
filename | Filename of the widget file that is to be loaded |
void tgui::Gui::moveWidgetToBack | ( | Widget::Ptr & | widget | ) |
Places a widget behind all other widgets.
widget | The widget that should be moved to the back |
void tgui::Gui::moveWidgetToFront | ( | Widget::Ptr & | widget | ) |
Places a widget before all other widgets.
widget | The widget that should be moved to the front |
bool tgui::Gui::pollCallback | ( | Callback & | callback | ) |
Get the next callback from the callback queue.
This function works just like the pollEvent function from sfml.
The gui stores the callback of all the widgets. This function will return the next callback and then remove it from the queue.
Note that more than one callbacks may be present in the queue, thus you should always call this function in a loop to make sure that you process every callback.
callback | An empty tgui::Callback widget that will be (partly) filled when there is a callback. |
void tgui::Gui::remove | ( | const Widget::Ptr & | widget | ) |
Removes a single widget that was added to the container.
widget | Pointer to the widget to remove |
Usage example:
void tgui::Gui::removeAllWidgets | ( | ) |
Removes all widgets that were added to the container.
bool tgui::Gui::saveWidgetsToFile | ( | const std::string & | filename | ) |
Save the widgets to a file.
filename | Filename of the widget file that is to be created |
bool tgui::Gui::setGlobalFont | ( | const std::string & | filename | ) |
Changes the global font.
This font will be used by all widgets that are created after calling this function.
filename | Path of the font file to load |
void tgui::Gui::setGlobalFont | ( | const sf::Font & | font | ) |
Changes the global font.
This font will be used by all widgets that are created after calling this function.
font | Font to copy |
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 |
void tgui::Gui::setWindow | ( | sf::RenderWindow & | window | ) |
Set the window on which the gui should be drawn.
window | The sfml window that will be used by the gui. |
void tgui::Gui::setWindow | ( | sf::RenderTarget & | window | ) |
Set the target on which the gui should be drawn.
window | The render target that will be used by the gui. |
void tgui::Gui::unbindGlobalCallback | ( | ) |
Unbind the global callback function(s).
void tgui::Gui::uncheckRadioButtons | ( | ) |
Uncheck all the radio buttons.
void tgui::Gui::unfocusWidgets | ( | ) |
Unfocus all the widgets.