TGUI  0.9-dev
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 <TGUI/Backend/Font/BackendFont.hpp>
33#include <TGUI/Backend/Font/BackendFontFactory.hpp>
34#include <TGUI/Backend/Renderer/BackendText.hpp>
35#include <TGUI/Backend/Renderer/BackendTexture.hpp>
36#include <TGUI/Backend/Renderer/BackendRenderer.hpp>
37#include <cstdint>
38#include <memory>
39
41
42namespace tgui
43{
44 class Backend;
45 class BackendGui;
46
47
52 TGUI_API bool isBackendSet();
53
54
66 TGUI_API void setBackend(std::shared_ptr<Backend> backend);
67
68
77 TGUI_API std::shared_ptr<Backend> getBackend();
78
79
80
84 class TGUI_API Backend
85 {
86 public:
87
91 Backend() = default;
92
93
95 // The object cannot be copied
97 Backend(const Backend&) = delete;
98
99
101 // The object cannot be copied
103 Backend& operator=(const Backend&) = delete;
104
105
109 virtual ~Backend() = default;
110
111
119 void setDestroyOnLastGuiDetatch(bool destroyOnDetatch);
120
121
126 virtual void attachGui(BackendGui* gui) = 0;
127
128
133 virtual void detatchGui(BackendGui* gui) = 0;
134
135
141
142
147#ifdef TGUI_NEXT
148 std::shared_ptr<BackendFont> createFont();
149#else
150 virtual std::shared_ptr<BackendFont> createFont();
151#endif
152
157#ifdef TGUI_NEXT
158 std::shared_ptr<BackendText> createText();
159#else
160 virtual std::shared_ptr<BackendText> createText();
161#endif
162
167#ifdef TGUI_NEXT
168 std::shared_ptr<BackendTexture> createTexture();
169#else
170 virtual std::shared_ptr<BackendTexture> createTexture();
171#endif
172
181 virtual void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) = 0;
182
183
189 virtual void resetMouseCursorStyle(Cursor::Type type) = 0;
190
191
198 virtual void setMouseCursor(BackendGui* gui, Cursor::Type type) = 0;
199
200
207 virtual void openVirtualKeyboard(const FloatRect& inputRect);
208
209
215 virtual void closeVirtualKeyboard();
216
217
225 virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) = 0;
226
227
233 virtual void setClipboard(const String& contents);
234
235
241 virtual String getClipboard() const;
242
243
252 virtual std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const;
253
254
259 bool hasRenderer() const;
260
261
270 std::shared_ptr<BackendRenderer> getRenderer() const;
271
272
278 virtual void setRenderer(std::shared_ptr<BackendRenderer> renderer);
279
280
285 bool hasFontBackend() const;
286
287
296 std::shared_ptr<BackendFontFactory> getFontBackend() const;
297
298
304 virtual void setFontBackend(std::shared_ptr<BackendFontFactory> fontBackend);
305
306
308 protected:
309
310 bool m_destroyOnLastGuiDetatch = false;
311 String m_clipboardContents;
312
313 std::shared_ptr<BackendRenderer> m_renderer;
314 std::shared_ptr<BackendFontFactory> m_fontBackend;
315 };
316
318
319#ifndef TGUI_REMOVE_DEPRECATED_CODE
320 using BackendBase TGUI_DEPRECATED("BackendBase was renamed to Backend") = Backend;
321#endif
322
324}
325
327
328#endif // TGUI_BACKEND_HPP
Base class for the Gui.
Definition: BackendGui.hpp:45
Base class for the backend.
Definition: Backend.hpp:85
virtual void setClipboard(const String &contents)
Changes the contents of the clipboard.
std::shared_ptr< BackendFontFactory > getFontBackend() const
Returns the font factory.
virtual std::shared_ptr< BackendTexture > createTexture()
Creates a new texture object.
virtual void detatchGui(BackendGui *gui)=0
Informs the backend that a gui object is being destroyed.
virtual void setRenderer(std::shared_ptr< BackendRenderer > renderer)
Sets the renderer that the backend should use.
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.
virtual void setMouseCursor(BackendGui *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 std::shared_ptr< BackendFont > createFont()
Creates a new font object.
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 resetMouseCursorStyle(Cursor::Type type)=0
Changes the look of a certain mouse cursor back to the system theme.
virtual String getClipboard() const
Returns the contents of the clipboard.
virtual void closeVirtualKeyboard()
Closes the virtual keyboard on Android and iOS.
virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey)=0
Checks the state for one of the modifier keys.
virtual ~Backend()=default
Virtual destructor.
virtual void openVirtualKeyboard(const FloatRect &inputRect)
Opens the virtual keyboard on Android and iOS.
virtual std::shared_ptr< BackendText > createText()
Creates a new text object.
std::shared_ptr< BackendRenderer > getRenderer() const
Returns the renderer.
virtual void setFontBackend(std::shared_ptr< BackendFontFactory > fontBackend)
Sets the font factory that the backend should use.
bool hasFontBackend() const
Checks whether a font factory has been attached to the backend.
void setDestroyOnLastGuiDetatch(bool destroyOnDetatch)
Informs the backend whether it should destroy itself when the last Gui is detached from it.
virtual void attachGui(BackendGui *gui)=0
Informs the backend that a new gui object has been created.
virtual Font createDefaultFont()
Creates and returns the default font for all widgets.
bool hasRenderer() const
Checks whether a renderer has been attached to the backend.
Backend()=default
Default constructor.
Type
List of available cursors.
Definition: Cursor.hpp:48
Definition: Font.hpp:57
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
TGUI_API void setBackend(std::shared_ptr< Backend > backend)
Changes the global backend.
TGUI_API std::shared_ptr< Backend > getBackend()
Returns the global backend.
TGUI_API bool isBackendSet()
Checks whether the backend differs from a nullptr.
KeyModifier
Modifiers keys.
Definition: Event.hpp:156