TGUI  1.3-dev
Loading...
Searching...
No Matches
Backend.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_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
38#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
39 #include <cstdint>
40 #include <memory>
41 #include <set>
42#endif
43
45
46TGUI_MODULE_EXPORT namespace tgui
47{
48 class Sprite;
49 class Backend;
50 class BackendGui;
51 class BackendRenderer;
52 class BackendFontFactory;
53
58 TGUI_API bool isBackendSet();
59
60
72 TGUI_API void setBackend(std::shared_ptr<Backend> backend);
73
74
83 TGUI_API std::shared_ptr<Backend> getBackend();
84
85
86
90 class TGUI_API Backend
91 {
92 public:
93
97 Backend() = default;
98
99
101 // The object cannot be copied
103 Backend(const Backend&) = delete;
104
105
107 // The object cannot be copied
109 Backend& operator=(const Backend&) = delete;
110
111
115 virtual ~Backend() = default;
116
117
125 void setDestroyOnLastGuiDetatch(bool destroyOnDetatch);
126
127
132 virtual void attachGui(BackendGui* gui);
133
134
139 virtual void detatchGui(BackendGui* gui);
140
141
146 TGUI_NODISCARD virtual Font createDefaultFont();
147
148
153 TGUI_NODISCARD std::shared_ptr<BackendFont> createFont();
154
155
160 TGUI_NODISCARD std::shared_ptr<BackendText> createText();
161
162
167 TGUI_NODISCARD std::shared_ptr<BackendTexture> createTexture();
168
169
180 void setFontScale(float scale);
181
182
190 float getFontScale() const;
191
192
201 virtual void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) = 0;
202
203
209 virtual void resetMouseCursorStyle(Cursor::Type type) = 0;
210
211
218 virtual void setMouseCursor(BackendGui* gui, Cursor::Type type) = 0;
219
220#ifndef TGUI_REMOVE_DEPRECATED_CODE
229 TGUI_DEPRECATED("Use BackendGui::startTextInput instead") virtual void openVirtualKeyboard(const FloatRect& inputRect);
230
231
239 TGUI_DEPRECATED("Use BackendGui::stopTextInput instead") virtual void closeVirtualKeyboard();
240#endif
241
249 TGUI_NODISCARD virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey) = 0;
250
251
257 virtual void setClipboard(const String& contents);
258
259
265 TGUI_NODISCARD virtual String getClipboard() const;
266
267
276 TGUI_NODISCARD virtual std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const;
277
278
283 TGUI_NODISCARD bool hasRenderer() const;
284
285
294 TGUI_NODISCARD std::shared_ptr<BackendRenderer> getRenderer() const;
295
296
302 virtual void setRenderer(std::shared_ptr<BackendRenderer> renderer);
303
304
309 TGUI_NODISCARD bool hasFontBackend() const;
310
311
320 TGUI_NODISCARD std::shared_ptr<BackendFontFactory> getFontBackend() const;
321
322
328 virtual void setFontBackend(std::shared_ptr<BackendFontFactory> fontBackend);
329
330
338 void registerFont(BackendFont* font);
339
340
348 void unregisterFont(BackendFont* font);
349
350
358 void registerSvgSprite(Sprite* sprite);
359
360
368 void unregisterSvgSprite(Sprite* sprite);
369
370
372 protected:
373
374 bool m_destroyOnLastGuiDetatch = false;
375 String m_clipboardContents;
376 float m_fontScale = 1;
377
378 std::shared_ptr<BackendRenderer> m_renderer;
379 std::shared_ptr<BackendFontFactory> m_fontBackend;
380
381 std::set<BackendGui*> m_guis;
382 std::set<BackendFont*> m_registeredFonts;
383 std::set<Sprite*> m_registeredSvgSprites;
384 };
385
387}
388
390
391#endif // TGUI_BACKEND_HPP
Base class for font implementations that depend on the backend.
Definition BackendFont.hpp:46
Base class for the Gui.
Definition BackendGui.hpp:48
Base class for the backend.
Definition Backend.hpp:91
virtual void setClipboard(const String &contents)
Changes the contents of the clipboard.
TGUI_NODISCARD std::shared_ptr< BackendText > createText()
Creates a new text object.
float getFontScale() const
Returns the scale factor to render text at a higher quality, e.g. to scale for DPI awareness.
TGUI_NODISCARD std::shared_ptr< BackendFontFactory > getFontBackend() const
Returns the font factory.
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 TGUI_NODISCARD Font createDefaultFont()
Creates and returns the default font for all widgets.
virtual TGUI_NODISCARD 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.
TGUI_NODISCARD std::shared_ptr< BackendFont > createFont()
Creates a new font object.
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 void resetMouseCursorStyle(Cursor::Type type)=0
Changes the look of a certain mouse cursor back to the system theme.
TGUI_NODISCARD std::shared_ptr< BackendTexture > createTexture()
Creates a new texture object.
virtual void attachGui(BackendGui *gui)
Informs the backend that a new gui object has been created.
TGUI_NODISCARD std::shared_ptr< BackendRenderer > getRenderer() const
Returns the renderer.
virtual ~Backend()=default
Virtual destructor.
virtual void detatchGui(BackendGui *gui)
Informs the backend that a gui object is being destroyed.
TGUI_NODISCARD bool hasRenderer() const
Checks whether a renderer has been attached to the backend.
virtual void setFontBackend(std::shared_ptr< BackendFontFactory > fontBackend)
Sets the font factory that the backend should use.
virtual TGUI_NODISCARD bool isKeyboardModifierPressed(Event::KeyModifier modifierKey)=0
Checks the state for one of the modifier keys.
void setDestroyOnLastGuiDetatch(bool destroyOnDetatch)
Informs the backend whether it should destroy itself when the last Gui is detached from it.
virtual TGUI_NODISCARD String getClipboard() const
Returns the contents of the clipboard.
void setFontScale(float scale)
Sets the scale factor to render text at a higher quality, e.g. to scale for DPI awareness.
Backend()=default
Default constructor.
TGUI_NODISCARD bool hasFontBackend() const
Checks whether a font factory has been attached to the backend.
Type
List of available cursors.
Definition Cursor.hpp:51
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:61
Definition Sprite.hpp:48
Wrapper class to store strings.
Definition String.hpp:101
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
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:158