shithub: dpaint

ref: 289d92186e8b0ee450a22c07f1c8642645e6d732
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>
#include <keyboard.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  ? : means this 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");
}