TGUI 1.11
Loading...
Searching...
No Matches
BackendGuiSDL.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_BACKEND_GUI_SDL_HPP
26#define TGUI_BACKEND_GUI_SDL_HPP
27
28#include <TGUI/extlibs/IncludeSDL.hpp>
29#if SDL_MAJOR_VERSION < 3
30 #include <SDL_touch.h>
31#endif
32
33#include <TGUI/Backend/Window/BackendGui.hpp>
34
36
37namespace tgui
38{
40
41 class TGUI_API BackendGuiSDL : public BackendGui
42 {
43 public:
44
50 BackendGuiSDL() = default;
51
68 bool handleEvent(const SDL_Event& event);
70
98 void mainLoop(Color clearColor = {240, 240, 240}) override;
99
108 TGUI_NODISCARD bool convertEvent(const SDL_Event& eventSDL, Event& eventTGUI);
109
115 SDL_Window* getWindow() const;
116
123 void startTextInput(FloatRect inputRect) override;
124
129 void stopTextInput() override;
130
138 void updateTextCursorPosition(FloatRect inputRect, Vector2f caretPos) override;
139
147 TGUI_NODISCARD bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) const override;
148
150 protected:
151
157 void setGuiWindow(SDL_Window* window);
158
160 // Updates the view and changes the size of the root container when needed
162 void updateContainerSize() override;
163
165 protected:
166
170 virtual void renderFrame(Color clearColor);
171
175 virtual void presentScreen() = 0;
176
177#if ((SDL_MAJOR_VERSION == 2) && (SDL_MINOR_VERSION < 26))
181 virtual void updateFramebufferSize() = 0;
182#endif
183
185 protected:
186
187 SDL_Window* m_window = nullptr;
188 float m_dpiScale = 1;
189
190 bool m_textInputStarted = false;
191 SDL_Rect m_textInputRect = {};
192
193 bool m_touchFirstFingerDown = false;
194 SDL_FingerID m_touchFirstFingerId = 0; // Only valid if m_touchFirstFingerDown is true
195 SDL_TouchID m_touchFirstFingerTouchId = 0; // Only valid if m_touchFirstFingerDown is true
196
198 };
199}
200
202
203#endif // TGUI_BACKEND_GUI_SDL_HPP
void startTextInput(FloatRect inputRect) override
This function is called by TGUI when focusing a text field (EditBox or TextArea). It may result in th...
void mainLoop(Color clearColor={240, 240, 240}) override
Give the gui control over the main loop.
BackendGuiSDL()=default
Default constructor.
SDL_Window * getWindow() const
Returns the window that was provided to the gui.
void setGuiWindow(SDL_Window *window)
Sets the window on which the gui should be drawn.
bool convertEvent(const SDL_Event &eventSDL, Event &eventTGUI)
Helper function that converts an SDL event to a TGUI event.
bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) const override
Checks the state for one of the modifier keys.
void stopTextInput() override
This function is called by TGUI when unfocusing a text field (EditBox or TextArea)....
bool handleEvent(const SDL_Event &event)
Passes the event to the widgets.
virtual void renderFrame(Color clearColor)
Clears the screen, draws the gui and then presents the frame.
virtual void presentScreen()=0
Shows the drawn content with SDL_GL_SwapWindow or SDL_RenderPresent, depending on the renderer.
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 Te...
bool handleEvent(Event event)
Passes the event to the widgets.
BackendGui()
Default constructor.
Wrapper for colors.
Definition Color.hpp:71
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
Definition Event.hpp:38
KeyModifier
Modifiers keys.
Definition Event.hpp:157