TGUI  1.6.1
Loading...
Searching...
No Matches
BackendSDL.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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_SDL_HPP
26#define TGUI_BACKEND_SDL_HPP
27
28#include <TGUI/extlibs/IncludeSDL.hpp>
29#include <TGUI/Backend/Window/SDL/BackendGuiSDL.hpp>
30
31#if !TGUI_BUILD_AS_CXX_MODULE
32 #include <TGUI/Backend/Window/Backend.hpp>
33#endif
34
35#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
36 #include <unordered_map>
37 #include <map>
38#endif
39
41
42TGUI_IGNORE_DEPRECATED_WARNINGS_START // Required for VS2017 due to inheriting a function that we deprecated
43
44TGUI_MODULE_EXPORT namespace tgui
45{
46 class TGUI_API BackendSDL : public Backend
47 {
48 public:
49
53 ~BackendSDL() override;
54
63 void setGuiWindow(BackendGui* gui, SDL_Window* window);
64
69 void detatchGui(BackendGui* gui) override;
70
79 void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) override;
80
87
94 void setMouseCursor(BackendGui* gui, Cursor::Type type) override;
95
96#ifndef TGUI_REMOVE_DEPRECATED_CODE
103 TGUI_DEPRECATED("Use BackendGui::startTextInput instead") void openVirtualKeyboard(const FloatRect& inputRect) override;
104
110 TGUI_DEPRECATED("Use BackendGui::stopTextInput instead") void closeVirtualKeyboard() override;
111#endif
112
120 TGUI_DEPRECATED("Use gui.isKeyboardModifierPressed(modifierKey) instead") TGUI_NODISCARD bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) override;
121
127 void setClipboard(const String& contents) override;
128
134 TGUI_NODISCARD String getClipboard() const override;
135
136#ifdef TGUI_SYSTEM_ANDROID
145 TGUI_NODISCARD std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const override;
146#endif
147
149 private:
150
152 // Helper function to create a system cursor
154 TGUI_NODISCARD SDL_Cursor* createSystemCursor(Cursor::Type type);
155
157 // Helper function to update the mouse cursors on all attached guis
159 void updateMouseCursorStyle(Cursor::Type type, SDL_Cursor* cursor);
160
162 // Helper function to update the mouse cursor on a window
164 void updateShownMouseCursor(SDL_Window* window, Cursor::Type type);
165
167 private:
168
169 struct GuiResources
170 {
171 SDL_Window* window = nullptr;
172 Cursor::Type mouseCursor = Cursor::Type::Arrow;
173 };
174
175 std::unordered_map<const BackendGui*, GuiResources> m_guiResources;
176 std::unordered_map<Cursor::Type, SDL_Cursor*> m_mouseCursors;
177
178#if defined(TGUI_SYSTEM_LINUX) && defined(TGUI_USE_X11) && (SDL_MAJOR_VERSION < 3) && defined(SDL_VIDEO_DRIVER_X11)
179 bool m_customCursorX11 = false;
180#endif
181 };
182
184}
185
186TGUI_IGNORE_DEPRECATED_WARNINGS_END
187
189
190#endif // TGUI_BACKEND_SDL_HPP
Base class for the Gui.
Definition BackendGui.hpp:47
Definition BackendSDL.hpp:47
void resetMouseCursorStyle(Cursor::Type type) override
Changes the look of a certain mouse cursor back to the system theme.
void detatchGui(BackendGui *gui) override
Informs the backend that a gui object is being destroyed.
void setMouseCursor(BackendGui *gui, Cursor::Type type) override
Changes the mouse cursor when the mouse is on top of the window to which the gui is attached.
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.
~BackendSDL() override
Destructor.
void setGuiWindow(BackendGui *gui, SDL_Window *window)
Informs the backend which window belongs to the gui.
Base class for the backend.
Definition Backend.hpp:87
Type
List of available cursors.
Definition Cursor.hpp:50
Wrapper class to store strings.
Definition String.hpp:96
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Definition Event.hpp:38