Enumerations | Functions
Text.h File Reference
#include <SFML/Graphics/Export.h>
#include <SFML/Graphics/Color.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/Types.h>
#include <SFML/Graphics/Transform.h>
#include <SFML/System/Vector2.h>
#include <stddef.h>

Go to the source code of this file.

Enumerations

enum  sfTextStyle {
  sfTextRegular = 0,
  sfTextBold = 1 << 0,
  sfTextItalic = 1 << 1,
  sfTextUnderlined = 1 << 2,
  sfTextStrikeThrough = 1 << 3
}
 sfText styles More...
 

Functions

CSFML_GRAPHICS_API sfTextsfText_create (void)
 Create a new text. More...
 
CSFML_GRAPHICS_API sfTextsfText_copy (const sfText *text)
 Copy an existing text. More...
 
CSFML_GRAPHICS_API void sfText_destroy (sfText *text)
 Destroy an existing text. More...
 
CSFML_GRAPHICS_API void sfText_setPosition (sfText *text, sfVector2f position)
 Set the position of a text. More...
 
CSFML_GRAPHICS_API void sfText_setRotation (sfText *text, float angle)
 Set the orientation of a text. More...
 
CSFML_GRAPHICS_API void sfText_setScale (sfText *text, sfVector2f scale)
 Set the scale factors of a text. More...
 
CSFML_GRAPHICS_API void sfText_setOrigin (sfText *text, sfVector2f origin)
 Set the local origin of a text. More...
 
CSFML_GRAPHICS_API sfVector2f sfText_getPosition (const sfText *text)
 Get the position of a text. More...
 
CSFML_GRAPHICS_API float sfText_getRotation (const sfText *text)
 Get the orientation of a text. More...
 
CSFML_GRAPHICS_API sfVector2f sfText_getScale (const sfText *text)
 Get the current scale of a text. More...
 
CSFML_GRAPHICS_API sfVector2f sfText_getOrigin (const sfText *text)
 Get the local origin of a text. More...
 
CSFML_GRAPHICS_API void sfText_move (sfText *text, sfVector2f offset)
 Move a text by a given offset. More...
 
CSFML_GRAPHICS_API void sfText_rotate (sfText *text, float angle)
 Rotate a text. More...
 
CSFML_GRAPHICS_API void sfText_scale (sfText *text, sfVector2f factors)
 Scale a text. More...
 
CSFML_GRAPHICS_API sfTransform sfText_getTransform (const sfText *text)
 Get the combined transform of a text. More...
 
CSFML_GRAPHICS_API sfTransform sfText_getInverseTransform (const sfText *text)
 Get the inverse of the combined transform of a text. More...
 
CSFML_GRAPHICS_API void sfText_setString (sfText *text, const char *string)
 Set the string of a text (from an ANSI string) More...
 
CSFML_GRAPHICS_API void sfText_setUnicodeString (sfText *text, const sfUint32 *string)
 Set the string of a text (from a unicode string) More...
 
CSFML_GRAPHICS_API void sfText_setFont (sfText *text, const sfFont *font)
 Set the font of a text. More...
 
CSFML_GRAPHICS_API void sfText_setCharacterSize (sfText *text, unsigned int size)
 Set the character size of a text. More...
 
CSFML_GRAPHICS_API void sfText_setStyle (sfText *text, sfUint32 style)
 Set the style of a text. More...
 
CSFML_GRAPHICS_API void sfText_setColor (sfText *text, sfColor color)
 Set the fill color of a text. More...
 
CSFML_GRAPHICS_API void sfText_setFillColor (sfText *text, sfColor color)
 Set the fill color of a text. More...
 
CSFML_GRAPHICS_API void sfText_setOutlineColor (sfText *text, sfColor color)
 Set the outline color of the text. More...
 
CSFML_GRAPHICS_API void sfText_setOutlineThickness (sfText *text, float thickness)
 Set the thickness of the text's outline. More...
 
CSFML_GRAPHICS_API const char * sfText_getString (const sfText *text)
 Get the string of a text (returns an ANSI string) More...
 
