Gosu::Font Class Reference

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

List of all members.

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.
std::wstring name () const
 Returns the name of the font that was used to create it.
unsigned height () const
 Returns the height of the font, in pixels.
unsigned flags () const
 Returns the flags used to create the font characters.
double textWidth (const std::wstring &text, double factorX=1) const
 Returns the width, in pixels, the given text would occupy if drawn.
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).
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).
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.


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:
fontName Name of a system font, or a filename to a TTF file (must contain '/', does not work on Linux).
fontHeight Height of the font, in pixels.
fontFlags Flags 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:
text Formatted 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:
relX Determines 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.
relY See 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.

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: