TGUI  0.8.7
Text.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_TEXT_HPP
27 #define TGUI_TEXT_HPP
28 
29 #include <TGUI/Font.hpp>
30 #include <TGUI/Color.hpp>
31 #include <TGUI/Vector2f.hpp>
32 #include <TGUI/TextStyle.hpp>
33 #include <SFML/Graphics/Text.hpp>
34 #include <SFML/Graphics/Transformable.hpp>
35 
37 
38 namespace tgui
39 {
41 
42  class TGUI_API Text : public sf::Transformable
43  {
44  public:
45 
46 #ifndef TGUI_REMOVE_DEPRECATED_CODE
47  TGUI_DEPRECATED("Use as (non-static) member function instead") static float getExtraHorizontalPadding(const Text& text);
51 #endif
52 
58  static float getExtraHorizontalPadding(Font font, unsigned int characterSize, TextStyle textStyle = {});
59 
60 
66  static float getExtraHorizontalOffset(Font font, unsigned int characterSize, TextStyle textStyle = {});
67 
68 
72  static float getExtraVerticalPadding(unsigned int characterSize);
73 
74 #ifndef TGUI_REMOVE_DEPRECATED_CODE
75  TGUI_DEPRECATED("Use as (non-static) member function instead") static float getLineHeight(const Text& text);
79 #endif
80 
84  static float getLineHeight(Font font, unsigned int characterSize, TextStyle textStyle = {});
85 
86 #ifndef TGUI_REMOVE_DEPRECATED_CODE
87  TGUI_DEPRECATED("Use as (non-static) member function instead") static float getLineWidth(const Text& text);
91 #endif
92 
96  static float getLineWidth(const sf::String &text, Font font, unsigned int characterSize, TextStyle textStyle = {});
97 
98 
107  static unsigned int findBestTextSize(Font font, float height, int fit = 0);
108 
109 
115  static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyle style = {});
116 
117 
129  static sf::String wordWrap(float maxWidth, const sf::String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
130 
131 
133  public:
134 
141  Vector2f getSize() const;
142 
143 
150  void setString(const sf::String& string);
151 
152 
159  const sf::String& getString() const;
160 
161 
168  void setCharacterSize(unsigned int size);
169 
170 
177  unsigned int getCharacterSize() const;
178 
179 
186  void setColor(Color color);
187 
188 
195  Color getColor() const;
196 
197 
204  void setOpacity(float opacity);
205 
206 
213  float getOpacity() const;
214 
215 
222  void setFont(Font font);
223 
224 
231  Font getFont() const;
232 
233 
244  void setStyle(TextStyle style);
245 
246 
253  TextStyle getStyle() const;
254 
255 
261  void setOutlineColor(Color color);
262 
263 
269  Color getOutlineColor() const;
270 
271 
277  void setOutlineThickness(float thickness);
278 
279 
285  float getOutlineThickness() const;
286 
287 
300  Vector2f findCharacterPos(std::size_t index) const;
301 
302 
310  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
311 
312 
318  float getExtraHorizontalPadding() const;
319 
320 
326  float getExtraHorizontalOffset() const;
327 
328 
332  float getLineHeight() const;
333 
334 
338  float getLineWidth() const;
339 
340 
342  private:
343 
345  // Calculates the size of the text again after something changed.
347  void recalculateSize();
348 
349 
351  private:
352 
353  sf::Text m_text;
354  Vector2f m_size;
355  Font m_font;
356  Color m_color;
357  Color m_outlineColor;
358  float m_opacity = 1;
359  };
360 
362 }
363 
365 
366 #endif // TGUI_TEXT_HPP
Definition: Font.hpp:42
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Text.hpp:42
Wrapper for colors.
Definition: Color.hpp:48
Definition: Vector2f.hpp:38
Wrapper for text styles.
Definition: TextStyle.hpp:46