CSFML_GRAPHICS_API const sfUint32sfText_getUnicodeString (const sfText *text)
 Get the string of a text (returns a unicode string) More...
 
CSFML_GRAPHICS_API const sfFontsfText_getFont (const sfText *text)
 Get the font used by a text. More...
 
CSFML_GRAPHICS_API unsigned int sfText_getCharacterSize (const sfText *text)
 Get the size of the characters of a text. More...
 
CSFML_GRAPHICS_API sfUint32 sfText_getStyle (const sfText *text)
 Get the style of a text. More...
 
CSFML_GRAPHICS_API sfColor sfText_getColor (const sfText *text)
 Get the fill color of a text. More...
 
CSFML_GRAPHICS_API sfColor sfText_getFillColor (const sfText *text)
 Get the fill color of a text. More...
 
CSFML_GRAPHICS_API sfColor sfText_getOutlineColor (const sfText *text)
 Get the outline color of a text. More...
 
CSFML_GRAPHICS_API float sfText_getOutlineThickness (const sfText *text)
 Get the outline thickness of a text. More...
 
CSFML_GRAPHICS_API sfVector2f sfText_findCharacterPos (const sfText *text, size_t index)
 Return the position of the index-th character in a text. More...
 
CSFML_GRAPHICS_API sfFloatRect sfText_getLocalBounds (const sfText *text)
 Get the local bounding rectangle of a text. More...
 
CSFML_GRAPHICS_API sfFloatRect sfText_getGlobalBounds (const sfText *text)
 Get the global bounding rectangle of a text. More...
 

Enumeration Type Documentation

◆ sfTextStyle

sfText styles

Enumerator
sfTextRegular 

Regular characters, no style.

sfTextBold 

Bold characters.

sfTextItalic 

Italic characters.

sfTextUnderlined 

Underlined characters.

sfTextStrikeThrough 

Strike through characters.

Definition at line 43 of file Text.h.

Function Documentation

◆ sfText_copy()

CSFML_GRAPHICS_API sfText* sfText_copy ( const sfText text)

Copy an existing text.

Parameters
textText to copy
Returns
Copied object

◆ sfText_create()

CSFML_GRAPHICS_API sfText* sfText_create ( void  )

Create a new text.

Returns
A new sfText object, or NULL if it failed

◆ sfText_destroy()

CSFML_GRAPHICS_API void sfText_destroy ( sfText text)

Destroy an existing text.

Parameters
textText to delete

◆ sfText_findCharacterPos()

CSFML_GRAPHICS_API sfVector2f sfText_findCharacterPos ( const sfText text,
size_t  index 
)

Return the position of the index-th character in a text.

This function computes the visual position of a character from its index in the string. The returned position is in global coordinates (translation, rotation, scale and origin are applied). If index is out of range, the position of the end of the string is returned.

Parameters
textText object
indexIndex of the character
Returns
Position of the character

◆ sfText_getCharacterSize()

CSFML_GRAPHICS_API unsigned int sfText_getCharacterSize ( const sfText text)

Get the size of the characters of a text.

Parameters
textText object
Returns
Size of the characters

◆ sfText_getColor()

CSFML_GRAPHICS_API sfColor sfText_getColor ( const sfText text)

Get the fill color of a text.

Parameters
textText object
Returns
Fill color of the text
Deprecated:
This function is deprecated and may be removed in future releases. Use sfText_getFillColor instead.

◆ sfText_getFillColor()

CSFML_GRAPHICS_API sfColor sfText_getFillColor ( const sfText text)

Get the fill color of a text.

Parameters
textText object
Returns
Fill color of the text

◆ sfText_getFont()

CSFML_GRAPHICS_API const sfFont* sfText_getFont ( const sfText text)

Get the font used by a text.

If the text has no font attached, a NULL pointer is returned. The returned pointer is const, which means that you can't modify the font when you retrieve it with this function.

Parameters
textText object
Returns
Pointer to the font

◆ sfText_getGlobalBounds()

