raylib-cpp
C++ object-oriented wrapper library for raylib.
Public Member Functions | Protected Member Functions | List of all members
raylib::Font Class Reference

Font type, includes texture and charSet array data. More...

Public Member Functions

 Font ()
 Retrieves the default Font.
 
 Font (const ::Font &font)
 
 Font (const ::Image &image, ::Color key, int firstChar)
 Loads a Font from the given image with a color key. More...
 
 Font (const Font &)=delete
 
 Font (const std::string &fileName)
 Loads a Font from the given file. More...
 
 Font (const std::string &fileName, int fontSize, int *fontChars=0, int charCount=0)
 Loads a Font from the given file, with generation parameters. More...
 
 Font (const std::string &fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount)
 Loads a font from memory, based on the given file type and file data. More...
 
 Font (Font &&other)
 
 Font (int baseSize, int glyphCount, int glyphPadding, ::Texture2D texture, ::Rectangle *recs=nullptr, ::GlyphInfo *glyphs=nullptr)
 
void DrawText (const char *text, ::Vector2 position, ::Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint=WHITE) const
 
void DrawText (const char *text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE) const
 Draw text using font and additional parameters.
 
void DrawText (const char *text, int posX, int posY, float fontSize, float spacing, ::Color tint=WHITE) const
 Draw text using font and additional parameters.
 
void DrawText (const int *codepoints, int count, ::Vector2 position, float fontSize, float spacing, ::Color tint={255, 255, 255, 255}) const
 Draw multiple character (codepoint)
 
void DrawText (const std::string &text, ::Vector2 position, ::Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint=WHITE) const
 
void DrawText (const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE) const
 Draw text using font and additional parameters.
 
void DrawText (const std::string &text, int posX, int posY, float fontSize, float spacing, ::Color tint=WHITE) const
 Draw text using font and additional parameters.
 
void DrawText (int codepoint, ::Vector2 position, float fontSize, ::Color tint={255, 255, 255, 255}) const
 Draw one character (codepoint)
 
int GetBaseSize () const
 Retrieves the baseSize value for the object. More...
 
int GetGlyphCount () const
 Retrieves the glyphCount value for the object. More...
 
int GetGlyphIndex (int character) const
 Get index position for a unicode character on font.
 
int GetGlyphPadding () const
 Retrieves the glyphPadding value for the object. More...
 
::GlyphInfo * GetGlyphs () const
 Retrieves the glyphs value for the object. More...
 
::RectangleGetRecs () const
 Retrieves the recs value for the object. More...
 
TextureUnmanaged GetTexture ()
 Get the texture atlas containing the glyphs.
 
::Image ImageText (const char *text, float fontSize, float spacing, ::Color tint) const
 Create an image from text (custom sprite font)
 
::Image ImageText (const std::string &text, float fontSize, float spacing, ::Color tint) const
 Create an image from text (custom sprite font)
 
bool IsValid () const
 Returns if the font is ready to be used.
 
void Load (const ::Image &image, ::Color key, int firstChar)
 
void Load (const std::string &fileName)
 Loads a font from a given file. More...
 
void Load (const std::string &fileName, int fontSize, int *fontChars, int charCount)
 Loads a font from a given file with generation parameters. More...
 
void Load (const std::string &fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount)
 
Vector2 MeasureText (const char *text, float fontSize, float spacing) const
 Measure string size for Font.
 
Vector2 MeasureText (const std::string &text, float fontSize, float spacing) const
 Measure string size for Font.
 
Fontoperator= (const ::Font &font)
 
Fontoperator= (const Font &)=delete
 
Fontoperator= (Font &&other) noexcept
 
void SetTexture (const ::Texture &newTexture)
 Set the texture atlas containing the glyphs.
 
void Unload ()
 

Protected Member Functions

void set (const ::Font &font)
 

Detailed Description

Font type, includes texture and charSet array data.

Definition at line 15 of file Font.hpp.

Constructor & Destructor Documentation

◆ Font() [1/4]

raylib::Font::Font ( const std::string &  fileName)
inline

Loads a Font from the given file.

Parameters
fileNameThe file name of the font to load.
Exceptions
raylib::RaylibExceptionThrows if the given font failed to initialize.

Definition at line 42 of file Font.hpp.

References Load().

◆ Font() [2/4]

raylib::Font::Font ( const std::string &  fileName,
int  fontSize,
int *  fontChars = 0,
int  charCount = 0 
)
inline

Loads a Font from the given file, with generation parameters.

Parameters
fileNameThe file name of the font to load.
Exceptions
raylib::RaylibExceptionThrows if the given font failed to initialize.
See also
LoadFontEx

Definition at line 53 of file Font.hpp.

References Load().

◆ Font() [3/4]

raylib::Font::Font ( const ::Image image,
::Color  key,
int  firstChar 
)
inline

Loads a Font from the given image with a color key.

Parameters
imageThe image to load the fond from.
Exceptions
raylib::RaylibExceptionThrows if the given font failed to initialize.
See also
::LoadFontFromImage()

Definition at line 66 of file Font.hpp.

References Load().

◆ Font() [4/4]

raylib::Font::Font ( const std::string &  fileType,
const unsigned char *  fileData,
int  dataSize,
int  fontSize,
int *  fontChars,
int  charsCount 
)
inline

Loads a font from memory, based on the given file type and file data.

Exceptions
raylib::RaylibExceptionThrows if the given font failed to initialize.
See also
::LoadFontFromMemory()

Definition at line 75 of file Font.hpp.

References Load().

Member Function Documentation

◆ GetBaseSize()

int raylib::Font::GetBaseSize ( ) const
inline

Retrieves the baseSize value for the object.

Returns
The baseSize value of the object.

Definition at line 108 of file Font.hpp.

◆ GetGlyphCount()

int raylib::Font::GetGlyphCount ( ) const
inline

Retrieves the glyphCount value for the object.

Returns
The glyphCount value of the object.

Definition at line 109 of file Font.hpp.

◆ GetGlyphPadding()

int raylib::Font::GetGlyphPadding ( ) const
inline

Retrieves the glyphPadding value for the object.

Returns
The glyphPadding value of the object.

Definition at line 110 of file Font.hpp.

◆ GetGlyphs()

::GlyphInfo* raylib::Font::GetGlyphs ( ) const
inline

Retrieves the glyphs value for the object.

Returns
The glyphs value of the object.

Definition at line 112 of file Font.hpp.

◆ GetRecs()

::Rectangle* raylib::Font::GetRecs ( ) const
inline

Retrieves the recs value for the object.

Returns
The recs value of the object.

Definition at line 111 of file Font.hpp.

◆ Load() [1/2]

void raylib::Font::Load ( const std::string &  fileName)
inline

Loads a font from a given file.

Parameters
fileNameThe filename of the font to load.
Exceptions
raylib::RaylibExceptionThrows if the given font failed to initialize.
See also
LoadFont()

Definition at line 159 of file Font.hpp.

References IsValid(), and raylib::LoadFont().

Referenced by Font().

◆ Load() [2/2]

void raylib::Font::Load ( const std::string &  fileName,
int  fontSize,
int *  fontChars,
int  charCount 
)
inline

Loads a font from a given file with generation parameters.

Parameters
fileNameThe filename of the font to load.
fontSizeThe desired size of the font.
Exceptions
raylib::RaylibExceptionThrows if the given font failed to initialize.
See also
LoadFontEx()

Definition at line 176 of file Font.hpp.

References IsValid(), and raylib::LoadFontEx().