TGUI  0.10-dev
RendererDefines.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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 tgui::Outline CLASS::get##NAME() const \
36 { \
37 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
38 if (it != m_data->propertyValuePairs.end()) \
39 return it->second.getOutline(); \
40 else \
41 return {}; \
42 } \
43 void CLASS::set##NAME(const tgui::Outline& outline) \
44 { \
45 setProperty(tgui::String(#NAME), {outline}); \
46 }
47
49
50#define TGUI_RENDERER_PROPERTY_COLOR(CLASS, NAME, DEFAULT) \
51 tgui::Color CLASS::get##NAME() const \
52 { \
53 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
54 if (it != m_data->propertyValuePairs.end()) \
55 return it->second.getColor(); \
56 else \
57 return DEFAULT; \
58 } \
59 void CLASS::set##NAME(tgui::Color color) \
60 { \
61 setProperty(tgui::String(#NAME), {color}); \
62 }
63
65
66#define TGUI_RENDERER_PROPERTY_TEXT_STYLE(CLASS, NAME, DEFAULT) \
67 tgui::TextStyles CLASS::get##NAME() const \
68 { \
69 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
70 if (it != m_data->propertyValuePairs.end()) \
71 return it->second.getTextStyle(); \
72 else \
73 return DEFAULT; \
74 } \
75 void CLASS::set##NAME(tgui::TextStyles style) \
76 { \
77 setProperty(tgui::String(#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(tgui::String(#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(tgui::String(#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(tgui::String(#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(tgui::String(#NAME), ObjectConverter{flag}); \
116 }
117
119
120#define TGUI_RENDERER_PROPERTY_TEXTURE(CLASS, NAME) \
121 const tgui::Texture& CLASS::get##NAME() const \
122 { \
123 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
124 if (it != m_data->propertyValuePairs.end()) \
125 return it->second.getTexture(); \
126 else \
127 { \
128 m_data->propertyValuePairs[tgui::String(#NAME)] = {tgui::Texture{}}; \
129 return m_data->propertyValuePairs[tgui::String(#NAME)].getTexture(); \
130 } \
131 } \
132 void CLASS::set##NAME(const tgui::Texture& texture) \
133 { \
134 setProperty(tgui::String(#NAME), {texture}); \
135 }
136
138
139#define TGUI_RENDERER_PROPERTY_RENDERER_WITH_DEFAULT(CLASS, NAME, RENDERER, DEFAULT) \
140 std::shared_ptr<tgui::RendererData> CLASS::get##NAME() const \
141 { \
142 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
143 if (it != m_data->propertyValuePairs.end()) \
144 return it->second.getRenderer(); \
145 else \
146 { \
147 const auto& renderer = Theme::getDefault()->getRendererNoThrow(RENDERER); \
148 m_data->propertyValuePairs[tgui::String(#NAME)] = {renderer ? renderer : DEFAULT}; \
149 return renderer; \
150 } \
151 } \
152 void CLASS::set##NAME(std::shared_ptr<tgui::RendererData> renderer) \
153 { \
154 setProperty(tgui::String(#NAME), {renderer}); \
155 }
156
157#define TGUI_RENDERER_PROPERTY_RENDERER(CLASS, NAME, RENDERER) \
158 TGUI_RENDERER_PROPERTY_RENDERER_WITH_DEFAULT(CLASS, NAME, RENDERER, tgui::RendererData::create()) \
159
160
162
163#endif // TGUI_RENDERER_DEFINES_HPP