TGUI  0.9.5
Loading...
Searching...
No Matches

Gui class for the SFML backend. More...

#include <TGUI/Backends/SFML/GuiSFML.hpp>

Inheritance diagram for tgui::GuiSFML:
tgui::GuiBase

Public Member Functions

 GuiSFML ()
 Default constructor.
 
 GuiSFML (sf::RenderTarget &target)
 Constructs the gui and set the target on which the gui should be drawn.
 
void setTarget (sf::RenderTarget &target)
 Sets the target on which the gui should be drawn.
 
sf::RenderTarget * getTarget () const
 Returns the render target on which the gui is being drawn.
 
bool handleEvent (sf::Event event)
 Passes the event to the widgets.
 
void draw () override
 Draws all the widgets that were added to the gui.
 
void mainLoop () override
 Give the gui control over the main loop.
 
bool convertEvent (const sf::Event &eventSFML, Event &eventTGUI)
 Helper function that converts an SFML event to a TGUI event.
 
bool handleEvent (Event event)
 Passes the event to the widgets.
 
- Public Member Functions inherited from tgui::GuiBase
 GuiBase (const GuiBase &copy)=delete
 
GuiBaseoperator= (const GuiBase &right)=delete
 
void setAbsoluteViewport (const FloatRect &viewport)
 Sets the part of the screen to which the gui will render in pixels.
 
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.
 
RelFloatRect getViewport () const
 Returns to which part of the screen the gui will render.
 
void setAbsoluteView (const FloatRect &view)
 Sets the part of the gui that will be used to fill the viewport in pixels.
 
void setRelativeView (const FloatRect &view)
 Sets the part of the gui that will be used to fill the viewport.
 
RelFloatRect getView () const
 Returns the part of the gui that will be used to fill the viewport.
 
bool handleEvent (Event event)
 Passes the event to the widgets.
 
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)
 
RootContainer::Ptr getContainer () const
 Returns the internal container of the Gui.
 
void setFont (const Font &font)
 Changes the global font.
 
Font getFont () const
 Returns the global font for this gui.
 
const std::vector< Widget::Ptr > & getWidgets () const
 Returns a list of all the widgets.
 
void add (const Widget::Ptr &widgetPtr, const String &widgetName="")
 Adds a widget to the container.
 
Widget::Ptr get (const String &widgetName) const
 Returns a pointer to an earlier created widget.
 
template<class T >
T::Ptr get (const String &widgetName) const
 Returns a pointer to an earlier created widget.
 
bool remove (const Widget::Ptr &widget)
 Removes a single widget that was added to the container.
 
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.
 
Widget::Ptr getFocusedLeaf () const
 Returns the leaf child widget that is focused inside this container.
 
Widget::Ptr getWidgetAtPosition (Vector2f pos) const
 Returns the leaf child widget that is located at the given position.
 
Widget::Ptr getWidgetBelowMouseCursor (Vector2i mousePos) const
 Returns the leaf child widget below the mouse.
 
bool focusNextWidget (bool recursive=true)
 Focuses the next widget in the gui.
 
bool focusPreviousWidget (bool recursive=true)
 Focuses the previous widget in the gui.
 
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.
 
void moveWidgetToBack (const Widget::Ptr &widget)
 Places a widget behind all other widgets, to the back of the z-order.
 
std::size_t moveWidgetForward (const Widget::Ptr &widget)
 Places a widget one step forward in the z-order.
 
std::size_t moveWidgetBackward (const Widget::Ptr &widget)
 Places a widget one step backward in the z-order.
 
bool setWidgetIndex (const Widget::Ptr &widget, std::size_t index)
 Changes the index of a widget in this container.
 
int getWidgetIndex (const Widget::Ptr &widget) const
 Returns the current index of a widget in this container.
 
void setOpacity (float opacity)
 Changes the opacity of all widgets.
 
float getOpacity () const
 Returns the opacity of all the widgets.
 
void setTextSize (unsigned int size)
 Changes the character size of all existing and future child widgets.
 
