FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::sdl2::TrueTypeFont Class Reference

#include <truetypefont.hpp>

Inheritance diagram for fcn::sdl2::TrueTypeFont:
fcn::Font

Public Member Functions

void drawString (fcn::Graphics *graphics, std::string const &text, int x, int y) override
virtual int getGlyphSpacing ()
int getHeight () const override
virtual int getRowSpacing ()
int getWidth (std::string const &text) const override
virtual bool isAntiAlias ()
TrueTypeFontoperator= (TrueTypeFont &&)=delete
TrueTypeFontoperator= (TrueTypeFont const &)=delete
virtual void setAntiAlias (bool antiAlias)
virtual void setGlyphSpacing (int spacing)
virtual void setRowSpacing (int spacing)
 TrueTypeFont (std::string const &filename, int size)
 TrueTypeFont (TrueTypeFont &&)=delete
 TrueTypeFont (TrueTypeFont const &)=delete
Public Member Functions inherited from fcn::Font
 Font (Font &&)=default
 Font (Font const &)=default
virtual int getStringIndexAt (std::string const &text, int x) const
Font & operator= (Font &&)=default
Font & operator= (Font const &)=default

Protected Attributes

bool mAntiAlias
std::string mFilename
TTF_Font * mFont
int mGlyphSpacing
int mHeight {}
int mRowSpacing

Detailed Description

SDL2/FreeType implementation for rendering TrueType fonts.

It uses the SDL_ttf library to display True Type Fonts with SDL.

Note: initialize the SDL_ttf library (TTF_Init) before using this class and call TTF_Quit when finished.

Definition at line 29 of file truetypefont.hpp.

Constructor & Destructor Documentation

◆ TrueTypeFont()

fcn::sdl2::TrueTypeFont::TrueTypeFont ( std::string const & filename,
int size )

Constructor.

Parameters
filenamethe filename of the True Type Font.
sizethe size the font should be in.

Definition at line 18 of file truetypefont.cpp.

References mAntiAlias, mFilename, mFont, mGlyphSpacing, and mRowSpacing.

◆ ~TrueTypeFont()

fcn::sdl2::TrueTypeFont::~TrueTypeFont ( )
override

Definition at line 31 of file truetypefont.cpp.

Member Function Documentation

◆ drawString()

void fcn::sdl2::TrueTypeFont::drawString ( fcn::Graphics * graphics,
std::string const & text,
int x,
int y )
overridevirtual

Draws a string.

NOTE: You normally won't use this function to draw text since Graphics contains better functions for drawing text.

Parameters
Graphics & RenderingA Graphics object to use for drawing.
textThe string to draw.
xThe x coordinate where to draw the string.
yThe y coordinate where to draw the string.

Implements fcn::Font.

Definition at line 50 of file truetypefont.cpp.

References fcn::Color::a, fcn::Color::b, fcn::Color::g, fcn::Graphics::getColor(), getRowSpacing(), mAntiAlias, mFont, and fcn::Color::r.

◆ getGlyphSpacing()

int fcn::sdl2::TrueTypeFont::getGlyphSpacing ( )
virtual

Gets the spacing between letters in pixels.

Returns
the spacing.

Definition at line 128 of file truetypefont.cpp.

References mGlyphSpacing.

◆ getHeight()

int fcn::sdl2::TrueTypeFont::getHeight ( ) const
overridevirtual

Gets the height of the glyphs in the font.

Returns
The height of the glyphs int the font.

Implements fcn::Font.

Definition at line 45 of file truetypefont.cpp.

References mFont, and mRowSpacing.

◆ getRowSpacing()

int fcn::sdl2::TrueTypeFont::getRowSpacing ( )
virtual

Gets the spacing between rows in pixels.

Returns
the spacing.

Definition at line 118 of file truetypefont.cpp.

References mRowSpacing.

Referenced by drawString().

◆ getWidth()

int fcn::sdl2::TrueTypeFont::getWidth ( std::string const & text) const
overridevirtual

Gets the width of a string.

The width of a string is not necessarily the sum of all the widths of it's glyphs.

Parameters
textThe string to return the width of.
Returns
The width of a string.

Implements fcn::Font.

Definition at line 36 of file truetypefont.cpp.

References mFont.

◆ isAntiAlias()

bool fcn::sdl2::TrueTypeFont::isAntiAlias ( )
virtual

Checks if anti aliasing is used.

Returns
true if anti aliasing is used.

Definition at line 138 of file truetypefont.cpp.

References mAntiAlias.

◆ setAntiAlias()

void fcn::sdl2::TrueTypeFont::setAntiAlias ( bool antiAlias)
virtual

Enable or disable anti-aliasing for rendered glyphs.

Parameters
antiAliasTrue to enable anti-aliasing, false to disable.

Definition at line 133 of file truetypefont.cpp.

References mAntiAlias.

◆ setGlyphSpacing()

void fcn::sdl2::TrueTypeFont::setGlyphSpacing ( int spacing)
virtual

Sets the spacing between letters in pixels.

Default is 0 pixels. The spacing can be negative.

Parameters
spacingthe spacing in pixels.

Definition at line 123 of file truetypefont.cpp.

References mGlyphSpacing.

◆ setRowSpacing()

void fcn::sdl2::TrueTypeFont::setRowSpacing ( int spacing)
virtual

Sets the spacing between rows in pixels.

Default is 0 pixels. The spacing can be negative.

Parameters
spacingthe spacing in pixels.

Definition at line 113 of file truetypefont.cpp.

References mRowSpacing.

Member Data Documentation

◆ mAntiAlias

bool fcn::sdl2::TrueTypeFont::mAntiAlias
protected

Whether anti-aliasing is enabled for rendering.

Definition at line 116 of file truetypefont.hpp.

Referenced by drawString(), isAntiAlias(), setAntiAlias(), and TrueTypeFont().

◆ mFilename

std::string fcn::sdl2::TrueTypeFont::mFilename
protected

Filename of the font used to create mFont.

Definition at line 113 of file truetypefont.hpp.

Referenced by TrueTypeFont().

◆ mFont

TTF_Font* fcn::sdl2::TrueTypeFont::mFont
protected

Underlying TTF_Font pointer from SDL_ttf.

Definition at line 101 of file truetypefont.hpp.

Referenced by drawString(), getHeight(), getWidth(), and TrueTypeFont().

◆ mGlyphSpacing

int fcn::sdl2::TrueTypeFont::mGlyphSpacing
protected

Additional spacing between glyphs in pixels.

Definition at line 107 of file truetypefont.hpp.

Referenced by getGlyphSpacing(), setGlyphSpacing(), and TrueTypeFont().

◆ mHeight

int fcn::sdl2::TrueTypeFont::mHeight {}
protected

Cached font height in pixels.

Definition at line 104 of file truetypefont.hpp.

◆ mRowSpacing

int fcn::sdl2::TrueTypeFont::mRowSpacing
protected

Additional spacing between rows in pixels.

Definition at line 110 of file truetypefont.hpp.

Referenced by getHeight(), getRowSpacing(), setRowSpacing(), and TrueTypeFont().


The documentation for this class was generated from the following files: