TGUI  1.4.0
Loading...
Searching...
No Matches
ObjectConverter.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_OBJECT_CONVERTER_HPP
26#define TGUI_OBJECT_CONVERTER_HPP
27
28#include <TGUI/TextStyle.hpp>
29#include <TGUI/Variant.hpp>
30#include <TGUI/Outline.hpp>
31#include <TGUI/Texture.hpp>
32#include <TGUI/Color.hpp>
33#include <TGUI/Font.hpp>
34
36
37TGUI_MODULE_EXPORT namespace tgui
38{
39 struct RendererData;
40
45 class TGUI_API ObjectConverter
46 {
47 public:
48 enum class Type
49 {
50 None,
51 Bool,
52 Font,
53 Color,
54 String,
55 Number,
56 Outline,
57 Texture,
60 };
61
66 m_type{Type::None}
67 {
68 }
69
75 ObjectConverter(const char* string) :
76 ObjectConverter{String{string}}
77 {
78 }
79
85 ObjectConverter(const String& string) :
86 m_type {Type::String},
87 m_value {string},
88 m_serialized{true},
89 m_string {string}
90 {
91 }
92
99 m_type {Type::Font},
100 m_value{std::move(font)}
101 {
102 }
103
110 m_type {Type::Color},
111 m_value{color}
112 {
113 }
114
120 ObjectConverter(bool value) :
121 m_type {Type::Bool},
122 m_value{value}
123 {
124 }
125
131 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic<T>::value, T>>
132 ObjectConverter(T number) :
133 m_type {Type::Number},
134 m_value{static_cast<float>(number)}
135 {
136 }
137
143 ObjectConverter(const Outline& outline) :
144 m_type {Type::Outline},
145 m_value{outline}
146 {
147 }
148
154 ObjectConverter(const Texture& texture) :
155 m_type {Type::Texture},
156 m_value{texture}
157 {
158 }
159
166 m_type {Type::TextStyle},
167 m_value{TextStyles(style)}
168 {
169 }
170
177 m_type {Type::TextStyle},
178 m_value{style}
179 {
180 }
181
187 ObjectConverter(std::shared_ptr<RendererData> data) :
188 m_type {Type::RendererData},
189 m_value{std::move(data)}
190 {
191 }
192
198 TGUI_NODISCARD const String& getString();
199
207 TGUI_NODISCARD const Font& getFont();
208
216 TGUI_NODISCARD const Color& getColor();
217
225 TGUI_NODISCARD const Outline& getOutline();
226
234 TGUI_NODISCARD bool getBool();
235
243 TGUI_NODISCARD float getNumber();
244
252 TGUI_NODISCARD const Texture& getTexture();
253
261 TGUI_NODISCARD const TextStyles& getTextStyle();
262
270 TGUI_NODISCARD const std::shared_ptr<RendererData>& getRenderer();
271
277 TGUI_NODISCARD Type getType() const;
278
284 TGUI_NODISCARD bool operator==(const ObjectConverter& right) const;
285
291 TGUI_NODISCARD bool operator!=(const ObjectConverter& right) const;
292
294 private:
295 Type m_type = Type::None;
296
298
299 bool m_serialized = false;
300 String m_string;
301 };
302
304}
305
307
308#endif // TGUI_OBJECT_CONVERTER_HPP
Wrapper for colors.
Definition Color.hpp:73
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:58
Implicit converter for settable properties.
Definition ObjectConverter.hpp:46
TGUI_NODISCARD const Outline & getOutline()
Retrieves the saved outline.
TGUI_NODISCARD const std::shared_ptr< RendererData > & getRenderer()
Retrieves the saved renderer data.
TGUI_NODISCARD const String & getString()
Retrieves the saved string.
TGUI_NODISCARD const Texture & getTexture()
Retrieves the saved texture.
ObjectConverter(bool value)
Stores a boolean for later retrieval.
Definition ObjectConverter.hpp:120
ObjectConverter(std::shared_ptr< RendererData > data)
Stores render data for later retrieval.
Definition ObjectConverter.hpp:187
TGUI_NODISCARD bool getBool()
Retrieves the saved boolean.
ObjectConverter(const Outline &outline)
Stores an outline object for later retrieval.
Definition ObjectConverter.hpp:143
ObjectConverter(Color color)
Stores a color object for later retrieval.
Definition ObjectConverter.hpp:109
ObjectConverter(const Texture &texture)
Stores a texture object for later retrieval.
Definition ObjectConverter.hpp:154
TGUI_NODISCARD bool operator!=(const ObjectConverter &right) const
Check if the object differs from another one.
TGUI_NODISCARD const Font & getFont()
Retrieves the saved font.
TGUI_NODISCARD bool operator==(const ObjectConverter &right) const
Check if the object equals another one.
ObjectConverter()
Default constructor, to create an empty object.
Definition ObjectConverter.hpp:65
ObjectConverter(const char *string)
Stores a string for later retrieval.
Definition ObjectConverter.hpp:75
ObjectConverter(Font font)
Stores a font object for later retrieval.
Definition ObjectConverter.hpp:98
ObjectConverter(TextStyle style)
Stores a single text style for later retrieval.
Definition ObjectConverter.hpp:165
TGUI_NODISCARD Type getType() const
Retrieves the type of the object that has been stored.
TGUI_NODISCARD const TextStyles & getTextStyle()
Retrieves the saved text style.
TGUI_NODISCARD const Color & getColor()
Retrieves the saved color.
ObjectConverter(const String &string)
Stores a string for later retrieval.
Definition ObjectConverter.hpp:85
TGUI_NODISCARD float getNumber()
Retrieves the saved number.
ObjectConverter(T number)
Stores a number for later retrieval.
Definition ObjectConverter.hpp:132
ObjectConverter(TextStyles style)
Stores a text style for later retrieval.
Definition ObjectConverter.hpp:176
Definition Outline.hpp:38
Wrapper class to store strings.
Definition String.hpp:96
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:57
Definition Variant.hpp:94
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
TextStyle
Enumeration of the text drawing styles.
Definition TextStyle.hpp:38
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:48