TGUI  1.2.0
Loading...
Searching...
No Matches
BackendSFML.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
26#ifndef TGUI_BACKEND_SFML_HPP
27#define TGUI_BACKEND_SFML_HPP
28
29#include <TGUI/Config.hpp>
30#if !TGUI_BUILD_AS_CXX_MODULE
31 #include <TGUI/Backend/Window/Backend.hpp>
32#endif
33
34#include <TGUI/Backend/Window/SFML/BackendGuiSFML.hpp>
35
36#include <SFML/Window.hpp>
37
38#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
39 #include <unordered_map>
40 #include <map>
41#endif
42
44
45TGUI_IGNORE_DEPRECATED_WARNINGS_START // Required for VS2017 due to inheriting a function that we deprecated
46
47TGUI_MODULE_EXPORT namespace tgui
48{
49 class TGUI_API BackendSFML : public Backend
50 {
51 public:
52
61 void setGuiWindow(BackendGui* gui, sf::Window* window);
62
63
68 void detatchGui(BackendGui* gui) override;
69
70
79 void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) override;
80
81
88
89
96 void setMouseCursor(BackendGui* gui, Cursor::Type type) override;
97
98#ifndef TGUI_REMOVE_DEPRECATED_CODE
105 TGUI_DEPRECATED("Use BackendGui::startTextInput instead") void openVirtualKeyboard(const FloatRect& inputRect) override;
106
107
113 TGUI_DEPRECATED("Use BackendGui::stopTextInput instead") void closeVirtualKeyboard() override;
114#endif
115
123 TGUI_NODISCARD bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) override;
124
125
131 void setClipboard(const String& contents) override;
132
133
139 TGUI_NODISCARD String getClipboard() const override;
140
141#ifdef TGUI_SYSTEM_ANDROID
150 TGUI_NODISCARD std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const override;
151#endif
152
164 static void cleanupLeakedCursors();
165
166
168 protected:
169
171 // Helper function to create a system cursor
173 TGUI_NODISCARD std::unique_ptr<sf::Cursor> createSystemCursor(Cursor::Type type);
174
175
177 // Helper function to update the mouse cursors on all attached guis
179 void updateMouseCursor(Cursor::Type type, std::unique_ptr<sf::Cursor> cursor);
180
181
183 // Helper function to update the mouse cursor on a window
185 void updateMouseCursor(sf::Window* window, Cursor::Type type);
186
187
189 protected:
190
191 struct GuiResources
192 {
193 sf::Window* window = nullptr;
194 Cursor::Type mouseCursor = Cursor::Type::Arrow;
195 };
196
197 std::unordered_map<BackendGui*, GuiResources> m_guiResources;
198 std::unordered_map<Cursor::Type, std::unique_ptr<sf::Cursor>> m_mouseCursors;
199
200 static std::vector<std::unique_ptr<sf::Cursor>> m_leakedCursors;
201 };
202
204}
205
206TGUI_IGNORE_DEPRECATED_WARNINGS_END
207
209
210#endif // TGUI_BACKEND_SFML_HPP
Base class for the Gui.
Definition BackendGui.hpp:48
Definition BackendSFML.hpp:50
void setClipboard(const String &contents) override
Changes the contents of the clipboard.
TGUI_NODISCARD bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) override
Checks the state for one of the modifier keys.
TGUI_NODISCARD String getClipboard() const override
Returns the contents of the clipboard.
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 setGuiWindow(BackendGui *gui, sf::Window *window)
Informs the backend which window belongs to the gui.
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.
static void cleanupLeakedCursors()
Destroys any leaked cursors.
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.
Base class for the backend.
Definition Backend.hpp:91
Type
List of available cursors.
Definition Cursor.hpp:51
Wrapper class to store strings.
Definition String.hpp:101
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
KeyModifier
Modifiers keys.
Definition Event.hpp:158