TGUI  1.3-dev
Loading...
Searching...
No Matches
WidgetRenderer.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_WIDGET_RENDERER_HPP
27#define TGUI_WIDGET_RENDERER_HPP
28
29
30#include <TGUI/Config.hpp>
31#include <TGUI/ObjectConverter.hpp>
32#include <TGUI/Loading/DataIO.hpp>
33
34#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
35 #include <unordered_set>
36 #include <map>
37#endif
38
40
41TGUI_MODULE_EXPORT namespace tgui
42{
43 class Theme;
44 class Widget;
45
49 struct TGUI_API RendererData
50 {
51 RendererData() = default;
52 RendererData(const RendererData& other);
53 RendererData& operator=(const RendererData& other);
54
55 TGUI_NODISCARD static std::shared_ptr<RendererData> create(const std::map<String, ObjectConverter>& init = {});
56
58 TGUI_NODISCARD static std::shared_ptr<RendererData> createFromDataIONode(const DataIO::Node* rendererNode);
59
60 std::map<String, ObjectConverter> propertyValuePairs;
61 std::unordered_set<Widget*> observers;
62 Theme* connectedTheme = nullptr;
63 bool themePropertiesInherited = false;
64 bool shared = true;
65 };
66
67
71 class TGUI_API WidgetRenderer
72 {
73 public:
74
75 WidgetRenderer() = default;
80
81
88 WidgetRenderer(const std::shared_ptr<RendererData>& data)
89 {
90 setData(data);
91 }
92
93
98 virtual ~WidgetRenderer() = default;
99
100
107 void setOpacity(float opacity);
108
109
116 TGUI_NODISCARD float getOpacity() const;
117
118
126 void setOpacityDisabled(float opacity);
127
128
135 TGUI_NODISCARD float getOpacityDisabled() const;
136
137
146 void setFont(const Font& font);
147
148
155 TGUI_NODISCARD Font getFont() const;
156
157
165 void setTextSize(unsigned int size);
166
167
176 TGUI_NODISCARD unsigned int getTextSize() const;
177
178
189 void setTransparentTexture(bool ignoreTransparentParts);
190
191
197 TGUI_NODISCARD bool getTransparentTexture() const;
198
199
210 void setProperty(const String& property, ObjectConverter&& value);
211
212
222 TGUI_NODISCARD ObjectConverter getProperty(const String& property) const;
223
224
231 TGUI_NODISCARD const std::map<String, ObjectConverter>& getPropertyValuePairs() const;
232
233
239 void subscribe(Widget* widget);
240
241
247 void unsubscribe(Widget* widget);
248
249
257 void setData(const std::shared_ptr<RendererData>& data);
258
259
268 TGUI_NODISCARD std::shared_ptr<RendererData> getData() const;
269
270
277 TGUI_NODISCARD std::shared_ptr<RendererData> clone() const;
278
279
281 protected:
282
283 std::shared_ptr<RendererData> m_data = RendererData::create();
284
285
287 };
288
290}
291
293
294#endif // TGUI_WIDGETS_HPP
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:61
Implicit converter for settable properties.
Definition ObjectConverter.hpp:48
Wrapper class to store strings.
Definition String.hpp:101
This class can be used to manage the widget renderers.
Definition Theme.hpp:41
Base class for all renderer classes.
Definition WidgetRenderer.hpp:72
virtual ~WidgetRenderer()=default
Virtual destructor.
WidgetRenderer(const std::shared_ptr< RendererData > &data)
Construct the renderer from renderer data.
Definition WidgetRenderer.hpp:88
void setProperty(const String &property, ObjectConverter &&value)
Changes a property of the renderer.
void setFont(const Font &font)
Changes the font used for the text in the widget.
void unsubscribe(Widget *widget)
Subscribes a callback function to changes in the renderer.
TGUI_NODISCARD const std::map< String, ObjectConverter > & getPropertyValuePairs() const
Gets a map with all properties and their values.
void subscribe(Widget *widget)
Subscribes a callback function to changes in the renderer.
TGUI_NODISCARD Font getFont() const
Returns the font associated with the widget (if any)
TGUI_NODISCARD std::shared_ptr< RendererData > clone() const
Gets a clone of the renderer data.
WidgetRenderer(const WidgetRenderer &)
Copy constructor.
WidgetRenderer & operator=(const WidgetRenderer &)
Copy assignment operator.
TGUI_NODISCARD float getOpacity() const
Returns the opacity of the widget.
TGUI_NODISCARD unsigned int getTextSize() const
Returns text size of the widget that is specified by the renderer.
TGUI_NODISCARD bool getTransparentTexture() const
Returns whether mouse events should be ignored on transparent parts of the texture of the widget.
WidgetRenderer & operator=(WidgetRenderer &&)=default
Default move assignment operator.
TGUI_NODISCARD std::shared_ptr< RendererData > getData() const
Returns the renderer data.
void setTextSize(unsigned int size)
Changes the text size of the widget that is specified by the renderer.
TGUI_NODISCARD float getOpacityDisabled() const
Returns the opacity of the widget when it is disabled.
void setOpacityDisabled(float opacity)
Changes the opacity of the widget when it is disabled.
TGUI_NODISCARD ObjectConverter getProperty(const String &property) const
Retrieves the value of a certain property.
WidgetRenderer()=default
Default constructor.
void setTransparentTexture(bool ignoreTransparentParts)
Sets whether mouse events should be ignored on transparent parts of the texture of the widget in norm...
WidgetRenderer(WidgetRenderer &&)=default
Default move constructor.
void setOpacity(float opacity)
Changes the opacity of the widget.
The parent class for every widget.
Definition Widget.hpp:84
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:50