TGUI  0.8.9
RendererDefines.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 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/Loading/Theme.hpp>
31
33
34#define TGUI_RENDERER_PROPERTY_OUTLINE(CLASS, NAME) \
35 Outline CLASS::get##NAME() const \
36 { \
37 const 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 const 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 const 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 const 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_GET_BOOL(CLASS, NAME, DEFAULT) \
102 bool CLASS::get##NAME() const \
103 { \
104 const auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
105 if (it != m_data->propertyValuePairs.end()) \
106 return it->second.getBool(); \
107 else \
108 return DEFAULT; \
109 }
110
111#define TGUI_RENDERER_PROPERTY_BOOL(CLASS, NAME, DEFAULT) \
112 TGUI_RENDERER_PROPERTY_GET_BOOL(CLASS, NAME, DEFAULT) \
113 void CLASS::set##NAME(bool flag) \
114 { \
115 setProperty(toLower(#NAME), ObjectConverter{flag}); \
116 }
117
119
120// TGUI_NEXT: const reference
121#define TGUI_RENDERER_PROPERTY_TEXTURE(CLASS, NAME) \
122 Texture& CLASS::get##NAME() const \
123 { \
124 const auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
125 if (it != m_data->propertyValuePairs.end()) \
126 return it->second.getTexture(); \
127 else \
128 { \
129 m_data->propertyValuePairs[toLower(#NAME)] = {Texture{}}; \
130 return m_data->propertyValuePairs[toLower(#NAME)].getTexture(); \
131 } \
132 } \
133 void CLASS::set##NAME(const Texture& texture) \
134 { \
135 setProperty(toLower(#NAME), {texture}); \
136 }
137
139
140#define TGUI_RENDERER_PROPERTY_RENDERER(CLASS, NAME, RENDERER) \
141 std::shared_ptr<RendererData> CLASS::get##NAME() const \
142 { \
143 const auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
144 if (it != m_data->propertyValuePairs.end()) \
145 return it->second.getRenderer(); \
146 else \
147 { \
148 const auto& renderer = Theme::getDefault()->getRendererNoThrow(RENDERER); \
149 m_data->propertyValuePairs[toLower(#NAME)] = {renderer ? renderer : RendererData::create()}; \
150 return renderer; \
151 } \
152 } \
153 void CLASS::set##NAME(std::shared_ptr<RendererData> renderer) \
154 { \
155 setProperty(toLower(#NAME), {renderer}); \
156 }
157
159
160#endif // TGUI_RENDERER_DEFINES_HPP