#include <sys/types.h>
#include <malloc.h>
#include <string.h>
#include <sys/time.h>
#include <sys/fcntl.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>

#include "xstuff.h"

int main(int argc, char *argv[])
{
    int i, n = (argc >= 2 ? atoi(argv[1]):2000);

    puts("Press 'q' in the X-window to quit, or press ^C in this window.");

    /* This function must be called to initialize the X stuff.
    ** It will exit if there is an error.
    */
    start_x(argc, argv, "simple drawing program");

    while(1)
    {
	static unsigned old_x, old_y;
	unsigned x,y, mouse_button[3];

	/* This function must be called frequently to handle the X
	** events for you.
	*/
	update_x();

	mouse_info(&x, &y, mouse_button);

	if(mouse_button[0])
	    drawline(old_x, old_y, x, y);

	if(mouse_button[2])
	{
	    clearline(old_x, old_y, x, y);
	    clearline(old_x-1, old_y, x-1, y);
	    clearline(old_x+1, old_y, x+1, y);
	    clearline(old_x, old_y-1, x, y-1);
	    clearline(old_x, old_y+1, x, y+1);
	}

	old_x = x;
	old_y = y;
    }
}
