Plan 9 from Bell Labs’s /usr/web/sources/contrib/aiju/paint.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>

void
main()
{
	Event e;
	Point last;
	int haslast;
	
	haslast = 0;
	initdraw(0, 0, 0);
	einit(Emouse | Ekeyboard);
	draw(screen, screen->r, display->white, 0, ZP);
	flushimage(display, 1);
	while(1) {
		switch(event(&e)) {
		case Emouse:
			if(e.mouse.buttons & 1) {
				if(haslast)
					
					line(screen, last, e.mouse.xy, Enddisc, Enddisc, 5, display->black, ZP);
				else
					fillellipse(screen, e.mouse.xy, 5, 5, display->black, ZP);
				
				last = e.mouse.xy;
				haslast = 1;
				flushimage(display, 1);
			} else haslast = 0;
			if(e.mouse.buttons & 4) {
				fillellipse(screen, e.mouse.xy, 5, 5, display->white, ZP);
				flushimage(display, 1);
			}
			break;
		case Ekeyboard:
			if(e.kbdc == 'q') exits(nil);
			if(e.kbdc == 'c')
				draw(screen, screen->r, display->white, 0, ZP);
			break;
		}
	}
}

void
eresized(int)
{
	if(getwindow(display, Refnone) < 0)
		sysfatal("resize failed");
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].