TGUI  1.6.1
Loading...
Searching...
No Matches
RendererDefines.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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#ifndef TGUI_RENDERER_DEFINES_HPP
26#define TGUI_RENDERER_DEFINES_HPP
27
28#include <TGUI/Loading/Theme.hpp>
29
31
32#define TGUI_RENDERER_PROPERTY_OUTLINE(CLASS, NAME) \
33 tgui::Outline CLASS::get##NAME() const \
34 { \
35 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
36 if (it != m_data->propertyValuePairs.end()) \
37 return it->second.getOutline(); \
38 else \
39 return {}; \
40 } \
41 void CLASS::set##NAME(const tgui::Outline& outline) \
42 { \
43 setProperty(tgui::String(#NAME), {outline}); \
44 }
45
47
48#define TGUI_RENDERER_PROPERTY_COLOR(CLASS, NAME, DEFAULT) \
49 tgui::Color CLASS::get##NAME() const \
50 { \
51 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
52 if (it != m_data->propertyValuePairs.end()) \
53 return it->second.getColor(); \
54 else \
55 return DEFAULT; \
56 } \
57 void CLASS::set##NAME(tgui::Color color) \
58 { \
59 setProperty(tgui::String(#NAME), {color}); \
60 }
61
63
64#define TGUI_RENDERER_PROPERTY_TEXT_STYLE(CLASS, NAME, DEFAULT) \
65 tgui::TextStyles CLASS::get##NAME() const \
66 { \
67 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
68 if (it != m_data->propertyValuePairs.end()) \
69 return it->second.getTextStyle(); \
70 else \
71 return DEFAULT; \
72 } \
73 void CLASS::set##NAME(tgui::TextStyles style) \
74 { \
75 setProperty(tgui::String(#NAME), tgui::ObjectConverter{style}); \
76 }
77
79
80#define TGUI_RENDERER_PROPERTY_GET_NUMBER(CLASS, NAME, DEFAULT) \
81 float CLASS::get##NAME() const \
82 { \
83 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
84 if (it != m_data->propertyValuePairs.end()) \
85 return it->second.getNumber(); \
86 else \
87 return DEFAULT; \
88 }
89
90#define TGUI_RENDERER_PROPERTY_NUMBER(CLASS, NAME, DEFAULT) \
91 TGUI_RENDERER_PROPERTY_GET_NUMBER(CLASS, NAME, DEFAULT) \
92 void CLASS::set##NAME(float number) \
93 { \
94 setProperty(tgui::String(#NAME), tgui::ObjectConverter{number}); \
95 }
96
98
99#define TGUI_RENDERER_PROPERTY_GET_BOOL(CLASS, NAME, DEFAULT) \
100 bool CLASS::get##NAME() const \
101 { \
102 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
103 if (it != m_data->propertyValuePairs.end()) \
104 return it->second.getBool(); \
105 else \
106 return DEFAULT; \
107 }
108
109#define TGUI_RENDERER_PROPERTY_BOOL(CLASS, NAME, DEFAULT) \
110 TGUI_RENDERER_PROPERTY_GET_BOOL(CLASS, NAME, DEFAULT) \
111 void CLASS::set##NAME(bool flag) \
112 { \
113 setProperty(tgui::String(#NAME), tgui::ObjectConverter{flag}); \
114 }
115
117
118#define TGUI_RENDERER_PROPERTY_TEXTURE(CLASS, NAME) \
119 const tgui::Texture& CLASS::get##NAME() const \
120 { \
121 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
122 if (it != m_data->propertyValuePairs.end()) \
123 return it->second.getTexture(); \
124 else \
125 { \
126 m_data->propertyValuePairs[tgui::String(#NAME)] = {tgui::Texture{}}; \
127 return m_data->propertyValuePairs[tgui::String(#NAME)].getTexture(); \
128 } \
129 } \
130 void CLASS::set##NAME(const tgui::Texture& texture) \
131 { \
132 setProperty(tgui::String(#NAME), {texture}); \
133 }
134
136
137#define TGUI_RENDERER_PROPERTY_RENDERER_WITH_DEFAULT(CLASS, NAME, RENDERER, DEFAULT) \
138 std::shared_ptr<tgui::RendererData> CLASS::get##NAME() const \
139 { \
140 const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
141 if (it != m_data->propertyValuePairs.end()) \
142 return it->second.getRenderer(); \
143 else \
144 { \
145 const auto& renderer = tgui::Theme::getDefault()->getRendererNoThrow(RENDERER); \
146 m_data->propertyValuePairs[tgui::String(#NAME)] = {renderer ? renderer : (DEFAULT)}; \
147 return renderer; \
148 } \
149 } \
150 void CLASS::set##NAME(std::shared_ptr<tgui::RendererData> renderer) \
151 { \
152 if (renderer) \
153 setProperty(tgui::String(#NAME), {std::move(renderer)}); \
154 else \
155 setProperty(tgui::String(#NAME), {RendererData::create()}); \
156 }
157
158#define TGUI_RENDERER_PROPERTY_RENDERER(CLASS, NAME, RENDERER) \
159 TGUI_RENDERER_PROPERTY_RENDERER_WITH_DEFAULT(CLASS, NAME, RENDERER, tgui::RendererData::create()) \
160
162
163#endif // TGUI_RENDERER_DEFINES_HPP