FifeGUI 0.3.0
A C++ GUI library designed for games.
fcn::DefaultFont Class Reference

#include <defaultfont.hpp>

Inheritance diagram for fcn::DefaultFont:
fcn::Font

Public Member Functions

virtual int drawGlyph (Graphics *graphics, unsigned char glyph, int x, int y)
void drawString (Graphics *graphics, std::string const &text, int x, int y) override
int getHeight () const override
int getStringIndexAt (std::string const &text, int x) const override
int getWidth (std::string const &text) const override
Public Member Functions inherited from fcn::Font
 Font (Font &&)=default
 Font (Font const &)=default
Fontoperator= (Font &&)=default
Fontoperator= (Font const &)=default
virtual ~Font ()=default

Detailed Description

A basic font implementation capable only of drawing rectangles (placeholder).

This font is used as a default font when no other font is specified.

Definition at line 23 of file defaultfont.hpp.

Member Function Documentation

◆ drawGlyph()

int fcn::DefaultFont::drawGlyph ( Graphics * graphics,
unsigned char glyph,
int x,
int y )
virtual

Draws a glyph as a rectangle.

The glyphs will always be drawn as rectangles no matter the glyph.

Note
You normally won't use this function to draw text since the Graphics class contains better functions for drawing text.
Parameters
graphicsA Graphics object to be used for drawing.
glyphThe glyph to draw.
xThe x coordinate where to draw the glyph.
yThe y coordinate where to draw the glyph.
Returns
The width of the drawn glyph in pixels.

Definition at line 26 of file defaultfont.cpp.

References fcn::Graphics::drawRectangle().

Referenced by drawString().

◆ drawString()

void fcn::DefaultFont::drawString ( 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
graphicsA 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 35 of file defaultfont.cpp.

References drawGlyph(), and getWidth().

◆ getHeight()

int fcn::DefaultFont::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 16 of file defaultfont.cpp.

◆ getStringIndexAt()

int fcn::DefaultFont::getStringIndexAt ( std::string const & text,
int x ) const
overridevirtual

Gets a string index in a string providing an x coordinate.

Used to retrieve a string index (for a character in a string) at a certain x position. It is especially useful when a mouse clicks in a TextField and you want to know which character was clicked.

Returns
A string index in a string providing an x coordinate.

Reimplemented from fcn::Font.

Definition at line 44 of file defaultfont.cpp.

References getWidth().

◆ getWidth()

int fcn::DefaultFont::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 its glyphs.

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

Implements fcn::Font.

Definition at line 21 of file defaultfont.cpp.

Referenced by drawString(), and getStringIndexAt().


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