shithub: dpaint

ref: 363056d387d355804f182d3161c63aa3b56d313f
dir: /0paint.c/

View raw version
/*
 * written in plan 9 c dialect
 * thedaemon
*/
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>

void
main(void)
{
	Mouse m;
	Point prevm; /* previous mouse position */
	initdraw(0, 0, "0 Paint");
	eresized(0);
	einit(Emouse);
	int brush = 1;
	int eraser = 4;

	for(;;){
		m = emouse();

		if(m.buttons & 2)
			break;
		if(m.buttons & 4) { 
			line(screen,
			     prevm.x == -1 ? m.xy : prevm,
			     m.xy, Enddisc, Enddisc, eraser, display->white, ZP);
			prevm = m.xy;
		} 
		if(m.buttons & 1) { /* Paint Function  ? : is if else true and false*/
			line(screen,
			     prevm.x == -1 ? m.xy : prevm,
			     m.xy, Enddisc, Enddisc, brush, display->black, ZP); /* ZP is a constant point (0,0) */
			prevm = m.xy;
		} else {
			prevm = Pt(-1, -1);
		}
	}
}

void
eresized(int new)
{
	USED(new);
	if(getwindow(display, Refnone) < 0)
		sysfatal("resize failed: %r");
}