unsigned int getTextSize () const
 Returns the character size for future child widgets (and for existing widgets where the size wasn't changed)
 
void loadWidgetsFromFile (const String &filename, bool replaceExisting=true)
 Loads the child widgets from a text file.
 
void saveWidgetsToFile (const String &filename)
 Saves the child widgets to a text file.
 
void loadWidgetsFromStream (std::stringstream &stream, bool replaceExisting=true)
 Loads the child widgets from a string stream.
 
void loadWidgetsFromStream (std::stringstream &&stream, bool replaceExisting=true)
 Loads the child widgets from a string stream.
 
void saveWidgetsToStream (std::stringstream &stream) const
 Saves this the child widgets to a text file.
 
void setOverrideMouseCursor (Cursor::Type type)
 Overrides which cursor gets shown.
 
void restoreOverrideMouseCursor ()
 Undoes the effect of the last call to setOverrideCursor.
 
void requestMouseCursor (Cursor::Type type)
 Function that is used by widgets to change the mouse cursor.
 
void setDrawingUpdatesTime (bool drawUpdatesTime)
 Sets whether drawing the gui will automatically update the internal clock or whether the user does it manually.
 
bool updateTime ()
 Updates the internal clock (for timers, animations and blinking edit cursors)
 
bool updateTime (Duration elapsedTime)
 
Vector2f mapPixelToView (int x, int y) const
 

Protected Member Functions

void init () override
 
void updateContainerSize () override
 

Protected Attributes

std::shared_ptr< BackendRenderTargetSFML > m_renderTarget = nullptr
 
- Protected Attributes inherited from tgui::GuiBase
std::chrono::steady_clock::time_point m_lastUpdateTime
 
bool m_windowFocused = true
 
RootContainer::Ptr m_container = nullptr
 
Widget::Ptr m_visibleToolTip = nullptr
 
Duration m_tooltipTime
 
bool m_tooltipPossible = false
 
Vector2f m_toolTipRelativePos
 
Vector2f m_lastMousePos
 
RelFloatRect m_viewport {RelativeValue{0}, RelativeValue{0}, RelativeValue{1}, RelativeValue{1}}
 
RelFloatRect m_view {RelativeValue{0}, RelativeValue{0}, RelativeValue{1}, RelativeValue{1}}
 
FloatRect m_lastView
 
bool m_drawUpdatesTime = true
 
bool m_tabKeyUsageEnabled = true
 
Cursor::Type m_requestedMouseCursor = Cursor::Type::Arrow
 
std::stack< Cursor::Typem_overrideMouseCursors
 

Additional Inherited Members

- Public Attributes inherited from tgui::GuiBase
SignalFloatRect onViewChange = {"ViewChanged"}
 The view was changed. Optional parameter: new view rectangle.
 

Detailed Description

Gui class for the SFML backend.

Constructor & Destructor Documentation

◆ GuiSFML() [1/2]

tgui::GuiSFML::GuiSFML ( )

Default constructor.

Warning
If you use this constructor then you will still have to call setTarget before using the gui.

◆ GuiSFML() [2/2]

tgui::GuiSFML::GuiSFML ( sf::RenderTarget &  target)

Constructs the gui and set the target on which the gui should be drawn.

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

Member Function Documentation

◆ convertEvent()

bool tgui::GuiSFML::convertEvent ( const sf::Event &  eventSFML,
Event eventTGUI 
)

Helper function that converts an SFML event to a TGUI event.

Parameters
eventSFMLThe input SFML event
eventTGUIThe output TGUI event
Returns
Did the SFML event match on a TGUI event and has the output event been written to?

You typically don't need this function as you can call handleEvent directly with an sf::Event.

◆ draw()

void tgui::GuiSFML::draw ( )
overridevirtual

Draws all the widgets that were added to the gui.

Implements tgui::GuiBase.

◆ getTarget()

sf::RenderTarget * tgui::GuiSFML::getTarget ( ) const

Returns the render target on which the gui is being drawn.

Returns
The sfml render target that is used by the gui

◆ handleEvent() [1/2]

bool tgui::GuiBase::handleEvent ( Event  event)

Passes the event to the widgets.

Parameters
eventThe event that was polled from the window
Returns
Has the event been consumed? When this function returns false, then the event was ignored by all widgets.

◆ handleEvent() [2/2]

bool tgui::GuiSFML::handleEvent ( sf::Event  event)

Passes the event to the widgets.

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

sf::Event event;
while (window.pollEvent(event) {
gui.handleEvent(event);
}

◆ init()

void tgui::GuiSFML::init ( )
overrideprotectedvirtual

Reimplemented from tgui::GuiBase.

◆ mainLoop()

void tgui::GuiSFML::mainLoop ( )
overridevirtual

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.

You can consider this function to execute something similar (but not identical) to the following code:

while (window.isOpen())
{
while (window.waitEvent(event))
{
gui.handleEvent(event);
if (event.type == sf::Event::Closed)
window.close();
}
window.clear({240, 240, 240});
gui.draw();
window.display();
}

Implements tgui::GuiBase.

◆ setTarget()

void tgui::GuiSFML::setTarget ( sf::RenderTarget &  target)

Sets the target on which the gui should be drawn.

Parameters
targetThe render target (typically sf::RenderWindow) that will be used by the gui

◆ updateContainerSize()

void tgui::GuiSFML::updateContainerSize ( )
overrideprotectedvirtual

Reimplemented from tgui::GuiBase.


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