28#include <SFML/Graphics/String.hpp>
29#include <SFML/Graphics/Image.hpp>
30#include <SFML/Graphics/GraphicsContext.hpp>
40myFont (&
Font::GetDefaultFont()),
67 myNeedRectUpdate =
true;
79 myNeedRectUpdate =
true;
92 myNeedRectUpdate =
true;
106 myNeedRectUpdate =
true;
156 const Unicode::UTF32String& Text = myText;
159 if (
Index > Text.length())
160 Index = Text.length();
163 float FactorX = mySize / myFont->GetCharacterSize();
168 for (std::size_t
i = 0;
i <
Index; ++
i)
178 case L
' ' : Position.
x +=
AdvanceX;
break;
179 case L
'\t' : Position.
x +=
AdvanceX * 4;
break;
180 case L
'\v' : Position.
y +=
AdvanceY * 4;
break;
181 case L
'\n' : Position.
y +=
AdvanceY; Position.
x = 0;
break;
197 if (myNeedRectUpdate)
198 const_cast<String*
>(
this)->RecomputeRect();
216 const Unicode::UTF32String& Text = myText;
223 float CharSize =
static_cast<float>(myFont->GetCharacterSize());
228 myFont->GetImage().Bind();
243 for (std::size_t
i = 0;
i < Text.size(); ++
i)
263 case L
' ' : X += Advance;
continue;
264 case L
'\n' : Y +=
CharSize; X = 0;
continue;
265 case L
'\t' : X += Advance * 4;
continue;
266 case L
'\v' : Y +=
CharSize * 4;
continue;
279 static const float OffsetsX[] = {-0.5f, 0.5f, 0.f, 0.f};
280 static const float OffsetsY[] = {0.f, 0.f, -0.5f, 0.5f};
282 for (
int j = 0;
j < 4; ++
j)
324void String::RecomputeRect()
327 const Unicode::UTF32String& Text = myText;
330 myNeedRectUpdate =
false;
344 float Factor = mySize / myFont->GetCharacterSize();
347 for (std::size_t i = 0; i < Text.size(); ++i)
350 Uint32 CurChar = Text[i];
351 const Glyph& CurGlyph = myFont->GetGlyph(CurChar);
352 float Advance = CurGlyph.Advance * Factor;
353 const IntRect& Rect = CurGlyph.Rectangle;
358 case L
' ' : CurWidth += Advance;
continue;
359 case L
'\t' : CurWidth += Advance * 4;
continue;
360 case L
'\v' : Height += mySize * 4; CurHeight = 0;
continue;
365 if (CurWidth > Width)
375 float CharHeight = (myFont->GetCharacterSize() + Rect.Bottom) * Factor;
376 if (CharHeight > CurHeight)
377 CurHeight = CharHeight;
381 if (CurWidth > Width)
389 Height += 1 * Factor;
395 Width += 0.208f * mySize;
401 if (CurHeight < mySize + 4 * Factor)
402 Height += 4 * Factor;
408 myBaseRect.
Right = Width;
409 myBaseRect.
Bottom = Height;
const Vector2f & GetPosition() const
Get the position of the object.
const Vector2f & GetScale() const
Get the current scale of the object.
const Vector2f & GetCenter() const
Get the center of the object.
Font is the low-level class for loading and manipulating character fonts.
Structure describing a glyph (a visual character)
T Top
Top coordinate of the rectangle.
T Right
Right coordinate of the rectangle.
T Left
Left coordinate of the rectangle.
T Bottom
Bottom coordinate of the rectangle.
Base class for all render targets (window, image, ...)
String defines a graphical 2D text, that can be drawn on screen.
const Unicode::Text & GetText() const
Get the text (the returned text can be converted implicitely to any kind of string)
const Font & GetFont() const
Get the font used by the string.
void SetFont(const Font &CharFont)
Set the font of the string.
void SetSize(float Size)
Set the size of the string The default size is 30.
FloatRect GetRect() const
Get the string rectangle on screen.
void SetStyle(unsigned long TextStyle)
Set the style of the text The default style is Regular.
String()
Default constructor.
float GetSize() const
Get the size of the characters.
void SetText(const Unicode::Text &Text)
Set the text (from any kind of string)
virtual void Render(RenderTarget &Target) const
/see Drawable::Render
sf::Vector2f GetCharacterPos(std::size_t Index) const
Return the visual position of the Index-th character of the string, in coordinates relative to the st...
unsigned long GetStyle() const
Get the style of the text.
@ Bold
Characters are bold.
@ Underlined
Characters are underlined.
@ Italic
Characters are in italic.
This class is an abstract definition of a unicode text, it can be converted from and to any kind of s...
Vector2 is an utility class for manipulating 2 dimensional vectors.
T x
X coordinate of the vector.
T y
Y coordinate of the vector.