Main Page | Modules | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages

Font Class Reference

#include <font.h>

List of all members.


Detailed Description

This class loads and renders ttf fonts.

This class should be instantiated once for each font or font size to be used. Each font and size is cached for quick rendering at runtime. Fonts can be any color, size, or style. The .ttf file must be available for rendering to occur.

Definition at line 31 of file font.h.

Public Member Functions

 Font ()
 Constructor.
 ~Font ()
 Deconstructor.
int init ()
 Initializes the font based on given parameters.
int init (char *file, int size, int r, int g, int b, int style)
 Specify font file and size at init.
int render (SDL_Surface *surface, char *text, int x, int y)
 Renders the text on screen.

Public Attributes

char * file
int size
int r
int g
int b
int style


Constructor & Destructor Documentation

Font::Font  ) 
 

Constructor.

Initializes the font and creates a buffer for glyph storage.

Definition at line 3 of file font.cpp.

Font::~Font  ) 
 

Deconstructor.

Ensures that the font memory is freed and that SDL is shut down.

Definition at line 15 of file font.cpp.


Member Function Documentation

int Font::init char *  file,
int  size,
int  r,
int  g,
int  b,
int  style
 

Specify font file and size at init.

Parameters:
font - Location of font file.
size - Font size.
r - Red value of text color.
g - Green value of text color.
b - Blue value of text color.
style - Font style (See libsdl_ttf documentation).
Returns:
int - 0 if successful, -1 if error.

Definition at line 30 of file font.cpp.

int Font::init  ) 
 

Initializes the font based on given parameters.

This method starts up SDL_TTF, fills the glyph caches with characters from the loaded font file, and prepares to render them on screen.

Returns:
int - 0 if successful, -1 if error.

Definition at line 25 of file font.cpp.

int Font::render SDL_Surface *  surface,
char *  text,
int  x,
int  y
 

Renders the text on screen.

This method renders the given text string into a specified SDL surface. The color can be specified as well as the x and y coordinates within the surface.

Parameters:
surface - Rendering target surface.
text - Text string to render.
x - Staring X coordinate in surface.
y - Staring Y coordinate in surface.
Returns:
int - 0 if successful, -1 if error.

Definition at line 83 of file font.cpp.

References Metrics::advance, Metrics::maxY, and Metrics::minX.


The documentation for this class was generated from the following files:
Generated on Wed Aug 31 15:16:39 2005 for Chair by  doxygen 1.4.2