TGUI 1.11
Loading...
Searching...
No Matches
Backend.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 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#ifndef TGUI_BACKEND_HPP
26#define TGUI_BACKEND_HPP
27
28#include <TGUI/Font.hpp>
29#include <TGUI/Event.hpp>
30#include <TGUI/Cursor.hpp>
31#include <TGUI/Backend/Font/BackendFont.hpp>
32#include <TGUI/Backend/Font/BackendFontFactory.hpp>
33#include <TGUI/Backend/Renderer/BackendText.hpp>
34#include <TGUI/Backend/Renderer/BackendTexture.hpp>
35#include <TGUI/Backend/Renderer/BackendRenderer.hpp>
36
37#include <cstdint>
38#include <memory>
39#include <set>
40
42
43namespace tgui
44{
45 class Sprite;
46 class Backend;
47 class BackendGui;
48 class BackendRenderer;
50
55 TGUI_API bool isBackendSet();
56
68 TGUI_API void setBackend(std::shared_ptr<Backend> backend);
69
78 TGUI_API std::shared_ptr<Backend> getBackend();
79
80
84 class TGUI_API Backend
85 {
86 public:
87
91 Backend() = default;
92
94 // The object cannot be copied
96 Backend(const Backend&) = delete;
97
99 // The object cannot be copied
101 Backend& operator=(const Backend&) = delete;
102
106 virtual ~Backend() = default;
107
115 void setDestroyOnLastGuiDetatch(bool destroyOnDetatch);
116
121 virtual void attachGui(BackendGui* gui);
122
127 virtual void detatchGui(BackendGui* gui);
128
133 TGUI_NODISCARD virtual Font createDefaultFont();
134
139 TGUI_NODISCARD std::shared_ptr<BackendFont> createFont();
140
145 TGUI_NODISCARD std::shared_ptr<BackendText> createText();
146
151 TGUI_NODISCARD std::shared_ptr<BackendTexture> createTexture();
152
163 void setFontScale(float scale);
164
172 float getFontScale() const;
173
182 virtual void setMouseCursorStyle(Cursor::Type type, const std::uint8_t* pixels, Vector2u size, Vector2u hotspot) = 0;
183
189 virtual void resetMouseCursorStyle(Cursor::Type type) = 0;
190
197 virtual void setMouseCursor(BackendGui* gui, Cursor::Type type) = 0;
198
199#ifndef TGUI_REMOVE_DEPRECATED_CODE
208 TGUI_DEPRECATED("Use BackendGui::startTextInput instead") virtual void openVirtualKeyboard(const FloatRect& inputRect);
209
217 TGUI_DEPRECATED("Use BackendGui::stopTextInput instead") virtual void closeVirtualKeyboard();
218#endif
219
227 TGUI_DEPRECATED("Use gui.isKeyboardModifierPressed(modifierKey) instead") TGUI_NODISCARD virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey);
228
234 virtual void setClipboard(const String& contents);
235
241 TGUI_NODISCARD virtual String getClipboard() const;
242
251 TGUI_NODISCARD virtual std::unique_ptr<std::uint8_t[]> readFileFromAndroidAssets(const String& filename, std::size_t& fileSize) const;
252
257 TGUI_NODISCARD bool hasRenderer() const;
258
267 TGUI_NODISCARD std::shared_ptr<BackendRenderer> getRenderer() const;
268
274 virtual void setRenderer(std::shared_ptr<BackendRenderer> renderer);
275
280 TGUI_NODISCARD bool hasFontBackend() const;
281
290 TGUI_NODISCARD std::shared_ptr<BackendFontFactory> getFontBackend() const;
291
297 virtual void setFontBackend(std::shared_ptr<BackendFontFactory> fontBackend);
298
306 void registerFont(BackendFont* font);
307
315 void unregisterFont(BackendFont* font);
316
324 void registerSvgSprite(Sprite* sprite);
325
333 void unregisterSvgSprite(Sprite* sprite);
334
336 protected:
337
338 bool m_destroyOnLastGuiDetatch = false;
339 String m_clipboardContents;
340 float m_fontScale = 1;
341
342 std::shared_ptr<BackendRenderer> m_renderer;
343 std::shared_ptr<BackendFontFactory> m_fontBackend;
344
345 std::set<BackendGui*> m_guis;
346 std::set<BackendFont*> m_registeredFonts;
347 std::set<Sprite*> m_registeredSvgSprites;
348 };
349
351}
352
354
355#endif // TGUI_BACKEND_HPP
Base class for the font factory that is responsible for creating a font object specific to the font b...
Definition BackendFontFactory.hpp:40
Base class for font implementations that depend on the backend.
Definition BackendFont.hpp:43
Base class for the Gui.
Definition BackendGui.hpp:45
Base class for the backend renderer, which is responsible for creating text and texture objects.
Definition BackendRenderer.hpp:42
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.
std::shared_ptr< BackendFont > createFont()
Creates a new font object.
float getFontScale() const
Returns the scale factor to render text at a higher quality, e.g. to scale for DPI awareness.
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::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 void attachGui(BackendGui *gui)
Informs the backend that a new gui object has been created.
virtual ~Backend()=default
Virtual destructor.
virtual void openVirtualKeyboard(const FloatRect &inputRect)
Opens the virtual keyboard on Android and iOS.
virtual void detatchGui(BackendGui *gui)
Informs the backend that a gui object is being destroyed.
std::shared_ptr< BackendTexture > createTexture()
Creates a new texture object.
std::shared_ptr< BackendRenderer > getRenderer() const
Returns the renderer.
std::shared_ptr< BackendText > createText()
Creates a new text object.
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.
void setFontScale(float scale)
Sets the scale factor to render text at a higher quality, e.g. to scale for DPI awareness.
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.
virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey)
Checks the state for one of the modifier keys.
Type
List of available cursors.
Definition Cursor.hpp:48
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:56
Definition Sprite.hpp:45
Wrapper class to store strings.
Definition String.hpp:94
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.
Definition Event.hpp:38