e2d::graphics::TTF Class Reference

Inheritance diagram for e2d::graphics::TTF:

e2d::core::Rect

List of all members.


Detailed Description

Attention:
Development of this class has been discontinued: its recommended to use bitmap fonts instead of true type fonts, see Font.
This class is a wrapper around the SDL_ttf system. It is capable of transforming a string of text into an image, so you can blit it wherever you like. It can load a True Type font (*.ttf or *.fon), so you can use this font to write anything you want to the screen (or any other drawing surface).

In order to enable use of this class, you must compile Easy2D with support to SDL_ttf (check the Makefile for details), as well as link SDL_ttf library with your project. Also, you will need to manually include this class' header, like this:

  #include <ttf.hpp>

The bitmap with the text is only built when you call the Print() method after any change to the message or the way it is going to appear on-screen (color, style, etc...).

It's imperative that you set a message to be written with this font before calling the Print() method. SDL_ttf won't print empty messages. Also, if you need to change the size of the font, unfortunatelly you will have to instantiate another TTF object; this is a limitation of SDL_ttf.

Public Member Functions

 TTF (unsigned int buffer_size)
 Constructor.
void Load (const char *filename, int ptsize)
 Loads a font.
void SetMessage (char *message,...)
 Sets the message to be written, printf style.
void SetTextColor (Color color)
 Sets the font color.
void SetBackgroundColor (Color color)
 Sets the background color (for shaded mode).
void SetPrintMode (int mode)
 Sets the print mode (Solid, Shaded or Blended).
void SetStyle (int style)
 Sets font style (Normal, Italic, Bold, Underline);.
void Blit (SDL_Surface *destination)
 Blits the message to the destination.
void BuildSurface ()
 Builds the surface with the rendered text.

Static Public Member Functions

static void Init ()
 Initializes SDL_ttf.
static void Quit ()
 Quits SDL_ttf.

Static Public Attributes

static const int PRINT_MODE_SOLID = 0
 renders a solid message
static const int PRINT_MODE_SHADED = 1
 renders a shaded message
static const int PRINT_MODE_BLENDED = 2
 renders an alpha-blended message
static const int STYLE_NORMAL = TTF_STYLE_NORMAL
 renders a normal message
static const int STYLE_BOLD = TTF_STYLE_BOLD
 renders a bold message
static const int STYLE_ITALIC = TTF_STYLE_ITALIC
 renders an italic message
static const int STYLE_UNDERLINE = TTF_STYLE_UNDERLINE
 renders an underlined message


Constructor & Destructor Documentation

e2d::graphics::TTF::TTF ( unsigned int  buffer_size  ) 

Here you say what size you want the string buffer to be.

Parameters:
buffer_size The size in bytes allocated for the message that will be written by this font.


Member Function Documentation

void e2d::graphics::TTF::Init (  )  [static]

Performs initialization of SDL_ttf. You cannot use any method of this class before a call to this method. Remeber to call Quit() after you finish using SDL_ttf.

Exceptions:
e2d::core::Exception if any error occurs during SDL_ttf initialization.

void e2d::graphics::TTF::Quit ( void   )  [static]

Call this method to quit the SDL_ttf system.

void e2d::graphics::TTF::Load ( const char *  filename,
int  ptsize 
)

Loads a font from a *.ttf or a *.fon file.

Parameters:
filename Path to the font file.
ptsize Height, in pixels, of each character.

void e2d::graphics::TTF::SetMessage ( char *  message,
  ... 
)

Here you set the message you want written somewhere. You can use this method just the same way you would use printf().

Parameters:
message The message you want to write with this font.

void e2d::graphics::TTF::SetTextColor ( Color  color  ) 

Choose a color for your message.

Parameters:
color Text color.

void e2d::graphics::TTF::SetBackgroundColor ( Color  color  ) 

Sets the color of the shade in shaded mode.

Parameters:
color Background color.

void e2d::graphics::TTF::SetPrintMode ( int  mode  ) 

Sets the print mode.

Parameters:
mode The print mode, can be one of TTF::PRINT_MODE_SOLID, TTF::PRINT_MODE_SHADED or TTF::PRINT_MODE_BLENDED

void e2d::graphics::TTF::SetStyle ( int  style  ) 

Sets font style.

Parameters:
style The font style, can be one of TTF::STYLE_NORMAL, TTF::STYLE_BOLD, TTF::STYLE_ITALIC or TTF::STYLE_UNDERLINE.

void e2d::graphics::TTF::Blit ( SDL_Surface *  destination  ) 

Blits the rendered message to the destination. The resulting image will be blitted having its upper-left corner at position X, Y of the destination, where X and Y are this font's X and Y attributes inherited from Rect.

Parameters:
destination Pointer to an SDL_Surface where the text will be blitted (may be the Video::framebuffer).

void e2d::graphics::TTF::BuildSurface (  ) 

Renders the image containing the text. This method is called automatically before blitting, if required.


Generated on Tue Dec 8 10:32:45 2009 for Easy2D by  doxygen 1.5.6