TGUI  0.8-dev
tgui::Gui Class Reference

Gui class. More...

#include <Gui.hpp>

Public Member Functions

 Gui ()
 Default constructor. More...
 
 Gui (sf::RenderWindow &window)
 Constructs the gui and set the window on which the gui should be drawn. More...
 
 Gui (sf::RenderTarget &window)
 Constructs the gui and set the target on which the gui should be drawn. More...
 
void setWindow (sf::RenderWindow &window)
 Sets the window on which the gui should be drawn. More...
 
void setWindow (sf::RenderTarget &window)
 Sets 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...
 
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 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, 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...
 
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.
 
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...
 
void focusWidget (const 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.
 
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 loadWidgetsFromFile (const std::string &filename)
 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)
 Loads the child widgets from a string stream. More...
 
void saveWidgetsToStream (std::stringstream &stream)
 Saves this the child widgets to a text file. More...
 

Detailed Description

Gui class.

Constructor & Destructor Documentation

§ Gui() [1/3]

tgui::Gui::Gui ( )

Default constructor.

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

§ Gui() [2/3]

tgui::Gui::Gui ( sf::RenderWindow &  window)

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

§ Gui() [3/3]

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

Constructs 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

§ 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

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
Warning
The widget name should not contain whitespace

§ focusNextWidget()

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.

§ focusPreviousWidget()

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.

§ focusWidget()

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

Focuses a widget.

The previously focused widget will be unfocused.

Parameters
widgetThe widget that has to be focused

§ get() [1/2]

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");

§ get() [2/2]

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");

§ 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

§ 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

§ getView()

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

Returns the view that is currently used by the gui.

Returns
Currently set view

§ 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

§ getWindow()

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

§ 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)

Loads the child widgets from a text file.

Parameters
filenameFilename of the widget file

§ loadWidgetsFromStream()

void tgui::Gui::loadWidgetsFromStream ( std::stringstream &  stream)

Loads the child widgets from a string stream.

Parameters
streamstringstream that contains the widget file

§ 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

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2(container, "picName2");
container.remove(pic);
container.remove(container.get("picName2"));

§ 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)

Saves this the child widgets to a text file.

Parameters
streamstringstream to which the widget file will be added

§ 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

§ 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

§ setWindow() [1/2]

void tgui::Gui::setWindow ( sf::RenderWindow &  window)

Sets the window on which the gui should be drawn.

Parameters
windowThe sfml window that will be used by the gui

§ setWindow() [2/2]

void tgui::Gui::setWindow ( sf::RenderTarget &  window)

Sets the target on which the gui should be drawn.

Parameters
windowThe render target that will be used by the gui

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