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<void*, std::function<void(const std::string& property)>> observers;
53  };
54 
55 
59  class TGUI_API WidgetRenderer
60  {
61  public:
62 
66  WidgetRenderer() = default;
67 
68 
75  WidgetRenderer(std::shared_ptr<RendererData> data)
76  {
77  setData(data);
78  }
79 
80 
85  virtual ~WidgetRenderer() {};
86 
87 
94  void setOpacity(float opacity);
95 
96 
103  float getOpacity() const;
104 
105 
114  void setFont(Font font);
115 
116 
123  Font getFont() const;
124 
125 
136  void setProperty(const std::string& property, const std::string& value);
137 
138 
149  void setProperty(const std::string& property, ObjectConverter&& value);
150 
151 
161  ObjectConverter getProperty(const std::string& property) const;
162 
163 
170  const std::map<std::string, ObjectConverter>& getPropertyValuePairs() const;
171 
172 
180  void subscribe(void* id, const std::function<void(const std::string& property)>& function);
181 
182 
189  void unsubscribe(void* id);
190 
191 
199  void setData(std::shared_ptr<RendererData> data);
200 
201 
210  std::shared_ptr<RendererData> getData() const;
211 
212 
219  std::shared_ptr<RendererData> clone() const;
220 
221 
223  protected:
224 
225  std::shared_ptr<RendererData> m_data = RendererData::create();
226 
227 
229  };
230 
232 }
233 
235 
236 #endif // TGUI_WIDGETS_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:40
Definition: Font.hpp:41
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:47
virtual ~WidgetRenderer()
Virtual destructor.
Definition: WidgetRenderer.hpp:85
WidgetRenderer(std::shared_ptr< RendererData > data)
Construct the renderer from renderer data.
Definition: WidgetRenderer.hpp:75
Base class for all renderer classes.
Definition: WidgetRenderer.hpp:59