Tscope5
textio.c File Reference

Definitions of text input/output functions. More...

Go to the source code of this file.

Functions

Text input/output functions

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.

  • When using the Cartesian coordinate system, text is vertically centered around the y coordinate.
  • When using the Display coordinate system, 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.

Both standard C strings and Unicode strings can be used.

Drawing parameters are set with the graphics parameter functions.

double ts5_printf (double x, double y, const char *format,...)
 Write text to the active bitmap. More...
 
void ts5_printf_justify (double x1, double x2, double y, double diff, const char *format,...)
 Write justified text to the active bitmap. More...
 
double ts5_printf_ustr (double x, double y, const TS5_USTR *ustr)
 Write UTF-8 encoded text to the active bitmap. More...
 
void ts5_printf_justify_ustr (double x1, double x2, double y, double diff, const TS5_USTR *ustr)
 Write justified UTF-8 encoded text to the active bitmap. More...
 
int ts5_scanf (double x, double y, const char *format,...)
 Read text from the keyboard. More...
 
double ts5_get_text_width (const char *format,...)
 Get the width of a string without printing it. More...
 
double ts5_get_text_width_ustr (TS5_USTR *ustr)
 Get the width of a UTF-8 string without printing it. More...
 
Loading custom fonts

In Tscope5 three fonts are available as standard (courier, arial and times).

If these do not suit your needs any TrueType font that is installed on your computer can be loaded manually.

TS5_FONT * ts5_read_font (const char *fontfile, double size)
 Load a user defined font. More...
 
TS5_FONT * ts5_set_font (TS5_FONT *font)
 Set a user defined font. More...
 
void ts5_free_font (TS5_FONT *font)
 Free the memory used by a user defined font. More...
 

Detailed Description

Definitions of text input/output functions.

Definition in file textio.c.

Function Documentation

double ts5_printf ( double  x,
double  y,
const char *  format,
  ... 
)

Write text to the active bitmap.

Parameters
xHorizontal position of the text.
yVertical position of the text.
formatPrintf style format string.
Returns
Length of the string on the display (in pixels).
Examples:
audio03.c, audio04.c, cedrusbox01.c, display01.c, display01.cpp, display02.c, display03.c, display04.c, display05.c, display06.c, graphics01.c, graphics02.c, graphics03.c, graphics04.c, graphics10.c, joystick01.c, keyboard01.c, mouse01.c, mouse02.c, parport01.c, randomizer01.c, randomizer02.c, randomizer03.c, serialport01.c, textio01.c, textio02.c, textio03.c, textio04.c, textio05.c, timer01.c, timer02.c, timer03.c, timer04.c, timer05.c, and timer06.c.

Definition at line 66 of file textio.c.

void ts5_printf_justify ( double  x1,
double  x2,
double  y,
double  diff,
const char *  format,
  ... 
)

Write justified text to the active bitmap.

Parameters
x1Horizontal start position of the text.
x2Horizontal end position of the text.
yVertical position of the text.
diffMaximum amount of space. If the amount of space in a line of text is greater than the diff value, left justified text will be written.
formatPrintf style format string.
Examples:
textio01.c.

Definition at line 130 of file textio.c.

double ts5_printf_ustr ( double  x,
double  y,
const TS5_USTR *  ustr 
)

Write UTF-8 encoded text to the active bitmap.

Parameters
xHorizontal position of the text.
yVertical position of the text.
ustrUnicode string.
Returns
Length of the string on the display (in pixels).

Definition at line 189 of file textio.c.

void ts5_printf_justify_ustr ( double  x1,
double  x2,
double  y,
double  diff,
const TS5_USTR *  ustr 
)

Write justified UTF-8 encoded text to the active bitmap.

Parameters
x1Horizontal start position of the text.
x2Horizontal end position of the text.
yVertical position of the text.
diffMaximum amount of space. If the amount of space in a line of text is greater than the diff value, left justified text will be written.
ustrUnicode string.

Definition at line 246 of file textio.c.

int ts5_scanf ( double  x,
double  y,
const char *  format,
  ... 
)

Read text from the keyboard.

Parameters
xHorizontal position where the input will be echoed.
yVertical position where the input will be echoed.
formatPrintf style format string.
Returns
The number of arguments that were processed.
Examples:
textio04.c.

Definition at line 297 of file textio.c.

double ts5_get_text_width ( const char *  format,
  ... 
)

Get the width of a string without printing it.

Parameters
formatPrintf style format string.
Returns
The width of the string on the display (in pixels).
Examples:
textio03.c.

Definition at line 375 of file textio.c.

double ts5_get_text_width_ustr ( TS5_USTR *  ustr)

Get the width of a UTF-8 string without printing it.

Parameters
ustrUnicode string.
Returns
The width of the string on the display (in pixels).

Definition at line 408 of file textio.c.

TS5_FONT* ts5_read_font ( const char *  fontfile,
double  size 
)

Load a user defined font.

Parameters
fontfilePath to the file that describes the 1 type font.
sizeSize the font will be rendered in.
Returns
A pointer to the TS5_FONT font structure.

True type fonts can be found in /Library/fonts on Mac OS X.

Examples:
textio05.c.

Definition at line 449 of file textio.c.

TS5_FONT* ts5_set_font ( TS5_FONT *  font)

Set a user defined font.

Parameters
fontThe new font.
Returns
A pointer to the previous font.
Examples:
textio05.c.

Definition at line 479 of file textio.c.

void ts5_free_font ( TS5_FONT *  font)

Free the memory used by a user defined font.

Parameters
fontpointer to the font that will be freed.

This function should be called at the end of the program for each font read by the user.

Examples:
textio05.c.

Definition at line 507 of file textio.c.