TGUI  0.9.4
BackendSDL.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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
26#ifndef TGUI_BACKEND_SDL_HPP
27#define TGUI_BACKEND_SDL_HPP
28
29#include <TGUI/Backend.hpp>
30#include <map>
31
33
34union SDL_Event;
35struct SDL_Window;
36struct SDL_Cursor;
37typedef unsigned int GLuint;
38
39namespace tgui
40{
41 class GuiSDL;
42 class BackendRenderTargetSDL;
43
44
48 class TGUI_API BackendSDL : public BackendBase
49 {
50 public:
51
52#ifndef TGUI_REMOVE_DEPRECATED_CODE
59 TGUI_DEPRECATED("Use GuiSDL::convertEvent instead. This function doesn't handle touch events on desktop platforms.")
60 static bool convertEvent(const SDL_Event& eventSDL, Event& eventTGUI);
61#endif
62
67
68
73
74
79 void attachGui(GuiBase* gui) override;
80
81
86 void detatchGui(GuiBase* gui) override;
87
88
94
95
100 std::shared_ptr<BackendFontBase> createFont() override;
101
102
107 std::shared_ptr<BackendTextBase> createText() override;
108
109
114 std::shared_ptr<BackendTextureBase> createTexture() override;
115
116
125 void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) override;
126
127
134
135
142 void setMouseCursor(GuiBase* gui, Cursor::Type type) override;
143
144
149 void openVirtualKeyboard(const FloatRect& inputRect) override;
150
151
155 void closeVirtualKeyboard() override;
156
157
166
167
173 void setClipboard(const String& contents) override;
174
175
181 String getClipboard() const override;
182
183#ifdef TGUI_SYSTEM_ANDROID
192 std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const override;
193#endif
194
203 std::shared_ptr<BackendRenderTargetSDL> createGuiRenderTarget(GuiSDL* gui, SDL_Window* window);
204
205
215 void changeTexture(GLuint textureId, bool force);
216
217
219 private:
220
222 // Helper function to create a system cursor
224 SDL_Cursor* createSystemCursor(Cursor::Type type);
225
226
228 // Helper function to update the mouse cursors on all attached guis
230 void updateMouseCursorStyle(Cursor::Type type, SDL_Cursor* cursor);
231
232
234 // Helper function to update the mouse cursor on a window
236 void updateShownMouseCursor(SDL_Window* window, Cursor::Type type);
237
238
240 private:
241
242 struct GuiResources
243 {
244 SDL_Window* window = nullptr;
245 Cursor::Type mouseCursor = Cursor::Type::Arrow;
246 };
247
248 std::map<GuiBase*, GuiResources> m_guis;
249 std::map<Cursor::Type, SDL_Cursor*> m_mouseCursors;
250
251 GLuint m_currentTexture = 0;
252 };
253
255}
256
258
259#endif // TGUI_BACKEND_SDL_HPP
Base class for the backend.
Definition: Backend.hpp:83
Backend that uses SDL.
Definition: BackendSDL.hpp:49
void resetMouseCursorStyle(Cursor::Type type) override
Changes the look of a certain mouse cursor back to the system theme.
void closeVirtualKeyboard() override
Closes the virtual keyboard on Android and iOS.
void attachGui(GuiBase *gui) override
Informs the backend that a new gui object has been created.
void detatchGui(GuiBase *gui) override
Informs the backend that a gui object is being destroyed.
bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) override
Checks the state for one of the modifier keys.
~BackendSDL()
Destructor.
std::shared_ptr< BackendFontBase > createFont() override
Creates a new font object.
void setClipboard(const String &contents) override
Changes the contents of the clipboard.
std::shared_ptr< BackendTextBase > createText() override
Creates a new text object.
void setMouseCursorStyle(Cursor::Type type, const std::uint8_t *pixels, Vector2u size, Vector2u hotspot) override
Changes the look of a certain mouse cursor by using a bitmap.
void setMouseCursor(GuiBase *gui, Cursor::Type type) override
Changes the mouse cursor when the mouse is on top of the window to which the gui is attached.
BackendSDL()
Default constructor.
String getClipboard() const override
Returns the contents of the clipboard.
std::shared_ptr< BackendRenderTargetSDL > createGuiRenderTarget(GuiSDL *gui, SDL_Window *window)
Sets the SDL window to which the gui will render and returns a new render target object to interact w...
void changeTexture(GLuint textureId, bool force)
Changes the bound texture if another texture was currently set.
std::shared_ptr< BackendTextureBase > createTexture() override
Creates a new texture object.
Font createDefaultFont() override
Creates and returns the default font for all widgets.
void openVirtualKeyboard(const FloatRect &inputRect) override
Opens the virtual keyboard on Android and iOS.
Type
List of available cursors.
Definition: Cursor.hpp:48
@ Arrow
Arrow cursor (default)
Definition: Font.hpp:56
Base class for the Gui.
Definition: GuiBase.hpp:45
Gui class for the SDL backend.
Definition: GuiSDL.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Event.hpp:37
KeyModifier
Modifiers keys.
Definition: Event.hpp:156