TGUI 1.14-dev
Loading...
Searching...
No Matches

Gui class for SDL + FreeType, using Vulkan for rendering. More...

#include <TGUI/Backend/SDL-Vulkan.hpp>

Inheritance diagram for tgui::SDL_VULKAN::Gui:
tgui::BackendGuiSDL tgui::BackendGui

Public Member Functions

 Gui ()
 Default constructor.
 Gui (SDL_Window *window, const VulkanContext &vulkanContext)
 Constructor that immediately sets the window and Vulkan objects with which the gui should be drawn.
 ~Gui () override
 Destructor.
void setWindow (SDL_Window *window, const VulkanContext &vulkanContext)
 Sets the window and Vulkan objects with which the gui should be drawn.
void setRenderPass (VkRenderPass renderPass, VkFormat colorFormat, std::uint32_t maxFramesInFlight, std::uint32_t subpass=0, VkSampleCountFlagBits samples=VK_SAMPLE_COUNT_1_BIT)
 Informs the gui about the render pass in which draw(cmdBuffer) will be called.
void setDynamicRenderingFormats (VkFormat colorFormat, std::uint32_t maxFramesInFlight, VkFormat depthFormat=VK_FORMAT_UNDEFINED, VkFormat stencilFormat=VK_FORMAT_UNDEFINED, VkSampleCountFlagBits samples=VK_SAMPLE_COUNT_1_BIT)
 Informs the gui that draw(cmdBuffer) will be called while using dynamic rendering (vkCmdBeginRendering).
void draw () override
 This function is not used by this backend, use draw(VkCommandBuffer) instead.
void draw (VkCommandBuffer cmdBuffer)
 Draws all the widgets that were added to the gui.
void mainLoop (Color clearColor={240, 240, 240}) override
 Give the gui control over the main loop.
Public Member Functions inherited from tgui::BackendGuiSDL
 BackendGuiSDL ()=default
 Default constructor.
bool handleEvent (const SDL_Event &event)
 Passes the event to the widgets.
bool convertEvent (const SDL_Event &eventSDL, Event &eventTGUI)
 Helper function that converts an SDL event to a TGUI event.
SDL_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 may result in the software keyboard being opened.
void stopTextInput () override
 This function is called by TGUI when unfocusing a text field (EditBox or TextArea). It may result in the software keyboard being closed.
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.
Public Member Functions inherited from tgui::BackendGui
 BackendGui ()
 Default constructor.
 BackendGui (const BackendGui &copy)=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).
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 loadWidgetsFromFile (const String &filename, const FormLoadOptions &options)
 Loads the child widgets from a text file.
void saveWidgetsToFile (const String &filename) const
 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 loadWidgetsFromStream (std::stringstream &stream, const FormLoadOptions &options)
 Loads the child widgets from a string stream with load options.
void loadWidgetsFromStream (std::stringstream &&stream, const FormLoadOptions &options)
 Loads the child widgets from a string stream with load options.
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 renderFrame (Color clearColor) override
 Clears the window, draws the gui and then presents the frame.
void presentScreen () override
 Not used by this backend.
void createSwapchain ()
 Creates a new surface and swapchain for the window, replacing the existing ones.
Protected Member Functions inherited from tgui::BackendGuiSDL
void setGuiWindow (SDL_Window *window)
 Sets the window on which the gui should be drawn.
void updateContainerSize () override
Protected Member Functions inherited from tgui::BackendGui
bool handleTwoFingerScroll (bool wasAlreadyScrolling)

Protected Attributes

std::unique_ptr< SwapchainVulkan > m_swapchain
Protected Attributes inherited from tgui::BackendGuiSDL
SDL_Window * m_window = nullptr
float m_dpiScale = 1
bool m_textInputStarted = false
SDL_Rect m_textInputRect = {}
bool m_touchFirstFingerDown = false
SDL_FingerID m_touchFirstFingerId = 0
SDL_TouchID m_touchFirstFingerTouchId = 0
Protected Attributes inherited from tgui::BackendGui
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
std::uintptr_t m_trackedFingerId = 0
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

Public Attributes inherited from tgui::BackendGui
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.
Static Protected Member Functions inherited from tgui::BackendGui
static Event::KeyboardKey translateKeypadKey (Event::KeyboardKey key)

Detailed Description

Gui class for SDL + FreeType, using Vulkan for rendering.

When using the mainLoop() function, TGUI will create the swapchain and surface internally. Otherwise you must call setRenderPass or setDynamicRenderingFormats once before using the draw function.

Constructor & Destructor Documentation

◆ Gui() [1/2]

tgui::SDL_VULKAN::Gui::Gui ( )

Default constructor.

Warning
You must still call setWindow on the Gui before using any TGUI functions

◆ Gui() [2/2]

tgui::SDL_VULKAN::Gui::Gui ( SDL_Window * window,
const VulkanContext & vulkanContext )

Constructor that immediately sets the window and Vulkan objects with which the gui should be drawn.

Parameters
windowThe SDL window that will be used by the gui (created with the SDL_WINDOW_VULKAN flag)
vulkanContextVulkan objects that will be used for rendering

