TextRenderer

The font container

const char *filename,
int width = 9, int height = 12,
Rgba col = Rgba::BLACK, int italics = 0,
bool useHinting = true );

Construct the font by loading a True Type Font file.


const TextRenderer &otherRenderer,
int width = 9, int height = 12,
Rgba col = [inherit], int italics = [inherit] );

Construct the font by making an altered copy of an existing TextRenderer. If you don't pass anything as the color or the italics parameter they'll be inherited from otherRenderer.


GLYPH_FACE *face = 0,
int width = 9, int height = 12,
Rgba col = Rgba::BLACK, int italics = 0 );

Construct the font by using a Glyph Keeper font face.



The default constructor. Note that the TextRenderer will not be ready to use before you call the Load -method (IsValid() returns false).

The constructors do the the same as the equivalent Load -methods. The dimensions are in pixels and the italics angle is in degrees.

The alpha value of the color controls the opacity of the printed text. The higher the alpha value is, the more visible the text will be. For more information about alpha values see the definition of Bitmap.

If any of these functions fail to construct the font an error log will be added to the allegro.log file. In addition the IsValid() -method will return false if the TextRenderer is not ready to use. You can also test the validity of a TextRenderer like if the TextRenderer was a boolean value.

Global TextRenderers are now automated.

Examples

// Construct a new font by loading a true type font Arial.ttf in the fonts -folder //
// with the width of 10, the height of 15 and a black color //
TextRenderer myTextRenderer( "fonts/Arial.ttf"1015Rgba::BLACK );

// Construct a same looking font but with italics angle of 12 (the common italics angle) //
TextRenderer myItalicsRenderer( "fonts/Arial.ttf"1015Rgba::BLACK, 12 );

// Test if myItalicsRenderer was loaded correctly (maybe it didn't exist) //
if( !myItalicsRenderer ) {
  allegro_message( "Couldn't load fonts/Arial.ttf" );
}

// Construct a font which looks like myTextRenderer but with the opacity of only 30% //
TextRenderer myTranslucentRenderer( "fonts/Arial.ttf"1015Rgba0.00.00.00.30 ));

// Construct a smaller copy of an existing font (sized 9x12) //
// If you don't specify a color it'll be inherited //
// from the passed TextRenderer //
TextRenderer smallerTextRenderer( myTextRenderer, 912 );

// Construct the font from a glyph keeper font face //
// with a slightly yellow green color //
GLYPH_FACE *glyphKeeperFace = ...; 

TextRenderer otherTextRenderer( glyphKeeperFace, 2015Rgba0.31.00.0 ));


Member functions
Load
Load the font
Print
Prints the given text to the screen
SetColor
Sets the color of the font
GetColor
Returns the text color of the font
SetItalics
Sets the italics angle of the text
GetItalics
Returns the italics angle of the text
Width
Returns the width of the given text
Height
Returns the height of the given text
FirstLineWidth
Returns the width of the first text line of the given text
FirstLineHeight
Returns the height of the first text line of the given text
IsValid
Checks if the TextRenderer was loaded correctly

Advanced functions

GetFace
SendToGPU
UnloadFromGPU
UseAutoDelete


Questions about TextRenderer? Click here.