TGUI  v0.6.10
Public Member Functions | List of all members
tgui::Gui Class Reference
Inheritance diagram for tgui::Gui:

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...
 
ContainergetContainer ()
 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...
 

Constructor & Destructor Documentation

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.

Parameters
windowThe 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.

Parameters
windowThe render target that will be used by the gui.

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

Member Function Documentation

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

Usage example:

tgui::Picture::Ptr pic(container); // Create a picture and add it to the container
container.remove(pic); // Remove the picture from the container
container.add(pic); // Add the picture to the container again
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.

Parameters
funcPointer to a free function with a reference to a Callback widget as parameter.
template<typename T >
void tgui::Gui::bindGlobalCallback ( void(T::*)(const Callback &)  func,
const T *const  classPtr 
)
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.

Parameters
funcPointer to a member function with a reference to a Callback widget as parameter.
classPtrPointer 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.

Parameters
oldWidgetA pointer to the old widget.
newWidgetNameIf you want to access the widget later then you must do this with this name
Returns
Pointer to the new widget

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2 = container.copy(pic, "picName_2");
tgui::Picture::Ptr pic3 = container.copy(container.get("picName"), "picName_3");
void tgui::Gui::draw ( bool  resetView = true)

Draws all the widgets that were added to the gui.

Parameters
resetViewReset 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.

Parameters
widgetThe 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.

Parameters
widgetNameThe name that was given to the widget when it was added to the container.
recursiveShould the function also search for widgets inside containers that are inside this container?
Returns
Pointer to the earlier created widget
Warning
This function will return nullptr when an unknown widget name was passed.

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2 = container.get("picName");
template<class T >
T::Ptr tgui::Gui::get ( const sf::String &  widgetName,
bool  recursive = false 
) 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.
recursiveShould the function also search for widgets inside containers that are inside this container?
Returns
Pointer to the earlier created widget. The pointer will already be casted to the desired type.
Warning
This function will return nullptr when an unknown widget name was passed.

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2 = container.get<tgui::Picture>("picName");
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.

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
const sf::Font& tgui::Gui::getGlobalFont ( ) const

Returns the global font.

This is the font that is used for newly created widget by default.

Returns
global font
sf::Vector2f tgui::Gui::getSize ( ) const

Returns the size of the container.

Returns
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.

Parameters
widgetWidget of which the name should be retrieved
nameName for the widget
Returns
False is returned when the widget wasn't part of this container. In this case the name parameter is left unchanged.
const std::vector<sf::String>& tgui::Gui::getWidgetNames ( )

Returns a list of the names of all the widgets.

Returns
Vector of all widget names
const std::vector< Widget::Ptr >& tgui::Gui::getWidgets ( )

Returns a list of all the widgets.

Returns
Vector of all widget pointers
sf::RenderTarget* tgui::Gui::getWindow ( ) const

Returns the window on which the gui is being drawn.

Returns
The sfml that is used by the gui.
bool tgui::Gui::handleEvent ( sf::Event  event,
bool  resetView = true 
)

Passes the event to the widgets.

Parameters
eventThe event that was polled from the gui
resetViewReset 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.
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.

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.

Returns
Is the window currently focused?
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.

Parameters
filenameFilename of the widget file that is to be loaded
Returns
  • true on success
  • false when the file could not be opened
  • false when the file contains a mistake
  • false when one of the widgets couldn't be loaded
void tgui::Gui::moveWidgetToBack ( Widget::Ptr widget)

Places a widget behind all other widgets.

Parameters
widgetThe widget that should be moved to the back
void tgui::Gui::moveWidgetToFront ( Widget::Ptr widget)

Places a widget before all other widgets.

Parameters
widgetThe 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.

Parameters
callbackAn empty tgui::Callback widget that will be (partly) filled when there is a callback.
Returns
  • true when there is another callback. The callback parameter will be filled with information.
  • false when there is no callback. The callback parameter remains uninitialized and may not be used.
void tgui::Gui::remove ( const Widget::Ptr widget)

Removes a single widget that was added to the container.

Parameters
widgetPointer to the widget to remove

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2(container, "picName2");
container.remove(pic);
container.remove(container.get("picName2"));
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.

Parameters
filenameFilename of the widget file that is to be created
Returns
  • true on success
  • false when the file couldn't 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.

Parameters
filenamePath of the font file to load
Returns
True if loading succeeded, false if it failed
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.

Parameters
fontFont to copy
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.
void tgui::Gui::setWindow ( sf::RenderWindow &  window)

Set the window on which the gui should be drawn.

Parameters
windowThe 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.

Parameters
windowThe 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.


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