TGUI  1.0-alpha
WidgetRenderer.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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#include <unordered_set>
34#include <map>
35
37
38namespace tgui
39{
40 class Theme;
41 class Widget;
42
46 struct TGUI_API RendererData
47 {
48 RendererData() = default;
49 RendererData(const RendererData& other);
50 RendererData& operator=(const RendererData& other);
51
52 static std::shared_ptr<RendererData> create(const std::map<String, ObjectConverter>& init = {});
53
55 static std::shared_ptr<RendererData> createFromDataIONode(const DataIO::Node* rendererNode);
56
57 std::map<String, ObjectConverter> propertyValuePairs;
58 std::unordered_set<Widget*> observers;
59 Theme* connectedTheme = nullptr;
60 bool themePropertiesInherited = false;
61 bool shared = true;
62 };
63
64
68 class TGUI_API WidgetRenderer
69 {
70 public:
71
75 WidgetRenderer() = default;
76
77
84 WidgetRenderer(const std::shared_ptr<RendererData>& data)
85 {
86 setData(data);
87 }
88
89
94 virtual ~WidgetRenderer() = default;
95
96
103 void setOpacity(float opacity);
104
105
112 float getOpacity() const;
113
114
122 void setOpacityDisabled(float opacity);
123
124
131 float getOpacityDisabled() const;
132
133
142 void setFont(Font font);
143
144
151 Font getFont() const;
152
153
161 void setTextSize(unsigned int size);
162
163
172 unsigned int getTextSize() const;
173
174
185 void setTransparentTexture(bool ignoreTransparentParts);
186
187
194
195
206 void setProperty(const String& property, ObjectConverter&& value);
207
208
218 ObjectConverter getProperty(const String& property) const;
219
220
227 const std::map<String, ObjectConverter>& getPropertyValuePairs() const;
228
229
235 void subscribe(Widget* widget);
236
237
243 void unsubscribe(Widget* widget);
244
245
253 void setData(const std::shared_ptr<RendererData>& data);
254
255
264 std::shared_ptr<RendererData> getData() const;
265
266
273 std::shared_ptr<RendererData> clone() const;
274
275
277 protected:
278
279 std::shared_ptr<RendererData> m_data = RendererData::create();
280
281
283 };
284
286}
287
289
290#endif // TGUI_WIDGETS_HPP
Definition: Font.hpp:57
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:48
Wrapper class to store strings.
Definition: String.hpp:79
This class can be used to manage the widget renderers.
Definition: Theme.hpp:41
Base class for all renderer classes.
Definition: WidgetRenderer.hpp:69
virtual ~WidgetRenderer()=default
Virtual destructor.
WidgetRenderer(const std::shared_ptr< RendererData > &data)
Construct the renderer from renderer data.
Definition: WidgetRenderer.hpp:84
void setProperty(const String &property, ObjectConverter &&value)
Changes a property of the renderer.
void unsubscribe(Widget *widget)
Subscribes a callback function to changes in the renderer.
bool getTransparentTexture() const
Returns whether mouse events should be ignored on transparent parts of the texture of the widget.
void subscribe(Widget *widget)
Subscribes a callback function to changes in the renderer.
std::shared_ptr< RendererData > getData() const
Returns the renderer data.
float getOpacity() const
Returns the opacity of the widget.
Font getFont() const
Returns the font associated with the widget (if any)
float getOpacityDisabled() const
Returns the opacity of the widget when it is disabled.
std::shared_ptr< RendererData > clone() const
Gets a clone of the renderer data.
ObjectConverter getProperty(const String &property) const
Retrieves the value of a certain property.
void setTextSize(unsigned int size)
Changes the text size of the widget that is specified by the renderer.
void setOpacityDisabled(float opacity)
Changes the opacity of the widget when it is disabled.
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...
unsigned int getTextSize() const
Returns text size of the widget that is specified by the renderer.
void setOpacity(float opacity)
Changes the opacity of the widget.
void setFont(Font font)
Changes the font used for the text in the widget.
const std::map< String, ObjectConverter > & getPropertyValuePairs() const
Gets a map with all properties and their values.
The parent class for every widget.
Definition: Widget.hpp:70
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:47