Google

Tutorial: Extras

There are some handy helper functions which come with Terminality. They are platform-independent and use the Terminality functions to get their work done.

Box drawing

It's fun, it's useful, and it's boring to have to re-implement every time you need it.

The Terminality extras can draw plain boxes, as well as fake 3D ones, for you using some very simple function calls. The drawbox(...) function takes 4 parameters - the (x,y) coordinate pairs of the upper-left and lower-right corners of the box. The drawbox_in and drawbox_out macros simplify using the box_3d(...) function to draw fake 3D boxes. On top of the two corner coordinates, these macros require a color to be given for shading purposes.


#include <tn.h>
#include <extra.h>

int main()
{
	initcons();

	clrscr();
	textcolor(Red);
	drawbox(1,1,10,5);
	drawbox_in(20,1,30,5,Green);
	drawbox_out(40,1,50,5,Blue);

	update();

	donecons();
	return 0;
}
extra1.c
Screenshot

Text functions

writexy(...) is a neat convenience function which can be used to write arbitrary text at a given screen coordinate. Basically, it saves you an extra gotoxy(...) call. If you want to simply center a piece of text, you can use the center(...) function instead. center(...) can take special coloured escaped just like printc(...). Keep this in mind as you read on about printc(...).

printc(...) (print with colour) will print a formatted string with embedded colour codes. This is a more obscure function which can be used to avoid having to break up a printw(...) with repeated calls to change the text colour.


#include <tn.h>
#include <extra.h>

int main()
{
	initcons();

	clrscr();
	center(1,"Headlines");
	writexy(10,3, "We're not the owners of the sun and the earth");
	writexy(10,4, "It's like a roundabout");
	writexy(10,5, "And it goes 'round and 'round for ");

#define ESC "\x01B"
	printc(ESC "f4f" ESC "fCr" ESC "fEe" ESC "fFe");

	update();

	donecons();
	return 0;
}
extra2.c
Screenshot

The junk fed to printc(...) may look convoluted but the control sequences are pretty simple:

  • An escape followed by an 'f' denotes a change in foreground colour.
  • An escape followed by an 'b' denotes a change in background colour.

Each sequence consists of three characters: the escape, the colour component designation and, finally, the hexadecimal digit representing the desired colour.

ESC[fb][0123456789ABCDEF]
[contents]
$Id: tutor-extra.html,v 1.3 2002/07/26 01:49:15 darkmoon Exp $