TGUI  0.8-dev
RendererDefines.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_RENDERER_DEFINES_HPP
27 #define TGUI_RENDERER_DEFINES_HPP
28 
29 
30 #include <TGUI/Global.hpp>
31 
33 
34 #define TGUI_RENDERER_PROPERTY_OUTLINE(CLASS, NAME) \
35  Outline CLASS::get##NAME() const \
36  { \
37  auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
38  if (it != m_data->propertyValuePairs.end()) \
39  return it->second.getOutline(); \
40  else \
41  return {}; \
42  } \
43  void CLASS::set##NAME(const Outline& outline) \
44  { \
45  setProperty(toLower(#NAME), {outline}); \
46  }
47 
49 
50 #define TGUI_RENDERER_PROPERTY_COLOR(CLASS, NAME, DEFAULT) \
51  Color CLASS::get##NAME() const \
52  { \
53  auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
54  if (it != m_data->propertyValuePairs.end()) \
55  return it->second.getColor(); \
56  else \
57  return DEFAULT; \
58  } \
59  void CLASS::set##NAME(Color color) \
60  { \
61  setProperty(toLower(#NAME), {color}); \
62  }
63 
65 
66 #define TGUI_RENDERER_PROPERTY_TEXT_STYLE(CLASS, NAME, DEFAULT) \
67  TextStyle CLASS::get##NAME() const \
68  { \
69  auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
70  if (it != m_data->propertyValuePairs.end()) \
71  return it->second.getTextStyle(); \
72  else \
73  return DEFAULT; \
74  } \
75  void CLASS::set##NAME(TextStyle style) \
76  { \
77  setProperty(toLower(#NAME), ObjectConverter{style}); \
78  }
79 
81 
82 #define TGUI_RENDERER_PROPERTY_GET_NUMBER(CLASS, NAME, DEFAULT) \
83  float CLASS::get##NAME() const \
84  { \
85  auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
86  if (it != m_data->propertyValuePairs.end()) \
87  return it->second.getNumber(); \
88  else \
89  return DEFAULT; \
90  }
91 
92 #define TGUI_RENDERER_PROPERTY_NUMBER(CLASS, NAME, DEFAULT) \
93  TGUI_RENDERER_PROPERTY_GET_NUMBER(CLASS, NAME, DEFAULT) \
94  void CLASS::set##NAME(float number) \
95  { \
96  setProperty(toLower(#NAME), ObjectConverter{number}); \
97  }
98 
100 
101 #define TGUI_RENDERER_PROPERTY_TEXTURE(CLASS, NAME) \
102  Texture& CLASS::get##NAME() const \
103  { \
104  auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
105  if (it != m_data->propertyValuePairs.end()) \
106  return it->second.getTexture(); \
107  else \
108  { \
109  m_data->propertyValuePairs[toLower(#NAME)] = {Texture{}}; \
110  return m_data->propertyValuePairs[toLower(#NAME)].getTexture(); \
111  } \
112  } \
113  void CLASS::set##NAME(const Texture& texture) \
114  { \
115  setProperty(toLower(#NAME), {texture}); \
116  }
117 
119 
120 #define TGUI_RENDERER_PROPERTY_RENDERER(CLASS, NAME) \
121  std::shared_ptr<RendererData> CLASS::get##NAME() const \
122  { \
123  auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
124  if (it != m_data->propertyValuePairs.end()) \
125  return it->second.getRenderer(); \
126  else \
127  { \
128  m_data->propertyValuePairs[toLower(#NAME)] = {RendererData::create()}; \
129  return m_data->propertyValuePairs[toLower(#NAME)].getRenderer(); \
130  } \
131  } \
132  void CLASS::set##NAME(std::shared_ptr<RendererData> renderer) \
133  { \
134  setProperty(toLower(#NAME), {renderer}); \
135  }
136 
138 
139 #endif // TGUI_RENDERER_DEFINES_HPP