CSFML_GRAPHICS_API sfFloatRect sfText_getGlobalBounds ( const sfText text)

Get the global bounding rectangle of a text.

The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the text in the global 2D world's coordinate system.

Parameters
textText object
Returns
Global bounding rectangle of the entity

◆ sfText_getInverseTransform()

CSFML_GRAPHICS_API sfTransform sfText_getInverseTransform ( const sfText text)

Get the inverse of the combined transform of a text.

Parameters
textText object
Returns
Inverse of the combined transformations applied to the object

◆ sfText_getLocalBounds()

CSFML_GRAPHICS_API sfFloatRect sfText_getLocalBounds ( const sfText text)

Get the local bounding rectangle of a text.

The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.

Parameters
textText object
Returns
Local bounding rectangle of the entity

◆ sfText_getOrigin()

CSFML_GRAPHICS_API sfVector2f sfText_getOrigin ( const sfText text)

Get the local origin of a text.

Parameters
textText object
Returns
Current origin

◆ sfText_getOutlineColor()

CSFML_GRAPHICS_API sfColor sfText_getOutlineColor ( const sfText text)

Get the outline color of a text.

Parameters
textText object
Returns
Outline color of the text

◆ sfText_getOutlineThickness()

CSFML_GRAPHICS_API float sfText_getOutlineThickness ( const sfText text)

Get the outline thickness of a text.

Parameters
textText object
Returns
Outline thickness of a text, in pixels

◆ sfText_getPosition()

CSFML_GRAPHICS_API sfVector2f sfText_getPosition ( const sfText text)

Get the position of a text.

Parameters
textText object
Returns
Current position

◆ sfText_getRotation()

CSFML_GRAPHICS_API float sfText_getRotation ( const sfText text)

Get the orientation of a text.

The rotation is always in the range [0, 360].

Parameters
textText object
Returns
Current rotation, in degrees

◆ sfText_getScale()

CSFML_GRAPHICS_API sfVector2f sfText_getScale ( const sfText text)

Get the current scale of a text.

Parameters
textText object
Returns
Current scale factors

◆ sfText_getString()

CSFML_GRAPHICS_API const char* sfText_getString ( const sfText text)

Get the string of a text (returns an ANSI string)

Parameters
textText object
Returns
String as a locale-dependant ANSI string

◆ sfText_getStyle()

CSFML_GRAPHICS_API sfUint32 sfText_getStyle ( const sfText text)

Get the style of a text.

Parameters
textText object
Returns
Current string style (see sfTextStyle enum)

◆ sfText_getTransform()

CSFML_GRAPHICS_API sfTransform sfText_getTransform ( const sfText text)

Get the combined transform of a text.

Parameters
textText object
Returns
Transform combining the position/rotation/scale/origin of the object

◆ sfText_getUnicodeString()

CSFML_GRAPHICS_API const sfUint32* sfText_getUnicodeString ( const sfText text)

Get the string of a text (returns a unicode string)

Parameters
textText object
Returns
String as UTF-32

◆ sfText_move()

CSFML_GRAPHICS_API void sfText_move ( sfText text,
sfVector2f  offset 
)

Move a text by a given offset.

This function adds to the current position of the object, unlike sfText_setPosition which overwrites it.

Parameters
textText object
offsetOffset

◆ sfText_rotate()

CSFML_GRAPHICS_API void sfText_rotate ( sfText text,
float  angle 
)

Rotate a text.

This function adds to the current rotation of the object, unlike sfText_setRotation which overwrites it.

Parameters
textText object
angleAngle of rotation, in degrees

◆ sfText_scale()

CSFML_GRAPHICS_API void sfText_scale ( sfText text,
sfVector2f  factors 
)

Scale a text.

This function multiplies the current scale of the object, unlike sfText_setScale which overwrites it.

Parameters
textText object
factorsScale factors

◆ sfText_setCharacterSize()

CSFML_GRAPHICS_API void sfText_setCharacterSize ( sfText text,
unsigned int  size 
)

