Gosu::Font Class Reference

A font can be used to draw text on a Graphics object very flexibly. More...

Public Member Functions

 Font (Graphics &graphics, const std::wstring &fontName, unsigned fontHeight, unsigned fontFlags=ffBold)
 Constructs a font that can be drawn onto the graphics object. More...
 
std::wstring name () const
 Returns the name of the font that was used to create it. More...
 
unsigned height () const
 Returns the height of the font, in pixels. More...
 
unsigned flags () const
 Returns the flags used to create the font characters. More...
 
double textWidth (const std::wstring &text, double factorX=1) const
 Returns the width, in pixels, the given text would occupy if drawn. More...
 
void draw (const std::wstring &text, double x, double y, ZPos z, double factorX=1, double factorY=1, Color c=Color::WHITE, AlphaMode mode=amDefault) const
 Draws text so the top left corner of the text is at (x; y). More...
 
void drawRel (const std::wstring &text, double x, double y, ZPos z, double relX, double relY, double factorX=1, double factorY=1, Color c=Color::WHITE, AlphaMode mode=amDefault) const
 Draws text at a position relative to (x; y). More...
 
void setImage (wchar_t wc, unsigned fontFlags, const Gosu::Image &image)
 Maps a letter to a specific image instead of generating one using Gosu's built-in text rendering. More...
 
void setImage (wchar_t wc, const Gosu::Image &image)
 A shortcut for mapping a character to an image regardless of fontFlags. More...
 
GOSU_DEPRECATED void drawRot (const std::wstring &text, double x, double y, ZPos z, double angle, double factorX=1, double factorY=1, Color c=Color::WHITE, AlphaMode mode=amDefault) const
 DEPRECATED: Analogous to draw, but rotates the text by a given angle. More...
 

Detailed Description

A font can be used to draw text on a Graphics object very flexibly.

Fonts are ideal for small texts that change regularly. For large, static texts you should use createBitmap and turn the result into an image.

Definition at line 20 of file Font.hpp.

Constructor & Destructor Documentation

Gosu::Font::Font ( Graphics graphics,
const std::wstring &  fontName,
unsigned  fontHeight,
unsigned  fontFlags = ffBold 
)

Constructs a font that can be drawn onto the graphics object.

Parameters
fontNameName of a system font, or a filename to a TTF file (must contain '/', does not work on Linux).
fontHeightHeight of the font, in pixels.
fontFlagsFlags used to render individual characters of the font.

Member Function Documentation

void Gosu::Font::draw ( const std::wstring &  text,
double  x,
double  y,
ZPos  z,
double  factorX = 1,
double  factorY = 1,
Color  c = Color::WHITE,
AlphaMode  mode = amDefault 
) const

Draws text so the top left corner of the text is at (x; y).

Parameters
textFormatted text without line-breaks.
void Gosu::Font::drawRel ( const std::wstring &  text,
double  x,
double  y,
ZPos  z,
double  relX,
double  relY,
double  factorX = 1,
double  factorY = 1,
Color  c = Color::WHITE,
AlphaMode  mode = amDefault 
) const

Draws text at a position relative to (x; y).

Parameters
relXDetermines where the text is drawn horizontally. If relX is 0.0, the text will be to the right of x, if it is 1.0, the text will be to the left of x, if it is 0.5, it will be centered on x. Of course, all real numbers are possible values.
relYSee relX.
GOSU_DEPRECATED void Gosu::Font::drawRot ( const std::wstring &  text,
double  x,
double  y,
ZPos  z,
double  angle,
double  factorX = 1,
double  factorY = 1,
Color  c = Color::WHITE,
AlphaMode  mode = amDefault 
) const

DEPRECATED: Analogous to draw, but rotates the text by a given angle.

Use a simple pushTransform to achieve the same effect.

unsigned Gosu::Font::flags ( ) const

Returns the flags used to create the font characters.

unsigned Gosu::Font::height ( ) const

Returns the height of the font, in pixels.

std::wstring Gosu::Font::name ( ) const

Returns the name of the font that was used to create it.

void Gosu::Font::setImage ( wchar_t  wc,
unsigned  fontFlags,
const Gosu::Image image 
)

Maps a letter to a specific image instead of generating one using Gosu's built-in text rendering.

This can only be called once per character, and the character must not have been drawn before. This ensures that Fonts are still sort of immutable.

void Gosu::Font::setImage ( wchar_t  wc,
const Gosu::Image image 
)

A shortcut for mapping a character to an image regardless of fontFlags.

Later versions might apply faux italics or faux bold to it (to be decided!).

double Gosu::Font::textWidth ( const std::wstring &  text,
double  factorX = 1 
) const

Returns the width, in pixels, the given text would occupy if drawn.


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