TGUI  0.8-dev
Text.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_TEXT_HPP
27 #define TGUI_TEXT_HPP
28 
29 #include <TGUI/Font.hpp>
30 #include <TGUI/Color.hpp>
31 #include <TGUI/TextStyle.hpp>
32 #include <SFML/Graphics/Text.hpp>
33 #include <SFML/Graphics/Transformable.hpp>
34 
36 
37 namespace tgui
38 {
40 
41  class TGUI_API Text : public sf::Transformable
42  {
43  public:
44 
53  static unsigned int findBestTextSize(Font font, float height, int fit = 0);
54 
55 
61  static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyle style = sf::Text::Regular);
62 
63 
74  static sf::String wordWrap(float maxWidth, const sf::String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
75 
76 
77  public:
78 
85  sf::Vector2f getSize() const;
86 
87 
94  void setString(const sf::String& string);
95 
96 
103  const sf::String& getString() const;
104 
105 
112  void setCharacterSize(unsigned int size);
113 
114 
121  unsigned int getCharacterSize() const;
122 
123 
130  void setColor(Color color);
131 
132 
139  Color getColor() const;
140 
141 
148  void setOpacity(float opacity);
149 
150 
157  float getOpacity() const;
158 
159 
166  void setFont(Font font);
167 
168 
175  Font getFont() const;
176 
177 
188  void setStyle(TextStyle style);
189 
190 
197  TextStyle getStyle() const;
198 
199 
212  sf::Vector2f findCharacterPos(std::size_t index) const;
213 
214 
222  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
223 
224 
226  private:
227 
229  // Calculates the size of the text again after something changed.
231  void recalculateSize();
232 
233 
235  private:
236 
237  sf::Text m_text;
238  sf::Vector2f m_size;
239  Font m_font;
240  Color m_color;
241  float m_opacity = 1;
242  };
243 
245 }
246 
248 
249 #endif // TGUI_TEXT_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Wrapper for colors.
Definition: Color.hpp:46
Wrapper for text styles.
Definition: TextStyle.hpp:46
Definition: Font.hpp:41
Definition: Text.hpp:41