Propane::Font Class Reference

A class for rendering AngelCode bitmap fonts. More...

#include <PropaneFont.h>

List of all members.

Public Member Functions

 Font (const std::string &familyName)
 Constructor based on the shared family: "data/sharedfont" will load "data/sharedfont.png" and "data/sharedfont.fnt" with alpha keying on black (BMFont default).
 ~Font ()
 Destructor.
void print (int x, int y, const std::string &text)
 Standard print routine. Newlines are supported.
void rightAlignPrint (int x, int y, const std::string &text)
 Printing right-aligned. Newlines are supported.
void centrePrint (int screen_width, int y, const std::string &text)
 Printing centre-aligned. Newlines are supported.
void wordWrapPrint (int x, int y, int wrapPoint, const std::string &text)
 Word wrapped printing. "wrapPoint" is the x-coordinate (in pixels) where we should wrap along.
void mathPrint (int x, int y, float offset, float step, float amplitude, float(*function)(float), const std::string &text)
 Print using a mathematical function to order the y offset. Useful for cracktros (TODO).
unsigned int getLineHeight ()
 Get the height in pixels of a single line of text from this font.
unsigned int getWidthForString (const std::string &text)
 Get the width in pixels of a single line of text from this font, cutting out colour codes and ignoring newlines.
void setFontColour (float r, float g, float b, float a=1.0f)
 Sets the font colour.
bool ready ()
 Tells the end-user if the font successfully completed construction.


Detailed Description

A class for rendering AngelCode bitmap fonts.
Examples:

usingAFont.cpp.


Member Function Documentation

void Font::centrePrint int  screen_width,
int  y,
const std::string &  text
 

Printing centre-aligned. Newlines are supported.

Print text evenly centred around the middle of the screen

Does not handle newline correctly, but will involve colour codes in the calculation (uses getWidthForString).

Parameters:
screen_width The width of the screen, in pixels
y The y-coordinate to print the text at, in pixels
text The text string to print.

unsigned int Font::getLineHeight  ) 
 

Get the height in pixels of a single line of text from this font.

Returns the height, in pixels, of a single line of text using the current font.

Returns:
The height, in pixels, of a line of text.
Examples:
usingAFont.cpp.

unsigned int Font::getWidthForString const std::string &  str  ) 
 

Get the width in pixels of a single line of text from this font, cutting out colour codes and ignoring newlines.

Returns the width, in pixels, of a string when printed out. Does not take newlines into effect.

Parameters:
str The text string to check the width of
Returns:
The pixel width of the string

void Font::print int  x,
int  y,
const std::string &  text
 

Standard print routine. Newlines are supported.

Print a string to the screen, using this font. Cornerstone method of the entire Propane::Font class; most methods that print will call this.

It will emit an error on stderr and then abort if the font has not been correctly loaded.

Parameters:
x the X location to draw this string at, in pixels
y the Y location to draw this string at, in pixels
text The text string to draw to the screen.
Examples:
usingAFont.cpp.

void Font::rightAlignPrint int  x,
int  y,
const std::string &  text
 

Printing right-aligned. Newlines are supported.

Print text so it is to the left of X. Does not handle newline properly. Uses getWidthForString.

Parameters:
x The x-coordinate to right print around. All text printed will appear to the left of this coordinate. In pixels.
y The y-coordinate to print at, in pixels.
text The text string to print.

void Font::setFontColour float  newR,
float  newG,
float  newB,
float  newA = 1.0f
 

Sets the font colour.

Sets the default font colour used for rendering.

After using this function, all calls to print will print in that colour.

Parameters:
newR the red component of the colour, from 0 to 1.0 inclusive
newG the green component of the colour, from 0 to 1.0 inclusive
newB the blue component of the colour, from 0 to 1.0 inclusive
newA the alpha component of the colour. from 0 (invisible) to 1.0 (opaque) inclusive
Quickly resets the default font colour used for rendering.
Examples:
usingAFont.cpp.

void Font::wordWrapPrint int  x,
int  y,
int  wrapPoint,
const std::string &  text
 

Word wrapped printing. "wrapPoint" is the x-coordinate (in pixels) where we should wrap along.

Prints a certain string at a certain location, left aligned. Will break every 'wrapPoint' pixels to a new line. Not guaranteed to handle inline colour state correctly across linebreaks.

Will strip out multiple spaces, so "hello world" will appear as "hello world"

Parameters:
x The x-coordinate to print at, in pixels
y The y-coordinate to print at, in pixels
wrapPoint The x-coordinate to force a line break at, in pixels. This must be greater than x, or an error will be thrown to stderr and the function will abort. When printing reaches this x-coordinate, a line break will be enforced.
text The text string to print


The documentation for this class was generated from the following files:
Generated on Sun Jan 14 16:49:12 2007 for Propane Injector by  doxygen 1.4.6