TGUI  0.8-dev
WidgetRenderer.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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 
34 
35 namespace tgui
36 {
40  struct RendererData
41  {
42  RendererData() = default;
43 
44  static std::shared_ptr<RendererData> create(const std::map<std::string, ObjectConverter>& init = {})
45  {
46  auto data = std::make_shared<RendererData>();
47  data->propertyValuePairs = init;
48  return data;
49  }
50 
51  std::map<std::string, ObjectConverter> propertyValuePairs;
52  std::map<const void*, std::function<void(const std::string& property)>> observers;
53  bool shared = true;
54  };
55 
56 
60  class TGUI_API WidgetRenderer
61  {
62  public:
63 
67  WidgetRenderer() = default;
68 
69 
76  WidgetRenderer(const std::shared_ptr<RendererData>& data)
77  {
78  setData(data);
79  }
80 
81 
86  virtual ~WidgetRenderer() = default;
87 
88 
95  void setOpacity(float opacity);
96 
97 
104  float getOpacity() const;
105 
106 
115  void setFont(Font font);
116 
117 
124  Font getFont() const;
125 
126 
137  void setProperty(const std::string& property, ObjectConverter&& value);
138 
139 
149  ObjectConverter getProperty(const std::string& property) const;
150 
151 
158  const std::map<std::string, ObjectConverter>& getPropertyValuePairs() const;
159 
160 
168  void subscribe(const void* id, const std::function<void(const std::string& property)>& function);
169 
170 
177  void unsubscribe(const void* id);
178 
179 
187  void setData(const std::shared_ptr<RendererData>& data);
188 
189 
198  std::shared_ptr<RendererData> getData() const;
199 
200 
207  std::shared_ptr<RendererData> clone() const;
208 
209 
211  protected:
212 
213  std::shared_ptr<RendererData> m_data = RendererData::create();
214 
215 
217  };
218 
220 }
221 
223 
224 #endif // TGUI_WIDGETS_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:40
Definition: Font.hpp:41
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:52
WidgetRenderer(const std::shared_ptr< RendererData > &data)
Construct the renderer from renderer data.
Definition: WidgetRenderer.hpp:76
Base class for all renderer classes.
Definition: WidgetRenderer.hpp:60