Text output



Allegro provides text output routines that work with both proportional (individual characters can be any size) and fixed size 8x8 or 8x16 fonts. A font contains the ASCII characters 32 to 255: all other characters will be drawn as spaces. The grabber program can create fonts from sets of characters drawn on a PCX file (see grabber.txt for more information), and can also import GRX or BIOS format font files.

extern FONT *font;
A simple 8x8 fixed size font (the mode 13h BIOS default). If you want to alter the font used by the GUI routines, change this to point to one of your own fonts.

void text_mode(int mode);
Sets the mode in which text will be drawn. If mode is zero or positive, text output will be opaque and the background of the characters will be set to color #mode. If mode is negative, text will be drawn transparently (ie. the background of the characters will not be altered). The default is a mode of zero.

void textout(BITMAP *bmp, FONT *f, unsigned char *s, int x, y, int color);
Writes the string s onto the bitmap at position x, y, using the current text mode and the specified font and foreground color. If the color is -1 and a proportional font is in use, it will be drawn using the colors from the original font bitmap (the one you imported into the grabber program), which allows multicolored text output.

void textout_centre(BITMAP *bmp, FONT *f, unsigned char *s, int x, y, color);
Like textout(), but interprets the x coordinate as the centre rather than the left edge of the string.

void textout_justify(BITMAP *bmp, FONT *f, unsigned char *s, int x1, int x2, int y, int diff, int color);
Draws justified text within the region x1-x2. If the amount of spare space is greater than the diff value, it will give up and draw regular left justified text instead.

void textprintf(BITMAP *bmp, FONT *f, int x, y, color, char *fmt, ...);
Formatted text output, using a printf() style format string.

void textprintf_centre(BITMAP *bmp, FONT *f, int x, y, color, char *fmt, ...);
Like textprintf(), but interprets the x coordinate as the centre rather than the left edge of the string.

int text_length(FONT *f, unsigned char *str);
Returns the length (in pixels) of a string in the specified font.

int text_height(FONT *f)
Returns the height (in pixels) of the specified font.

void destroy_font(FONT *f);
Frees the memory being used by a font structure.




Back to Contents