Loading...
Searching...
No Matches
Text.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
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#ifndef SFML_TEXT_HPP
26#define SFML_TEXT_HPP
27
29// Headers
38#include <string>
39#include <vector>
40
41
42namespace sf
43{
49{
50public :
51
56 enum Style
57 {
58 Regular = 0,
59 Bold = 1 << 0,
60 Italic = 1 << 1,
61 Underlined = 1 << 2
62 };
63
71
80 Text(const String& string, const Font& font, unsigned int characterSize = 30);
81
101 void setString(const String& string);
102
118 void setFont(const Font& font);
119
130 void setCharacterSize(unsigned int size);
131
144 void setStyle(Uint32 style);
145
156 void setColor(const Color& color);
157
175 const String& getString() const;
176
189 const Font* getFont() const;
190
199 unsigned int getCharacterSize() const;
200
210
219 const Color& getColor() const;
220
236 Vector2f findCharacterPos(std::size_t index) const;
237
251
265
266private :
267
275 virtual void draw(RenderTarget& target, RenderStates states) const;
276
281 void updateGeometry();
282
284 // Member data
286 String m_string;
287 const Font* m_font;
288 unsigned int m_characterSize;
289 Uint32 m_style;
290 Color m_color;
291 VertexArray m_vertices;
292 FloatRect m_bounds;
293};
294
295} // namespace sf
296
297
298#endif // SFML_TEXT_HPP
299
300
#define SFML_GRAPHICS_API
Utility class for manpulating RGBA colors.
Definition Color.hpp:41
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:45
friend class RenderTarget
Definition Drawable.hpp:56
Class for loading and manipulating character fonts.
Definition Font.hpp:51
Define the states used for drawing to a RenderTarget.
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:44
Uint32 getStyle() const
Get the text's style.
void setFont(const Font &font)
Set the text's font.
Vector2f findCharacterPos(std::size_t index) const
Return the position of the index-th character.
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
unsigned int getCharacterSize() const
Get the character size.
Text(const String &string, const Font &font, unsigned int characterSize=30)
Construct the text from a string, font and size.
void setString(const String &string)
Set the text's string.
Style
Enumeration of the string drawing styles.
Definition Text.hpp:57
@ Regular
Regular characters, no style.
Definition Text.hpp:58
@ Underlined
Underlined characters.
Definition Text.hpp:61
@ Italic
Italic characters.
Definition Text.hpp:60
@ Bold
Bold characters.
Definition Text.hpp:59
const String & getString() const
Get the text's string.
const Color & getColor() const
Get the global color of the text.
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.
void setStyle(Uint32 style)
Set the text's style.
const Font * getFont() const
Get the text's font.
void setCharacterSize(unsigned int size)
Set the character size.
void setColor(const Color &color)
Set the global color of the text.
Text()
Default constructor.
Transformable()
Default constructor.
Define a set of one or more 2D primitives.
unsigned int Uint32
Definition Config.hpp:145
Vector2< float > Vector2f
Definition Vector2.hpp:255
Rect< float > FloatRect
Definition Rect.hpp:191