TGUI  0.9-dev
BackendSFML.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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/Backend/Window/Backend.hpp>
30#include <TGUI/Backend/Window/SFML/BackendGuiSFML.hpp>
31#include <SFML/Window.hpp>
32#include <unordered_map>
33#include <map>
34
36
37namespace tgui
38{
39 class TGUI_API BackendSFML : public Backend
40 {
41 public:
42
43#ifndef TGUI_REMOVE_DEPRECATED_CODE
50 TGUI_DEPRECATED("Use Gui::convertEvent instead") static bool convertEvent(const sf::Event& eventSFML, Event& eventTGUI);
51#endif
52
61 void setGuiWindow(BackendGui* gui, sf::Window* window);
62
63
68 void attachGui(BackendGui* gui) override;
69
70
75 void detatchGui(BackendGui* gui) override;
76
77
86 void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) override;
87
88
95
96
103 void setMouseCursor(BackendGui* gui, Cursor::Type type) override;
104
105
110 void openVirtualKeyboard(const FloatRect& inputRect) override;
111
112
116 void closeVirtualKeyboard() override;
117
118
127
128
134 void setClipboard(const String& contents) override;
135
136
142 String getClipboard() const override;
143
144#ifdef TGUI_SYSTEM_ANDROID
153 std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const override;
154#endif
155
157 protected:
158
160 // Helper function to create a system cursor
162 std::unique_ptr<sf::Cursor> createSystemCursor(Cursor::Type type);
163
164
166 // Helper function to update the mouse cursors on all attached guis
168 void updateMouseCursor(Cursor::Type type, std::unique_ptr<sf::Cursor> cursor);
169
170
172 // Helper function to update the mouse cursor on a window
174 void updateMouseCursor(sf::Window* window, Cursor::Type type);
175
176
178 protected:
179
180 struct GuiResources
181 {
182 sf::Window* window = nullptr;
183 Cursor::Type mouseCursor = Cursor::Type::Arrow;
184 };
185
186 std::unordered_map<BackendGui*, GuiResources> m_guis;
187 std::map<Cursor::Type, std::unique_ptr<sf::Cursor>> m_mouseCursors;
188 };
189
191}
192
194
195#endif // TGUI_BACKEND_SFML_HPP
Base class for the Gui.
Definition: BackendGui.hpp:45
Definition: BackendSFML.hpp:40
void setClipboard(const String &contents) override
Changes the contents of the clipboard.
bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) override
Checks the state for one of the modifier keys.
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.
String getClipboard() const override
Returns the contents of the clipboard.
void detatchGui(BackendGui *gui) override
Informs the backend that a gui object is being destroyed.
void openVirtualKeyboard(const FloatRect &inputRect) override
Opens the virtual keyboard on Android and iOS.
void attachGui(BackendGui *gui) override
Informs the backend that a new gui object has been created.
void closeVirtualKeyboard() override
Closes the virtual keyboard on Android and iOS.
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:85
Type
List of available cursors.
Definition: Cursor.hpp:48
@ Arrow
Arrow cursor (default)
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