TGUI
0.9-dev
|
Base class for the Gui. More...
#include </home/texus/Documents/TGUI-0.9/include/TGUI/Backend/Window/BackendGui.hpp>
Public Member Functions | |
BackendGui () | |
Default constructor. | |
void | setAbsoluteViewport (const FloatRect &viewport) |
Sets the part of the screen to which the gui will render in pixels. More... | |
void | setRelativeViewport (const FloatRect &viewport) |
Sets the part of the screen to which the gui will render as a ratio relative to the window size. More... | |
RelFloatRect | getViewport () const |
Returns to which part of the screen the gui will render. More... | |
void | setAbsoluteView (const FloatRect &view) |
Sets the part of the gui that will be used to fill the viewport in pixels. More... | |
void | setRelativeView (const FloatRect &view) |
Sets the part of the gui that will be used to fill the viewport. More... | |
RelFloatRect | getView () const |
Returns the part of the gui that will be used to fill the viewport. More... | |
bool | handleEvent (Event event) |
Passes the event to the widgets. More... | |
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) | |
virtual void | draw () |
Draws all the widgets that were added to the gui. | |
RootContainer::Ptr | getContainer () const |
Returns the internal container of the Gui. More... | |
std::shared_ptr< BackendRenderTarget > | getBackendRenderTarget () const |
Returns the backend render target that is assigned to the gui. More... | |
void | setFont (const Font &font) |
Changes the global font. More... | |
Font | getFont () const |
Returns the global font for this gui. More... | |
const std::vector< Widget::Ptr > & | getWidgets () const |
Returns a list of all the widgets. More... | |
void | add (const Widget::Ptr &widgetPtr, const String &widgetName="") |
Adds a widget to the container. More... | |
Widget::Ptr | get (const String &widgetName) const |
Returns a pointer to an earlier created widget. More... | |
template<class T > | |
T::Ptr | get (const 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 (Vector2f pos) const |
Returns the leaf child widget that is located at the given position. More... | |
Widget::Ptr | getWidgetBelowMouseCursor (Vector2i mousePos) const |
Returns the leaf child widget below the mouse. 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... | |
bool | setWidgetIndex (const Widget::Ptr &widget, std::size_t index) |
Changes the index of a widget in this container. More... | |
int | getWidgetIndex (const Widget::Ptr &widget) const |
Returns the current index of a widget in this container. More... | |
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 String &filename, bool replaceExisting=true) |
Loads the child widgets from a text file. More... | |
void | saveWidgetsToFile (const 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 | setOverrideMouseCursor (Cursor::Type type) |
Overrides which cursor gets shown. More... | |
void | restoreOverrideMouseCursor () |
Undoes the effect of the last call to setOverrideCursor. More... | |
void | requestMouseCursor (Cursor::Type type) |
Function that is used by widgets to change the mouse cursor. 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 timers, animations and blinking edit cursors) More... | |
virtual void | mainLoop ()=0 |
Give the gui control over the main loop. More... | |
Public Attributes | |
SignalFloatRect | onViewChange = {"ViewChanged"} |
The view was changed. Optional parameter: new view rectangle. | |
Base class for the Gui.
void tgui::BackendGui::add | ( | const Widget::Ptr & | widgetPtr, |
const 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::BackendGui::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::BackendGui::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::BackendGui::get | ( | const 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.
std::shared_ptr< BackendRenderTarget > tgui::BackendGui::getBackendRenderTarget | ( | ) | const |
Returns the backend render target that is assigned to the gui.
RootContainer::Ptr tgui::BackendGui::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::BackendGui::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::BackendGui::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.
Font tgui::BackendGui::getFont | ( | ) | const |
Returns the global font for this gui.
float tgui::BackendGui::getOpacity | ( | ) | const |
Returns the opacity of all the widgets.
unsigned int tgui::BackendGui::getTextSize | ( | ) | const |
Returns the character size for future child widgets (and for existing widgets where the size wasn't changed)
RelFloatRect tgui::BackendGui::getView | ( | ) | const |
Returns the part of the gui that will be used to fill the viewport.
By default the view will have the same size as the viewport.
RelFloatRect tgui::BackendGui::getViewport | ( | ) | const |
Returns to which part of the screen the gui will render.
By default the viewport will fill the entire screen.
Widget::Ptr tgui::BackendGui::getWidgetAtPosition | ( | 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::BackendGui::getWidgetBelowMouseCursor | ( | Vector2i | mousePos | ) | const |
Returns the leaf child widget below the mouse.
mousePos | Position of the mouse, in pixel coordinates, relative the the window |
int tgui::BackendGui::getWidgetIndex | ( | const Widget::Ptr & | widget | ) | const |
Returns the current index of a widget in this container.
const std::vector< Widget::Ptr > & tgui::BackendGui::getWidgets | ( | ) | const |
Returns a list of all the widgets.
bool tgui::BackendGui::handleEvent | ( | Event | event | ) |
Passes the event to the widgets.
event | The event that was polled from the window |
void tgui::BackendGui::loadWidgetsFromFile | ( | const 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::BackendGui::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::BackendGui::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 |
|
pure virtual |
Give the gui control over the main loop.
This function is only intended in cases where your program only needs to respond to gui events. For multimedia applications, games, or other programs where you want a high framerate or do a lot of processing in the main loop, you should use your own main loop.
Implemented in tgui::BackendGuiGLFW, tgui::BackendGuiSDL, and tgui::BackendGuiSFML.
std::size_t tgui::BackendGui::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::BackendGui::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::BackendGui::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::BackendGui::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::BackendGui::remove | ( | const Widget::Ptr & | widget | ) |
Removes a single widget that was added to the container.
widget | Pointer to the widget to remove |
void tgui::BackendGui::requestMouseCursor | ( | Cursor::Type | type | ) |
Function that is used by widgets to change the mouse cursor.
type | The requested cursor |
This function is used to change the mouse cursor when the mouse enters or leaves a widget. If you want to choose a cursor that doesn't get changed when moving the mouse then use setOverrideMouseCursor. If an override cursor is already set then this function won't be able to change the cursor. When all overrides are removed with restoreOverrideMouseCursor then the mouse cursor will be changed to what was last requested here.
void tgui::BackendGui::restoreOverrideMouseCursor | ( | ) |
Undoes the effect of the last call to setOverrideCursor.
This function has to be called for each call to setOverrideCursor. If the stack of overriden cursors becomes empty then widgets will be able to change the cursor again.
void tgui::BackendGui::saveWidgetsToFile | ( | const String & | filename | ) |
Saves the child widgets to a text file.
filename | Filename of the widget file |
Exception | when file could not be opened for writing |
void tgui::BackendGui::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::BackendGui::setAbsoluteView | ( | const FloatRect & | view | ) |
Sets the part of the gui that will be used to fill the viewport in pixels.
view | Rect of the gui that will be stretched to fill the viewport |
No stretching will occur when the view has the same size as the viewport (default).
Example code to use the contents of the gui container from top-left (200,100) to bottom-right (600, 400) and stetch it to fill the viewport (which equals the entire window by default):
void tgui::BackendGui::setAbsoluteViewport | ( | const FloatRect & | viewport | ) |
Sets the part of the screen to which the gui will render in pixels.
viewport | Rect of the window to which the gui should draw |
Example code to render the gui on only the right side of an 800x600 window:
void tgui::BackendGui::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::BackendGui::setFont | ( | const Font & | font | ) |
Changes the global font.
font | Font to use |
void tgui::BackendGui::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::BackendGui::setOverrideMouseCursor | ( | Cursor::Type | type | ) |
Overrides which cursor gets shown.
type | Which cursor to show |
Until restoreOverrideCursor is called, the cursor will no longer be changed by widgets. If setOverrideCursor is called multiple times, the cursors are stacked and calling restoreOverrideCursor will only pop the last added cursor from the stack.
void tgui::BackendGui::setRelativeView | ( | const FloatRect & | view | ) |
Sets the part of the gui that will be used to fill the viewport.
view | Rect of the gui that will be stretched to fill the viewport, relative to the viewport size |
The default view is (0, 0, 1, 1) so that no scaling happens even when the viewport is changed.
Example code to zoom in on the gui and display everything at 2x the size:
void tgui::BackendGui::setRelativeViewport | ( | const FloatRect & | viewport | ) |
Sets the part of the screen to which the gui will render as a ratio relative to the window size.
viewport | Rect of the window to which the gui should draw, relative to the window size |
The default viewport is set to (0, 0, 1, 1) so that it fills the entire window.
Example code to render the gui on only the right side of window:
void tgui::BackendGui::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.
bool tgui::BackendGui::setWidgetIndex | ( | const Widget::Ptr & | widget, |
std::size_t | index | ||
) |
Changes the index of a widget in this container.
Widgets are drawn in the order of the list, so overlapping widgets with a higher index will appear on top of others.
widget | Widget that is to be moved to a different index |
index | New index of the widget, corresponding to the widget position after the widget has been moved |
bool tgui::BackendGui::updateTime | ( | ) |
Updates the internal clock (for timers, animations and blinking edit cursors)
You do not need to call this function unless you set DrawingUpdatesTime to false (it is true by default).