Tscope5
textio.c File Reference

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, the 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,...)
void ts5_printf_justify (double x1, double x2, double y, const double diff, const char *format,...)
double ts5_printf_ustr (double x, double y, const TS5_USTR *ustr)
void ts5_printf_justify_ustr (double x1, double x2, double y, const double diff, const TS5_USTR *ustr)
int ts5_scanf (double x, double y, const char *format,...)
double ts5_get_text_width (const char *format,...)
double ts5_get_text_width_ustr (TS5_USTR *ustr)
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)
TS5_FONT * ts5_set_font (TS5_FONT *font)
void ts5_free_font (TS5_FONT *font)

Detailed Description

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:
display1.c, display2.c, display3.c, display4.c, display5.c, graphics1.c, graphics10.c, graphics2.c, graphics3.c, graphics4.c, randomizer1.c, randomizer2.c, randomizer3.c, textio1.c, textio2.c, textio3.c, textio4.c, textio5.c, timer1.c, timer2.c, timer3.c, timer4.c, timer5.c, and timer6.c.

Definition at line 52 of file textio.c.

void ts5_printf_justify ( double  x1,
double  x2,
double  y,
const 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 spare space is greater than the diff value, left justified text will be written.
formatPrintf style format string.
Examples:
textio1.c.

Definition at line 99 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 138 of file textio.c.

void ts5_printf_justify_ustr ( double  x1,
double  x2,
double  y,
const 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 spare space is greater than the diff value, left justified text will be written.
ustrUnicode string.

Definition at line 176 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:
textio4.c.

Definition at line 207 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).

Definition at line 285 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 317 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 true 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.

Examples:
textio5.c.

Definition at line 356 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:
textio5.c.

Definition at line 381 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:
textio5.c.

Definition at line 408 of file textio.c.