TGUI  0.9.3
Backend.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_HPP
27#define TGUI_BACKEND_HPP
28
29#include <TGUI/Font.hpp>
30#include <TGUI/Event.hpp>
31#include <TGUI/Cursor.hpp>
32#include <cstdint>
33#include <memory>
34
36
37namespace tgui
38{
39 class GuiBase;
40 class BackendBase;
41 class BackendFontBase;
42 class BackendTextBase;
43 class BackendTextureBase;
44
45
50 TGUI_API bool isBackendSet();
51
52
64 TGUI_API void setBackend(std::shared_ptr<BackendBase> backend);
65
66
75 TGUI_API std::shared_ptr<BackendBase> getBackend();
76
77
78
82 class TGUI_API BackendBase
83 {
84 public:
85
89 BackendBase() = default;
90
91
93 // The object cannot be copied
95 BackendBase(const BackendBase&) = delete;
96
97
99 // The object cannot be copied
101 BackendBase& operator=(const BackendBase&) = delete;
102
103
107 virtual ~BackendBase() = default;
108
109
117 void setDestroyOnLastGuiDetatch(bool destroyOnDetatch);
118
119
124 virtual void attachGui(GuiBase* gui) = 0;
125
126
131 virtual void detatchGui(GuiBase* gui) = 0;
132
133
138 virtual Font createDefaultFont() = 0;
139
140
145 virtual std::shared_ptr<BackendFontBase> createFont() = 0;
146
147
152 virtual std::shared_ptr<BackendTextBase> createText() = 0;
153
154
159 virtual std::shared_ptr<BackendTextureBase> createTexture() = 0;
160
161
170 virtual void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) = 0;
171
172
178 virtual void resetMouseCursorStyle(Cursor::Type type) = 0;
179
180
187 virtual void setMouseCursor(GuiBase* gui, Cursor::Type type) = 0;
188
189
194 virtual void openVirtualKeyboard(const FloatRect& inputRect) = 0;
195
196
200 virtual void closeVirtualKeyboard() = 0;
201
202
210 virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) = 0;
211
212
218 virtual void setClipboard(const String& contents);
219
220
226 virtual String getClipboard() const;
227
228
237 virtual std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const;
238
239
241 protected:
242
243 bool m_destroyOnLastGuiDetatch = false;
244 String m_clipboardContents;
245 };
246
248}
249
251
252#endif // TGUI_BACKEND_HPP
Base class for the backend.
Definition: Backend.hpp:83
virtual void setClipboard(const String &contents)
Changes the contents of the clipboard.
virtual std::shared_ptr< BackendTextBase > createText()=0
Creates a new text object.
virtual void resetMouseCursorStyle(Cursor::Type type)=0
Changes the look of a certain mouse cursor back to the system theme.
virtual Font createDefaultFont()=0
Creates and returns the default font for all widgets.
virtual String getClipboard() const
Returns the contents of the clipboard.
virtual ~BackendBase()=default
Virtual destructor.
virtual std::shared_ptr< BackendTextureBase > createTexture()=0
Creates a new texture object.
virtual void attachGui(GuiBase *gui)=0
Informs the backend that a new gui object has been created.
virtual std::shared_ptr< BackendFontBase > createFont()=0
Creates a new font object.
virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey)=0
Checks the state for one of the modifier keys.
virtual void detatchGui(GuiBase *gui)=0
Informs the backend that a gui object is being destroyed.
virtual void closeVirtualKeyboard()=0
Closes the virtual keyboard on Android and iOS.
virtual std::unique_ptr< std::uint8_t[]> readFileFromAndroidAssets(const String &filename, std::size_t &fileSize) const
Uses the AssetManager on Android to read a file and return its contents.
virtual void openVirtualKeyboard(const FloatRect &inputRect)=0
Opens the virtual keyboard on Android and iOS.
void setDestroyOnLastGuiDetatch(bool destroyOnDetatch)
Informs the backend whether it should destroy itself when the last Gui is detached from it.
virtual void setMouseCursor(GuiBase *gui, Cursor::Type type)=0
Changes the mouse cursor when the mouse is on top of the window to which the gui is attached.
virtual void setMouseCursorStyle(Cursor::Type type, const std::uint8_t *pixels, Vector2u size, Vector2u hotspot)=0
Changes the look of a certain mouse cursor by using a bitmap.
BackendBase()=default
Default constructor.
Type
List of available cursors.
Definition: Cursor.hpp:48
Definition: Font.hpp:56
Base class for the Gui.
Definition: GuiBase.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
TGUI_API std::shared_ptr< BackendBase > getBackend()
Returns the global backend.
TGUI_API void setBackend(std::shared_ptr< BackendBase > backend)
Changes the global backend.
TGUI_API bool isBackendSet()
Checks whether the backend differs from a nullptr.
KeyModifier
Modifiers keys.
Definition: Event.hpp:156