TGUI  0.9.5
Loading...
Searching...
No Matches
BackendSFML.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_SFML_HPP
27#define TGUI_BACKEND_SFML_HPP
28
29#include <TGUI/Backend.hpp>
30#include <SFML/Window/Cursor.hpp> // Can't be an incomplete type when instantiating an object of type BackendSFML
31#include <map>
32
34
35namespace sf
36{
37 class Event;
38 class Window;
39 class RenderTarget;
40}
41
42namespace tgui
43{
44 class GuiSFML;
45 class BackendRenderTargetSFML;
46
47
51 class TGUI_API BackendSFML : public BackendBase
52 {
53 public:
54
55#ifndef TGUI_REMOVE_DEPRECATED_CODE
62 TGUI_DEPRECATED("Use GuiSFML::convertEvent instead") static bool convertEvent(const sf::Event& eventSFML, Event& eventTGUI);
63#endif
64
69 void attachGui(GuiBase* gui) override;
70
71
76 void detatchGui(GuiBase* gui) override;
77
78
84
85
90 std::shared_ptr<BackendFontBase> createFont() override;
91
92
97 std::shared_ptr<BackendTextBase> createText() override;
98
99
104 std::shared_ptr<BackendTextureBase> createTexture() override;
105
106
115 void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) override;
116
117
124
125
132 void setMouseCursor(GuiBase* gui, Cursor::Type type) override;
133
134
139 void openVirtualKeyboard(const FloatRect& inputRect) override;
140
141
145 void closeVirtualKeyboard() override;
146
147
156
157
163 void setClipboard(const String& contents) override;
164
165
171 String getClipboard() const override;
172
173#ifdef TGUI_SYSTEM_ANDROID
182 std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const override;
183#endif
184
193 std::shared_ptr<BackendRenderTargetSFML> createGuiRenderTarget(GuiSFML* gui, sf::RenderTarget& target);
194
195
197 protected:
198
200 // Helper function to create a system cursor
202 std::unique_ptr<sf::Cursor> createSystemCursor(Cursor::Type type);
203
204
206 // Helper function to update the mouse cursors on all attached guis
208 void updateMouseCursor(Cursor::Type type, std::unique_ptr<sf::Cursor> cursor);
209
210
212 // Helper function to update the mouse cursor on a window
214 void updateMouseCursor(sf::Window* window, Cursor::Type type);
215
216
218 protected:
219
220 struct GuiResources
221 {
222 sf::Window* window = nullptr;
223 Cursor::Type mouseCursor = Cursor::Type::Arrow;
224 };
225
226 std::map<GuiBase*, GuiResources> m_guis;
227 std::map<Cursor::Type, std::unique_ptr<sf::Cursor>> m_mouseCursors;
228 };
229
231}
232
234
235#endif // TGUI_BACKEND_SFML_HPP
Base class for the backend.
Definition Backend.hpp:83
Backend that uses SFML.
Definition BackendSFML.hpp:52
void setClipboard(const String &contents) override
Changes the contents of the clipboard.
std::shared_ptr< BackendTextBase > createText() override
Creates a new text object.
std::shared_ptr< BackendFontBase > createFont() override
Creates a new font object.
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 attachGui(GuiBase *gui) override
Informs the backend that a new gui object has been created.
std::shared_ptr< BackendRenderTargetSFML > createGuiRenderTarget(GuiSFML *gui, sf::RenderTarget &target)
Sets the SFML target to which the gui will render and returns a new render target object to interact ...
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 openVirtualKeyboard(const FloatRect &inputRect) override
Opens the virtual keyboard on Android and iOS.
std::shared_ptr< BackendTextureBase > createTexture() override
Creates a new texture object.
Font createDefaultFont() override
Creates and returns the default font for all widgets.
void closeVirtualKeyboard() override
Closes the virtual keyboard on Android and iOS.
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.
void detatchGui(GuiBase *gui) override
Informs the backend that a gui object is being destroyed.
Type
List of available cursors.
Definition Cursor.hpp:48
Definition Font.hpp:56
Base class for the Gui.
Definition GuiBase.hpp:45
Gui class for the SFML backend.
Definition GuiSFML.hpp:46
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