TGUI 1.13
Loading...
Searching...
No Matches
ObjectConverter.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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_OBJECT_CONVERTER_HPP
26#define TGUI_OBJECT_CONVERTER_HPP
27
28#include <TGUI/Color.hpp>
29#include <TGUI/Font.hpp>
30#include <TGUI/Outline.hpp>
31#include <TGUI/TextStyle.hpp>
32#include <TGUI/Texture.hpp>
33
34#include <variant>
35
37
38namespace tgui
39{
40 struct RendererData;
41
46 class TGUI_API ObjectConverter
47 {
48 public:
49 enum class Type
50 {
51 None,
52 Bool,
53 Font,
54 Color,
55 String,
56 Number,
57 Outline,
58 Texture,
61 };
62
67 m_type{Type::None}
68 {
69 }
70
76 ObjectConverter(const char* string) :
77 ObjectConverter{String{string}}
78 {
79 }
80
86 ObjectConverter(const String& string) :
87 m_type{Type::String},
88 m_value{string},
89 m_serialized{true},
90 m_string{string}
91 {
92 }
93
100 m_type{Type::Font},
101 m_value{std::move(font)}
102 {
103 }
104
111 m_type{Type::Color},
112 m_value{color}
113 {
114 }
115
121 ObjectConverter(bool value) :
122 m_type{Type::Bool},
123 m_value{value}
124 {
125 }
126
132 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic_v<T>, T>>
133 ObjectConverter(T number) :
134 m_type{Type::Number},
135 m_value{static_cast<float>(number)}
136 {
137 }
138
144 ObjectConverter(const Outline& outline) :
145 m_type{Type::Outline},
146 m_value{outline}
147 {
148 }
149
155 ObjectConverter(const Texture& texture) :
156 m_type{Type::Texture},
157 m_value{texture}
158 {
159 }
160
167 m_type{Type::TextStyle},
168 m_value{TextStyles(style)}
169 {
170 }
171
178 m_type{Type::TextStyle},
179 m_value{style}
180 {
181 }
182
188 ObjectConverter(std::shared_ptr<RendererData> data) :
189 m_type{Type::RendererData},
190 m_value{std::move(data)}
191 {
192 }
193
199 [[nodiscard]] const String& getString();
200
208 [[nodiscard]] const Font& getFont();
209
217 [[nodiscard]] const Color& getColor();
218
226 [[nodiscard]] const Outline& getOutline();
227
235 [[nodiscard]] bool getBool();
236
244 [[nodiscard]] float getNumber();
245
253 [[nodiscard]] const Texture& getTexture();
254
262 [[nodiscard]] const TextStyles& getTextStyle();
263
271 [[nodiscard]] const std::shared_ptr<RendererData>& getRenderer();
272
278 [[nodiscard]] Type getType() const;
279
285 [[nodiscard]] bool operator==(const ObjectConverter& right) const;
286
292 [[nodiscard]] bool operator!=(const ObjectConverter& right) const;
293
295
296 private:
297 Type m_type = Type::None;
298
299 std::variant<String, Font, Color, Outline, bool, float, Texture, TextStyles, std::shared_ptr<RendererData>> m_value;
300
301 bool m_serialized = false;
302 String m_string;
303 };
304} // namespace tgui
305
306#endif // TGUI_OBJECT_CONVERTER_HPP
Wrapper for colors.
Definition Color.hpp:63
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:54
bool operator!=(const ObjectConverter &right) const
Check if the object differs from another one.
const Font & getFont()
Retrieves the saved font.
bool getBool()
Retrieves the saved boolean.
ObjectConverter(bool value)
Stores a boolean for later retrieval.
Definition ObjectConverter.hpp:121
const Color & getColor()
Retrieves the saved color.
ObjectConverter(std::shared_ptr< RendererData > data)
Stores render data for later retrieval.
Definition ObjectConverter.hpp:188
const Texture & getTexture()
Retrieves the saved texture.
ObjectConverter(const Outline &outline)
Stores an outline object for later retrieval.
Definition ObjectConverter.hpp:144
ObjectConverter(Color color)
Stores a color object for later retrieval.
Definition ObjectConverter.hpp:110
const std::shared_ptr< RendererData > & getRenderer()
Retrieves the saved renderer data.
ObjectConverter(const Texture &texture)
Stores a texture object for later retrieval.
Definition ObjectConverter.hpp:155
const String & getString()
Retrieves the saved string.
ObjectConverter()
Default constructor, to create an empty object.
Definition ObjectConverter.hpp:66
ObjectConverter(const char *string)
Stores a string for later retrieval.
Definition ObjectConverter.hpp:76
ObjectConverter(Font font)
Stores a font object for later retrieval.
Definition ObjectConverter.hpp:99
ObjectConverter(TextStyle style)
Stores a single text style for later retrieval.
Definition ObjectConverter.hpp:166
Type getType() const
Retrieves the type of the object that has been stored.
ObjectConverter(const String &string)
Stores a string for later retrieval.
Definition ObjectConverter.hpp:86
ObjectConverter(T number)
Stores a number for later retrieval.
Definition ObjectConverter.hpp:133
ObjectConverter(TextStyles style)
Stores a text style for later retrieval.
Definition ObjectConverter.hpp:177
const Outline & getOutline()
Retrieves the saved outline.
const TextStyles & getTextStyle()
Retrieves the saved text style.
bool operator==(const ObjectConverter &right) const
Check if the object equals another one.
float getNumber()
Retrieves the saved number.
Definition Outline.hpp:38
Wrapper class to store strings.
Definition String.hpp:94
Wrapper for text styles.
Definition TextStyle.hpp:55
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:53
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
TextStyle
Enumeration of the text drawing styles.
Definition TextStyle.hpp:38
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:47