TGUI  0.9-beta
Backend.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 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 
37 namespace 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 
230  protected:
231 
232  bool m_destroyOnLastGuiDetatch = false;
233  String m_clipboardContents;
234  };
235 
237 }
238 
240 
241 #endif // TGUI_BACKEND_HPP
Definition: Font.hpp:56
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
KeyModifier
Modifiers keys.
Definition: Event.hpp:156
virtual void resetMouseCursorStyle(Cursor::Type type)=0
Changes the look of a certain mouse cursor back to the system theme.
TGUI_API std::shared_ptr< BackendBase > getBackend()
Returns the global backend.
virtual void openVirtualKeyboard(const FloatRect &inputRect)=0
Opens the virtual keyboard on Android and iOS.
virtual Font createDefaultFont()=0
Creates and returns the default font for all widgets.
virtual std::shared_ptr< BackendFontBase > createFont()=0
Creates a new font object.
virtual String getClipboard() const
Returns the contents of the clipboard.
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 std::shared_ptr< BackendTextureBase > createTexture()=0
Creates a new texture object.
BackendBase()=default
Default constructor.
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.
TGUI_API void setBackend(std::shared_ptr< BackendBase > backend)
Changes the global backend.
virtual void detatchGui(GuiBase *gui)=0
Informs the backend that a gui object is being destroyed.
Type
List of available cursors.
Definition: Cursor.hpp:48
virtual std::shared_ptr< BackendTextBase > createText()=0
Creates a new text object.
Wrapper class to store strings.
Definition: String.hpp:74
virtual void setClipboard(const String &contents)
Changes the contents of the clipboard.
Base class for the Gui.
Definition: GuiBase.hpp:45
Definition: Vector2.hpp:42
TGUI_API bool isBackendSet()
Checks whether the backend differs from a nullptr.
Base class for the backend.
Definition: Backend.hpp:83
virtual bool isKeyboardModifierPressed(Event::KeyModifier modifierKey)=0
Checks the state for one of the modifier keys.
virtual void closeVirtualKeyboard()=0
Closes 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 ~BackendBase()=default
Virtual destructor.
virtual void attachGui(GuiBase *gui)=0
Informs the backend that a new gui object has been created.