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 |
e2d::graphics::TTF::TTF | ( | unsigned int | buffer_size | ) |
Here you say what size you want the string buffer to be.
buffer_size | The size in bytes allocated for the message that will be written by this font. |
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.
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.
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().
message | The message you want to write with this font. |
void e2d::graphics::TTF::SetTextColor | ( | Color | color | ) |
Choose a color for your message.
color | Text color. |
void e2d::graphics::TTF::SetBackgroundColor | ( | Color | color | ) |
Sets the color of the shade in shaded mode.
color | Background color. |
void e2d::graphics::TTF::SetPrintMode | ( | int | mode | ) |
Sets the print mode.
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.
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.
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.