SFML 2.6.1

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

Loading...
Searching...
No Matches
Text.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
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
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/Drawable.hpp>
33#include <SFML/Graphics/Transformable.hpp>
34#include <SFML/Graphics/Font.hpp>
35#include <SFML/Graphics/Rect.hpp>
36#include <SFML/Graphics/VertexArray.hpp>
37#include <SFML/System/String.hpp>
38#include <string>
39#include <vector>
40
41
42 namespace sf
43{
48 class SFML_GRAPHICS_API Text : public Drawable, public Transformable
49{
50 public:
51
56 enum Style
57 {
58 Regular = 0,
59 Bold = 1 << 0,
60 Italic = 1 << 1,
61 Underlined = 1 << 2,
62 StrikeThrough = 1 << 3
63 };
64
71 Text();
72
88 Text(const String& string, const Font& font, unsigned int characterSize = 30);
89
109 void setString(const String& string);
110
126 void setFont(const Font& font);
127
145 void setCharacterSize(unsigned int size);
146
159 void setLineSpacing(float spacingFactor);
160
178 void setLetterSpacing(float spacingFactor);
179
192 void setStyle(Uint32 style);
193
210 SFML_DEPRECATED void setColor(const Color& color);
211
224 void setFillColor(const Color& color);
225
236 void setOutlineColor(const Color& color);
237
251 void setOutlineThickness(float thickness);
252
270 const String& getString() const;
271
284 const Font* getFont() const;
285
294 unsigned int getCharacterSize() const;
295
304 float getLetterSpacing() const;
305
314 float getLineSpacing() const;
315
324 Uint32 getStyle() const;
325
338 SFML_DEPRECATED const Color& getColor() const;
339
348 const Color& getFillColor() const;
349
358 const Color& getOutlineColor() const;
359
368 float getOutlineThickness() const;
369
385 Vector2f findCharacterPos(std::size_t index) const;
386
399 FloatRect getLocalBounds() const;
400
413 FloatRect getGlobalBounds() const;
414
415 private:
416
424 virtual void draw(RenderTarget& target, RenderStates states) const;
425
433 void ensureGeometryUpdate() const;
434
436 // Member data
438 String m_string;
439 const Font* m_font;
440 unsigned int m_characterSize;
441 float m_letterSpacingFactor;
442 float m_lineSpacingFactor;
443 Uint32 m_style;
444 Color m_fillColor;
445 Color m_outlineColor;
446 float m_outlineThickness;
447 mutable VertexArray m_vertices;
448 mutable VertexArray m_outlineVertices;
449 mutable FloatRect m_bounds;
450 mutable bool m_geometryNeedUpdate;
451 mutable Uint64 m_fontTextureId;
452};
453
454} // namespace sf
455
456
457#endif // SFML_TEXT_HPP
458
459
sf::Color
Utility class for manipulating RGBA colors.
Definition Color.hpp:41
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:45
sf::Font
Class for loading and manipulating character fonts.
Definition Font.hpp:49
sf::Rect< float >
sf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition RenderStates.hpp:46
sf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition RenderTarget.hpp:53
sf::String
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:46
sf::Text
Graphical text that can be drawn to a render target.
Definition Text.hpp:49
sf::Text::getLetterSpacing
float getLetterSpacing() const
Get the size of the letter spacing factor.
sf::Text::getStyle
Uint32 getStyle() const
Get the text's style.
sf::Text::getFillColor
const Color & getFillColor() const
Get the fill color of the text.
sf::Text::setFont
void setFont(const Font &font)
Set the text's font.
sf::Text::findCharacterPos
Vector2f findCharacterPos(std::size_t index) const
Return the position of the index-th character.
sf::Text::getLocalBounds
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
sf::Text::getCharacterSize
unsigned int getCharacterSize() const
Get the character size.
sf::Text::Text
Text(const String &string, const Font &font, unsigned int characterSize=30)
Construct the text from a string, font and size.
sf::Text::getLineSpacing
float getLineSpacing() const
Get the size of the line spacing factor.
sf::Text::setString
void setString(const String &string)
Set the text's string.
sf::Text::setOutlineColor
void setOutlineColor(const Color &color)
Set the outline color of the text.
sf::Text::Style
Style
Enumeration of the string drawing styles.
Definition Text.hpp:57
sf::Text::setOutlineThickness
void setOutlineThickness(float thickness)
Set the thickness of the text's outline.
sf::Text::getString
const String & getString() const
Get the text's string.
sf::Text::getColor
const Color & getColor() const
Get the fill color of the text.
sf::Text::setLetterSpacing
void setLetterSpacing(float spacingFactor)
Set the letter spacing factor.
sf::Text::setFillColor
void setFillColor(const Color &color)
Set the fill color of the text.
sf::Text::getGlobalBounds
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.
sf::Text::setStyle
void setStyle(Uint32 style)
Set the text's style.
sf::Text::getFont
const Font * getFont() const
Get the text's font.
sf::Text::getOutlineColor
const Color & getOutlineColor() const
Get the outline color of the text.
sf::Text::setCharacterSize
void setCharacterSize(unsigned int size)
Set the character size.
sf::Text::setLineSpacing
void setLineSpacing(float spacingFactor)
Set the line spacing factor.
sf::Text::getOutlineThickness
float getOutlineThickness() const
Get the outline thickness of the text.
sf::Text::setColor
void setColor(const Color &color)
Set the fill color of the text.
sf::Text::Text
Text()
Default constructor.
sf::Transformable
Decomposed transform defined by a position, a rotation and a scale.
Definition Transformable.hpp:42
sf::Vector2< float >
sf::VertexArray
Define a set of one or more 2D primitives.
Definition VertexArray.hpp:46