--- ---
TGUI 1.x-dev
|
Public Member Functions | |
BackendGuiSFML () | |
Default constructor. | |
~BackendGuiSFML () | |
Destructor. | |
bool | handleEvent (sf::Event event) |
Passes the event to the widgets. | |
template<typename... Ts> | |
void | handleWindowEvents (Ts &&... handlers) |
Handle all pending window events at once using callbacks, as alternative to polling events. | |
void | mainLoop (Color clearColor={240, 240, 240}) 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. | |
sf::Window * | getWindow () const |
Returns the window that was provided to the gui. | |
void | startTextInput (FloatRect inputRect) override |
This function is called by TGUI when focusing a text field (EditBox or TextArea). It will result in the software keyboard being opened on Android and iOS. | |
void | stopTextInput () override |
This function is called by TGUI when unfocusing a text field (EditBox or TextArea). It will result in the software keyboard being closed on Android and iOS. | |
void | updateTextCursorPosition (FloatRect inputRect, Vector2f caretPos) override |
This function is called by TGUI when the position of the caret changes in a text field (EditBox or TextArea). If an IME is used then this function may move the IME candidate list to the text cursor position. | |
bool | isKeyboardModifierPressed (Event::KeyModifier modifierKey) const override |
Checks the state for one of the modifier keys. | |
bool | handleEvent (Event event) |
Passes the event to the widgets. | |
![]() | |
BackendGui () | |
Default constructor. | |
BackendGui (const BackendGui ©)=delete | |
BackendGui & | operator= (const BackendGui &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) | |
virtual void | draw () |
Draws all the widgets that were added to the gui. | |
RootContainer::Ptr | getContainer () const |
Returns the internal container of the Gui. | |
std::shared_ptr< BackendRenderTarget > | getBackendRenderTarget () const |
Returns the backend render target that is assigned to 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 WidgetType> | |
WidgetType::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 | getWidgetAtPos (Vector2f pos, bool recursive) const |
Returns the widget that is located at the given position. | |
Widget::Ptr | getWidgetBelowMouseCursor (Vector2i mousePos) const |
Returns the leaf child widget below the mouse. | |
Widget::Ptr | getWidgetBelowMouseCursor (Vector2i mousePos, bool recursive) const |
Returns the widget below the mouse. | |
Vector2i | getLastMousePosition () const |
Returns the mouse position of the last mouse event that was handled by the gui. | |
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 | mapPixelToCoords (Vector2i pixel) const |
Converts the pixel coordinate to a position within the view. | |
Vector2f | mapCoordsToPixel (Vector2f coord) const |
Converts a position within the view to the corresponding pixel coordinate. | |
void | setKeyboardNavigationEnabled (bool enabled) |
Changes whether using the arrow keys can be used to navigate between widgets. | |
bool | isKeyboardNavigationEnabled () const |
Returns whether using the arrow keys can be used to navigate between widgets. | |
Protected Member Functions | |
void | setGuiWindow (sf::Window &window) |
Sets the window which the gui should use. | |
void | updateContainerSize () override |
![]() | |
bool | handleTwoFingerScroll (bool wasAlreadyScrolling) |
Event::KeyboardKey | translateKeypadKey (Event::KeyboardKey key) |
Protected Attributes | |
sf::Window * | m_window = nullptr |
bool | m_modifierKeySystemPressed = false |
bool | m_modifierKeyControlPressed = false |
bool | m_modifierKeyShiftPressed = false |
bool | m_modifierKeyAltPressed = false |
![]() | |
std::chrono::steady_clock::time_point | m_lastUpdateTime |
bool | m_windowFocused = true |
RootContainer::Ptr | m_container = std::make_shared<RootContainer>() |
Widget::Ptr | m_visibleToolTip = nullptr |
Duration | m_tooltipTime |
bool | m_tooltipPossible = false |
Vector2f | m_toolTipRelativePos |
Vector2i | m_lastMousePos |
TwoFingerScrollDetect | m_twoFingerScroll |
Vector2i | m_framebufferSize |
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 |
bool | m_keyboardNavigationEnabled = false |
Cursor::Type | m_requestedMouseCursor = Cursor::Type::Arrow |
std::stack< Cursor::Type > | m_overrideMouseCursors |
std::shared_ptr< BackendRenderTarget > | m_backendRenderTarget = nullptr |
Additional Inherited Members | |
![]() | |
SignalFloatRect | onViewChange = {"ViewChanged"} |
The view was changed. Optional parameter: new view rectangle. | |
Signal | onWindowFocus = {"WindowFocused"} |
The window sent a GainedFocus event. | |
Signal | onWindowUnfocus = {"WindowUnfocused"} |
The window sent a LostFocus event. | |
tgui::BackendGuiSFML::BackendGuiSFML | ( | ) |
Default constructor.
|
nodiscard |
Helper function that converts an SFML event to a TGUI event.
eventSFML | The input SFML event |
eventTGUI | The output TGUI event |
You typically don't need this function as you can call handleEvent directly with an sf::Event.
sf::Window * tgui::BackendGuiSFML::getWindow | ( | ) | const |
Returns the window that was provided to the gui.
bool tgui::BackendGui::handleEvent | ( | Event | event | ) |
Passes the event to the widgets.
event | The event that was polled from the window |
bool tgui::BackendGuiSFML::handleEvent | ( | sf::Event | event | ) |
Passes the event to the widgets.
event | The event that was polled from the window |
You should call this function in your event loop.
SFML 2:
SFML 3:
If you use SFML 3 and want to use window.handleEvents instead of window.pollEvent or window.waitEvent then check out the handleWindowEvents function instead.
|
inline |
Handle all pending window events at once using callbacks, as alternative to polling events.
Using SFML's window.handleEvents directly is not practical in combination with TGUI because the gui needs access to almost all events. You would thus need to have a handler for all event types and call gui.handleEvent in each one. This handleWindowEvents function can be used as alternative to window.handleEvents to do it all for you.
Call this function with any amount of parameters, each a callable that takes an event of a certain type as parameter. For each pending event in the window, the callable that takes that event as parameter is called and the handleEvent function is executed (unless the callable returned false).
The callables must always take an SFML event as first parameter, but there are 3 variations of allowed handlers: 1) A void function that only takes the event as parameter will be called after gui.handleEvent is executed. 2) A void function with the event as first parameter and a bool as second parameter will also be called after the gui.handleEvent function finished, but the bool argument will contain the return value of handleEvent. 3) A function that returns a bool and takes the event as parameter will be called before gui.handleEvent is executed. When the handler returns false, the call to handleEvent will be skipped and the gui thus ignores the event.
This function is not blocking: if there's no pending event then it will return without calling any of the handlers.
Usage:
|
nodiscardoverridevirtual |
Checks the state for one of the modifier keys.
modifierKey | The modifier key of which the state is being queried |
Reimplemented from tgui::BackendGui.
|
overridevirtual |
Give the gui control over the main loop.
clearColor | background color of the window |
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 code below.
SFML 2:
SFML 3:
Implements tgui::BackendGui.
|
protected |
Sets the window which the gui should use.
window | The SFML window that will be used by the gui |
|
overridevirtual |
This function is called by TGUI when focusing a text field (EditBox or TextArea). It will result in the software keyboard being opened on Android and iOS.
inputRect | The rectangle where text is being inputted |
Reimplemented from tgui::BackendGui.
|
overridevirtual |
This function is called by TGUI when unfocusing a text field (EditBox or TextArea). It will result in the software keyboard being closed on Android and iOS.
Reimplemented from tgui::BackendGui.
|
overrideprotectedvirtual |
Reimplemented from tgui::BackendGui.
|
overridevirtual |
This function is called by TGUI when the position of the caret changes in a text field (EditBox or TextArea). If an IME is used then this function may move the IME candidate list to the text cursor position.
inputRect | The rectangle where text is being inputted |
caretPos | Location of the text cursor, relative to the gui view |
This function currently only has effect on Windows.
Reimplemented from tgui::BackendGui.