TGUI  0.9.5
Loading...
Searching...
No Matches
ObjectConverter.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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_OBJECT_CONVERTER_HPP
27#define TGUI_OBJECT_CONVERTER_HPP
28
29
30#include <TGUI/TextStyle.hpp>
31#include <TGUI/Variant.hpp>
32#include <TGUI/Outline.hpp>
33#include <TGUI/Texture.hpp>
34#include <TGUI/Color.hpp>
35#include <TGUI/Font.hpp>
36
38
39namespace tgui
40{
41 struct RendererData;
42
47 class TGUI_API ObjectConverter
48 {
49 public:
50 enum class Type
51 {
52 None,
53 Bool,
54 Font,
55 Color,
56 String,
57 Number,
58 Outline,
59 Texture,
62 };
63
64
70 m_type{Type::None}
71 {
72 }
73
74
80 ObjectConverter(const char* string) :
81 ObjectConverter{String{string}}
82 {
83 }
84
85
91 ObjectConverter(const String& string) :
92 m_type {Type::String},
93 m_value {string},
94 m_serialized{true},
95 m_string {string}
96 {
97 }
98
99
107 m_type {Type::Font},
108 m_value{std::move(font)}
109 {
110 }
111
112
120 m_type {Type::Color},
121 m_value{color}
122 {
123 }
124
125
131 ObjectConverter(bool value) :
132 m_type {Type::Bool},
133 m_value{value}
134 {
135 }
136
137
144 template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
145 ObjectConverter(T number) :
146 m_type {Type::Number},
147 m_value{static_cast<float>(number)}
148 {
149 }
150
151
158 ObjectConverter(const Outline& outline) :
159 m_type {Type::Outline},
160 m_value{outline}
161 {
162 }
163
164
171 ObjectConverter(const Texture& texture) :
172 m_type {Type::Texture},
173 m_value{texture}
174 {
175 }
176
177
184 m_type {Type::TextStyle},
185 m_value{TextStyles(style)}
186 {
187 }
188
189
196 m_type {Type::TextStyle},
197 m_value{style}
198 {
199 }
200
201
208 ObjectConverter(std::shared_ptr<RendererData> data) :
209 m_type {Type::RendererData},
210 m_value{std::move(data)}
211 {
212 }
213
214
222
223
232 const Font& getFont();
233
234
243 const Color& getColor();
244
245
255
256
264 bool getBool();
265
266
275 float getNumber();
276
277
287
288
298
299
308 const std::shared_ptr<RendererData>& getRenderer();
309
310
317 Type getType() const;
318
319
325 bool operator==(const ObjectConverter& right) const;
326
327
333 bool operator!=(const ObjectConverter& right) const;
334
335
337 private:
338 Type m_type = Type::None;
339
341
342 bool m_serialized = false;
343 String m_string;
344 };
345
347}
348
350
351#endif // TGUI_OBJECT_CONVERTER_HPP
Wrapper for colors.
Definition Color.hpp:63
Definition Font.hpp:56
Implicit converter for settable properties.
Definition ObjectConverter.hpp:48
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:131
const Color & getColor()
Retrieves the saved color.
ObjectConverter(std::shared_ptr< RendererData > data)
Stores render data for later retrieval.
Definition ObjectConverter.hpp:208
const Texture & getTexture()
Retrieves the saved texture.
ObjectConverter(const Outline &outline)
Stores an outline object for later retrieval.
Definition ObjectConverter.hpp:158
ObjectConverter(Color color)
Stores a color object for later retrieval.
Definition ObjectConverter.hpp:119
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:171
const String & getString()
Retrieves the saved string.
ObjectConverter()
Default constructor, to create an empty object.
Definition ObjectConverter.hpp:69
ObjectConverter(const char *string)
Stores a string for later retrieval.
Definition ObjectConverter.hpp:80
ObjectConverter(Font font)
Stores a font object for later retrieval.
Definition ObjectConverter.hpp:106
ObjectConverter(TextStyle style)
Stores a single text style for later retrieval.
Definition ObjectConverter.hpp:183
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:91
ObjectConverter(T number)
Stores a number for later retrieval.
Definition ObjectConverter.hpp:145
ObjectConverter(TextStyles style)
Stores a text style for later retrieval.
Definition ObjectConverter.hpp:195
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:39
Wrapper class to store strings.
Definition String.hpp:79
Wrapper for text styles.
Definition TextStyle.hpp:58
Definition Texture.hpp:49
Definition Variant.hpp:92
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
TextStyle
Enumeration of the text drawing styles.
Definition TextStyle.hpp:40
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:42