Subsections

Formatted text input/output

Defined in textio.h and textio.c

The text input-output functions all take the smallest possible number of parameters to put something on the screen: two coordinates, and a format string.

The vertical coordinates are interpreted differently by the two coordinate systems. With Cartesian coordinates, the text is vertically centered around the y coordinate. With standard coordinates, the y coordinate corresponds to the top of the text (like in other libraries).

The format string is the same as the standard C printf and scanf function families. It does not recognize the \t and \n escape characters, however. These are rendered as a a caret (^).

Drawing parameters are set with the graphics parameter functions.

int ts_printf(int x, int y, const char *txt, ...)

Writes text in *txt to position x, y of the current destination bitmap. The color of the text is defined with ts_fgcolor. The string to be printed can be specified using a printf() like format string. The maximum length of the string is set to 512 characters.

Returns the length of the output string in pixels.

int ts_printf_centre(int x, int y, const char *txt, ...)

Like ts_printf, but centered around x, y.

Returns the length of the output string in pixels.

int ts_printf_right(int x, int y, const char *txt, ...)

Like ts_printf, but aligned to the right of x, y.

Returns the length of the output string in pixels.

int ts_printf_justify(int x1, int x2, int y, const char *txt, ...)

Like ts_printf, but the text is justified between x1 and x2.

Returns the length of the output string in pixels.

int ts_textheight ()

Returns the height of the font in pixels.

int ts_textlength (char *txt)

Returns the length of string *txt in pixels.

int ts_scanf (int x, int y, char *format, ...);

Reads input from the keyboard with formatted input like scanf(). The input appears on the screen starting at position (x, y).

By default, the standard US keyboard layout (qwerty) is used. If you want to use another keyboard layout, you will have to reconfigure Allegro on a per-computer basis. The Tscope FAQ explains you how.

Returns the number of variables that have been read successfully, or EOF (-1) if no input has been read at all. If reading fails, the content of the supplied variables is not altered. Therefore it is advisable to initialize any variables supplied to ts_scanf before calling the function, and/or to check the return value of ts_scanf after the call.


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information