TGUI  0.8-dev
ObjectConverter.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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/Outline.hpp>
32 #include <TGUI/Texture.hpp>
33 #include <TGUI/Color.hpp>
34 #include <TGUI/Font.hpp>
35 #include <TGUI/Any.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  Font,
54  Color,
55  String,
56  Number,
57  Outline,
58  Texture,
59  TextStyle,
61  };
62 
63 
69  m_type{Type::None}
70  {
71  }
72 
73 
80  ObjectConverter(const sf::String& string) :
81  m_type {Type::String},
82  m_value {string},
83  m_serialized{true},
84  m_string {string}
85  {
86  }
87 
88 
96  m_type {Type::Font},
97  m_value{font}
98  {
99  }
100 
101 
108  ObjectConverter(sf::Color color) :
109  ObjectConverter(Color(color))
110  {
111  }
112 
113 
121  m_type {Type::Color},
122  m_value{color}
123  {
124  }
125 
126 
133  ObjectConverter(float number) :
134  m_type {Type::Number},
135  m_value{number}
136  {
137  }
138 
139 
146  ObjectConverter(const Outline& outline) :
147  m_type {Type::Outline},
148  m_value{outline}
149  {
150  }
151 
152 
159  ObjectConverter(const Texture& texture) :
160  m_type {Type::Texture},
161  m_value{texture}
162  {
163  }
164 
165 
174  ObjectConverter(sf::Text::Style style) :
175  ObjectConverter(TextStyle(style))
176  {
177  }
178 
179 
187  m_type {Type::TextStyle},
188  m_value{style}
189  {
190  }
191 
192 
199  ObjectConverter(std::shared_ptr<RendererData> data) :
200  m_type {Type::RendererData},
201  m_value{data}
202  {
203  }
204 
205 
212  const sf::String& getString();
213 
214 
223  const Font& getFont();
224 
225 
234  const Color& getColor();
235 
236 
245  const Outline& getOutline();
246 
247 
256  float getNumber();
257 
258 
267  Texture& getTexture();
268 
269 
278  const TextStyle& getTextStyle();
279 
280 
289  const std::shared_ptr<RendererData>& getRenderer();
290 
291 
298  Type getType() const;
299 
300 
302  private:
303  Type m_type = Type::None;
304  Any m_value;
305 
306  bool m_serialized = false;
307  sf::String m_string;
308  };
309 
311 }
312 
314 
315 #endif // TGUI_OBJECT_CONVERTER_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
ObjectConverter(const Texture &texture)
Stores a texture object for later retrieval.
Definition: ObjectConverter.hpp:159
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:40
Wrapper for colors.
Definition: Color.hpp:46
ObjectConverter(Color color)
Stores a color object for later retrieval.
Definition: ObjectConverter.hpp:120
Wrapper for text styles.
Definition: TextStyle.hpp:46
Definition: Font.hpp:41
ObjectConverter(std::shared_ptr< RendererData > data)
Stores render data for later retrieval.
Definition: ObjectConverter.hpp:199
ObjectConverter(float number)
Stores a number for later retrieval.
Definition: ObjectConverter.hpp:133
ObjectConverter(sf::Text::Style style)
Stores a text style for later retrieval.
Definition: ObjectConverter.hpp:174
ObjectConverter(const Outline &outline)
Stores a outline object for later retrieval.
Definition: ObjectConverter.hpp:146
Definition: Any.hpp:33
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:47
ObjectConverter(sf::Color color)
Stores a color object for later retrieval.
Definition: ObjectConverter.hpp:108
Definition: Texture.hpp:39
ObjectConverter(TextStyle style)
Stores a text style for later retrieval.
Definition: ObjectConverter.hpp:186
Definition: Outline.hpp:37
ObjectConverter()
Default constructor, to create an empty object.
Definition: ObjectConverter.hpp:68
ObjectConverter(Font font)
Stores a font object for later retrieval.
Definition: ObjectConverter.hpp:95
ObjectConverter(const sf::String &string)
Stores a string for later retrieval.
Definition: ObjectConverter.hpp:80