TGUI  0.8.9
ObjectConverter.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 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{sf::String{string}}
82 {
83 }
84
85
91 ObjectConverter(const std::string& string) :
92 ObjectConverter{sf::String{string}}
93 {
94 }
95
96
102 ObjectConverter(const sf::String& string) :
103 m_type {Type::String},
104 m_value {string},
105 m_serialized{true},
106 m_string {string}
107 {
108 }
109
110
118 m_type {Type::Font},
119 m_value{std::move(font)}
120 {
121 }
122
123
130 ObjectConverter(sf::Color color) :
131 ObjectConverter(Color{color})
132 {
133 }
134
135
143 m_type {Type::Color},
144 m_value{color}
145 {
146 }
147
148
154 ObjectConverter(bool value) :
155 m_type {Type::Bool},
156 m_value{value}
157 {
158 }
159
160
167 template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
168 ObjectConverter(T number) :
169 m_type {Type::Number},
170 m_value{static_cast<float>(number)}
171 {
172 }
173
174
181 ObjectConverter(const Outline& outline) :
182 m_type {Type::Outline},
183 m_value{outline}
184 {
185 }
186
187
194 ObjectConverter(const Texture& texture) :
195 m_type {Type::Texture},
196 m_value{texture}
197 {
198 }
199
200
209 ObjectConverter(sf::Text::Style style) :
211 {
212 }
213
214
222 m_type {Type::TextStyle},
223 m_value{style}
224 {
225 }
226
227
234 ObjectConverter(std::shared_ptr<RendererData> data) :
235 m_type {Type::RendererData},
236 m_value{std::move(data)}
237 {
238 }
239
240
247 const sf::String& getString();
248
249
258 const Font& getFont();
259
260
269 const Color& getColor();
270
271
281
282
290 bool getBool();
291
292
301 float getNumber();
302
303
313 // TGUI_NEXT: const reference
314
315
325
326
335 const std::shared_ptr<RendererData>& getRenderer();
336
337
344 Type getType() const;
345
346
352 bool operator==(const ObjectConverter& right) const;
353
354
360 bool operator!=(const ObjectConverter& right) const;
361
362
364 private:
365 Type m_type = Type::None;
366
368
369 bool m_serialized = false;
370 sf::String m_string;
371 };
372
374}
375
377
378#endif // TGUI_OBJECT_CONVERTER_HPP
Wrapper for colors.
Definition: Color.hpp:49
Definition: Font.hpp:43
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:48
Texture & getTexture()
Retrieves the saved texture.
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:154
const Color & getColor()
Retrieves the saved color.
ObjectConverter(std::shared_ptr< RendererData > data)
Stores render data for later retrieval.
Definition: ObjectConverter.hpp:234
ObjectConverter(const Outline &outline)
Stores an outline object for later retrieval.
Definition: ObjectConverter.hpp:181
ObjectConverter(sf::Text::Style style)
Stores a text style for later retrieval.
Definition: ObjectConverter.hpp:209
const sf::String & getString()
Retrieves the saved string.
ObjectConverter(Color color)
Stores a color object for later retrieval.
Definition: ObjectConverter.hpp:142
ObjectConverter(const sf::String &string)
Stores a string for later retrieval.
Definition: ObjectConverter.hpp:102
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:194
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:117
ObjectConverter(TextStyle style)
Stores a text style for later retrieval.
Definition: ObjectConverter.hpp:221
ObjectConverter(sf::Color color)
Stores a color object for later retrieval.
Definition: ObjectConverter.hpp:130
Type getType() const
Retrieves the type of the object that has been stored.
ObjectConverter(const std::string &string)
Stores a string for later retrieval.
Definition: ObjectConverter.hpp:91
ObjectConverter(T number)
Stores a number for later retrieval.
Definition: ObjectConverter.hpp:168
const TextStyle & getTextStyle()
Retrieves the saved text style.
const Outline & getOutline()
Retrieves the saved outline.
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:119
Wrapper for text styles.
Definition: TextStyle.hpp:47
Definition: Texture.hpp:42
Definition: Variant.hpp:92
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:42