TGUI  0.9-dev
ObjectConverter.hpp
1 //
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 
39 namespace 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,
60  TextStyle,
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{TextStyle(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 
221  const String& getString();
222 
223 
232  const Font& getFont();
233 
234 
243  const Color& getColor();
244 
245 
254  const Outline& getOutline();
255 
256 
264  bool getBool();
265 
266 
275  float getNumber();
276 
277 
286  const Texture& getTexture();
287 
288 
297  const TextStyle& getTextStyle();
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 
340  Variant<String, Font, Color, Outline, bool, float, Texture, TextStyle, std::shared_ptr<RendererData>> m_value;
341 
342  bool m_serialized = false;
343  String m_string;
344  };
345 
347 }
348 
350 
351 #endif // TGUI_OBJECT_CONVERTER_HPP
ObjectConverter()
Default constructor, to create an empty object.
Definition: ObjectConverter.hpp:69
ObjectConverter(std::shared_ptr< RendererData > data)
Stores render data for later retrieval.
Definition: ObjectConverter.hpp:208
Definition: Font.hpp:42
ObjectConverter(bool value)
Stores a boolean for later retrieval.
Definition: ObjectConverter.hpp:131
ObjectConverter(const Texture &texture)
Stores a texture object for later retrieval.
Definition: ObjectConverter.hpp:171
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:35
ObjectConverter(const String &string)
Stores a string for later retrieval.
Definition: ObjectConverter.hpp:91
Wrapper for colors.
Definition: Color.hpp:47
Style
Enumeration of the string drawing styles.
Definition: TextStyle.hpp:51
ObjectConverter(const Outline &outline)
Stores an outline object for later retrieval.
Definition: ObjectConverter.hpp:158
Definition: Texture.hpp:42
Wrapper class to store strings.
Definition: String.hpp:70
ObjectConverter(TextStyle style)
Stores a text style for later retrieval.
Definition: ObjectConverter.hpp:195
Definition: Outline.hpp:38
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:47
ObjectConverter(const char *string)
Stores a string for later retrieval.
Definition: ObjectConverter.hpp:80
ObjectConverter(T number)
Stores a number for later retrieval.
Definition: ObjectConverter.hpp:145
ObjectConverter(TextStyle::Style style)
Stores a single text style for later retrieval.
Definition: ObjectConverter.hpp:183
ObjectConverter(Color color)
Stores a color object for later retrieval.
Definition: ObjectConverter.hpp:119
ObjectConverter(Font font)
Stores a font object for later retrieval.
Definition: ObjectConverter.hpp:106
Wrapper for text styles.
Definition: TextStyle.hpp:44
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:41