Set the character size of a text.

The default size is 30.

Parameters
textText object
sizeNew character size, in pixels

◆ sfText_setColor()

CSFML_GRAPHICS_API void sfText_setColor ( sfText text,
sfColor  color 
)

Set the fill color of a text.

By default, the text's fill color is opaque white. Setting the fill color to a transparent color with an outline will cause the outline to be displayed in the fill area of the text.

Parameters
textText object
colorNew fill color of the text
Deprecated:
This function is deprecated and may be removed in future releases. Use sfText_setFillColor instead.

◆ sfText_setFillColor()

CSFML_GRAPHICS_API void sfText_setFillColor ( sfText text,
sfColor  color 
)

Set the fill color of a text.

By default, the text's fill color is opaque white. Setting the fill color to a transparent color with an outline will cause the outline to be displayed in the fill area of the text.

Parameters
textText object
colorNew fill color of the text

◆ sfText_setFont()

CSFML_GRAPHICS_API void sfText_setFont ( sfText text,
const sfFont font 
)

Set the font of a text.

The font argument refers to a texture that must exist as long as the text uses it. Indeed, the text doesn't store its own copy of the font, but rather keeps a pointer to the one that you passed to this function. If the font is destroyed and the text tries to use it, the behaviour is undefined.

Parameters
textText object
fontNew font

◆ sfText_setOrigin()

CSFML_GRAPHICS_API void sfText_setOrigin ( sfText text,
sfVector2f  origin 
)

Set the local origin of a text.

The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a text object is (0, 0).

Parameters
textText object
originNew origin

◆ sfText_setOutlineColor()

CSFML_GRAPHICS_API void sfText_setOutlineColor ( sfText text,
sfColor  color 
)

Set the outline color of the text.

By default, the text's outline color is opaque black.

Parameters
textText object
colorNew outline color of the text

◆ sfText_setOutlineThickness()

CSFML_GRAPHICS_API void sfText_setOutlineThickness ( sfText text,
float  thickness 
)

Set the thickness of the text's outline.

By default, the outline thickness is 0.

Be aware that using a negative value for the outline thickness will cause distorted rendering.

Parameters
thicknessNew outline thickness, in pixels
See also
getOutlineThickness

◆ sfText_setPosition()

CSFML_GRAPHICS_API void sfText_setPosition ( sfText text,
sfVector2f  position 
)

Set the position of a text.

This function completely overwrites the previous position. See sfText_move to apply an offset based on the previous position instead. The default position of a text Text object is (0, 0).

Parameters
textText object
positionNew position

◆ sfText_setRotation()

CSFML_GRAPHICS_API void sfText_setRotation ( sfText text,
float  angle 
)

Set the orientation of a text.

This function completely overwrites the previous rotation. See sfText_rotate to add an angle based on the previous rotation instead. The default rotation of a text Text object is 0.

Parameters
textText object
angleNew rotation, in degrees

◆ sfText_setScale()

CSFML_GRAPHICS_API void sfText_setScale ( sfText text,
sfVector2f  scale 
)

Set the scale factors of a text.

This function completely overwrites the previous scale. See sfText_scale to add a factor based on the previous scale instead. The default scale of a text Text object is (1, 1).

Parameters
textText object
scaleNew scale factors

◆ sfText_setString()

CSFML_GRAPHICS_API void sfText_setString ( sfText text,
const char *  string 
)

Set the string of a text (from an ANSI string)

A text's string is empty by default.

Parameters
textText object
stringNew string

◆ sfText_setStyle()

CSFML_GRAPHICS_API void sfText_setStyle ( sfText text,
sfUint32  style 
)

Set the style of a text.

You can pass a combination of one or more styles, for example sfTextBold | sfTextItalic. The default style is sfTextRegular.

Parameters
textText object
styleNew style

◆ sfText_setUnicodeString()

CSFML_GRAPHICS_API void sfText_setUnicodeString ( sfText text,
const sfUint32 string 
)

Set the string of a text (from a unicode string)

Parameters
textText object
stringNew string