! A very simple drawing program for Plan9, BSD/X11, and DOS/VGA.
! Compile with `tx -O -P draw.t'

#include "C:/v/t3xr5//graphics.inc"

info(fs) do
	g_clear(GCLEAR);
	g_puts(-27*fs[0], YLIM-fs[1], 1, GSET,
	packed "Left button = draw, Middle button = clear, ESC = exit");
end

do
	var	e[event], fs[2];
	var	x, y, lastx, lasty;
	var	draw, att;

	g_init();
	g_fontsize(1, fs);
	e[e_key] := 0;
	draw := 0;
	info(fs);
	while (e[e_key] \= 27) do
		if (g_reshaped()) info(fs);
		att := g_event(e, 0);
		x := e[e_x];
		y := e[e_y];
		if (att) do
			ie (e[e_buttons] & 1) do
				draw := 1;
			end
			else do
				if (e[e_buttons] & 2) info(fs);
				draw := 0;
			end
		end
		if (draw) g_line(lastx, lasty, x, y, GSET);
		lastx := x;
		lasty := y;
	end
	g_end();
end