Member Function Documentation

◆ draw() [1/2]

void tgui::SDL_VULKAN::Gui::draw ( )
inlineoverridevirtual

This function is not used by this backend, use draw(VkCommandBuffer) instead.

Reimplemented from tgui::BackendGui.

◆ draw() [2/2]

void tgui::SDL_VULKAN::Gui::draw ( VkCommandBuffer cmdBuffer)

Draws all the widgets that were added to the gui.

Parameters
cmdBufferCommand buffer to record the draw commands in, which must be inside an active render pass

This function should be called once per frame. The command buffer has to be submitted to the queue that was passed to the gui. Before calling this function, setRenderPass or setDynamicRenderingFormats must have been called.

Warning
Bound pipeline, vertex buffer, index buffer and descriptor sets will be changed by this function
Viewport and scissor are changed by this function. The scissor will contain the entire window afterwards.

◆ mainLoop()

void tgui::SDL_VULKAN::Gui::mainLoop ( Color clearColor = {240, 240, 240})
overridevirtual

Give the gui control over the main loop.

Parameters
clearColorbackground color of the window

A surface and swapchain are created for the window when this function is called, and they are destroyed again before the function returns. This function can thus not be used while you have your own swapchain for the window.

See also
BackendGuiSDL::mainLoop

Reimplemented from tgui::BackendGuiSDL.

◆ presentScreen()

void tgui::SDL_VULKAN::Gui::presentScreen ( )
overrideprotectedvirtual

Not used by this backend.

Implements tgui::BackendGuiSDL.

◆ renderFrame()

void tgui::SDL_VULKAN::Gui::renderFrame ( Color clearColor)
overrideprotectedvirtual

Clears the window, draws the gui and then presents the frame.

Reimplemented from tgui::BackendGuiSDL.

◆ setDynamicRenderingFormats()

void tgui::SDL_VULKAN::Gui::setDynamicRenderingFormats ( VkFormat colorFormat,
std::uint32_t maxFramesInFlight,
VkFormat depthFormat = VK_FORMAT_UNDEFINED,
VkFormat stencilFormat = VK_FORMAT_UNDEFINED,
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT )

Informs the gui that draw(cmdBuffer) will be called while using dynamic rendering (vkCmdBeginRendering).

Parameters
colorFormatFormat of the color attachment
maxFramesInFlightMaximum number of frames that your render loop lets the GPU execute at the same time (e.g. the amount of per-frame fences that you wait on). When draw(cmdBuffer) is called, the frame that was drawn maxFramesInFlight frames earlier must have finished executing, otherwise TGUI can overwrite buffers that the GPU is still reading from. A value that is higher than needed only costs a bit of memory.
depthFormatFormat of the depth attachment, or VK_FORMAT_UNDEFINED if there is none
stencilFormatFormat of the stencil attachment, or VK_FORMAT_UNDEFINED if there is none
samplesAmount of samples of the attachments

This function doesn't need to be called when using gui.mainLoop(). Dynamic rendering requires Vulkan 1.3 or the VK_KHR_dynamic_rendering extension, and the dynamicRendering feature has to be enabled on the device. Exactly one color attachment must be used. sRGB formats are supported, but alpha blending then happens in linear space, so semi-transparent parts can look slightly different than with a UNORM format. Changing maxFramesInFlight waits until the queue is idle, so it shouldn't be changed while a command buffer in which the gui was drawn still has to be submitted.

◆ setRenderPass()

void tgui::SDL_VULKAN::Gui::setRenderPass ( VkRenderPass renderPass,
VkFormat colorFormat,
std::uint32_t maxFramesInFlight,
std::uint32_t subpass = 0,
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT )

Informs the gui about the render pass in which draw(cmdBuffer) will be called.

Parameters
renderPassRender pass that will be active when draw is called
colorFormatFormat of the color attachment of the subpass
maxFramesInFlightMaximum number of frames that your render loop lets the GPU execute at the same time (e.g. the amount of per-frame fences that you wait on). When draw(cmdBuffer) is called, the frame that was drawn maxFramesInFlight frames earlier must have finished executing, otherwise TGUI can overwrite buffers that the GPU is still reading from. A value that is higher than needed only costs a bit of memory.
subpassIndex of the subpass that will be active when draw is called
samplesAmount of samples of the color attachment

This function doesn't need to be called when using gui.mainLoop(). The subpass must have exactly one color attachment. sRGB formats are supported, but alpha blending then happens in linear space, so semi-transparent parts can look slightly different than with a UNORM format. Changing maxFramesInFlight waits until the queue is idle, so it shouldn't be changed while a command buffer in which the gui was drawn still has to be submitted.

◆ setWindow()

void tgui::SDL_VULKAN::Gui::setWindow ( SDL_Window * window,
const VulkanContext & vulkanContext )

Sets the window and Vulkan objects with which the gui should be drawn.

Parameters
windowThe SDL window that will be used by the gui (created with the SDL_WINDOW_VULKAN flag)
vulkanContextVulkan objects that will be used for rendering
Warning
The vulkanContext is ignored if the backend was already created (e.g. by another Gui object).

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