TGUI  0.8.6
ObjectConverter.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2019 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{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) :
210  ObjectConverter(TextStyle(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 
280  const Outline& getOutline();
281 
282 
290  bool getBool();
291 
292 
301  float getNumber();
302 
303 
312  Texture& getTexture();
313  // TGUI_NEXT: const reference
314 
315 
324  const TextStyle& getTextStyle();
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 
367  Variant<sf::String, Font, Color, Outline, bool, float, Texture, TextStyle, std::shared_ptr<RendererData>> m_value;
368 
369  bool m_serialized = false;
370  sf::String m_string;
371  };
372 
374 }
375 
377 
378 #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:234
Definition: Font.hpp:42
ObjectConverter(bool value)
Stores a boolean for later retrieval.
Definition: ObjectConverter.hpp:154
ObjectConverter(const sf::String &string)
Stores a string for later retrieval.
Definition: ObjectConverter.hpp:102
ObjectConverter(const Texture &texture)
Stores a texture object for later retrieval.
Definition: ObjectConverter.hpp:194
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Wrapper for colors.
Definition: Color.hpp:48
ObjectConverter(sf::Text::Style style)
Stores a text style for later retrieval.
Definition: ObjectConverter.hpp:209
ObjectConverter(const Outline &outline)
Stores an outline object for later retrieval.
Definition: ObjectConverter.hpp:181
Definition: Texture.hpp:41
Wrapper class to store strings.
Definition: String.hpp:115
ObjectConverter(TextStyle style)
Stores a text style for later retrieval.
Definition: ObjectConverter.hpp:221
Definition: Outline.hpp:38
ObjectConverter(sf::Color color)
Stores a color object for later retrieval.
Definition: ObjectConverter.hpp:130
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:168
ObjectConverter(const std::string &string)
Stores a string for later retrieval.
Definition: ObjectConverter.hpp:91
ObjectConverter(Color color)
Stores a color object for later retrieval.
Definition: ObjectConverter.hpp:142
ObjectConverter(Font font)
Stores a font object for later retrieval.
Definition: ObjectConverter.hpp:117
Wrapper for text styles.
Definition: TextStyle.hpp:46
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:41