about summary refs log blame commit diff stats
path: root/p9c/scratch/mouse.c
blob: 21c6d33036bff3e7987159a710ca313ee0b51f14 (plain) (tree)
1
2
3
4
5
6
7
8
9




                  



                                                                       









                                                     

                

                 
                    
 
                               




                       
                               
                             






                                                                   


                                                          
                                                                                                                                            





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

char* options[] = {"Right Click", "", "Option3", "Option4", "Exit", 0};

Menu rightmenu = {options};

void
eresized(int new)
{
	if(new&& getwindow(display, Refnone) < 0)
		sysfatal("can't reattach to window");
}

void
main(int argc, char* argv[])
{

	Mouse m;
	Event ev;
	int e;
	Point prevm;

	initdraw(0, 0, "draw");
	eresized(0);
	einit(Emouse);

	/* Main loop */
	for(;;) {
		e = event(&ev);
		m = emouse();
		if((e == Emouse) && (m.buttons & 4))
			if(emenuhit(3, &ev.mouse, &rightmenu) == 2)
				print("Pressed Option 3\n");
			if(emenuhit(3, &ev.mouse, &rightmenu) == 3)
				print("Pressed Option 4\n");
			if(emenuhit(3, &ev.mouse, &rightmenu) == 4)
				exits(nil);
		if(m.buttons & 1) {
			line(screen,
			     prevm.x == -1 ? m.xy : prevm,
			     m.xy, Enddisc, Enddisc, 1, display->black, ZP); // where the int after Enddisc with the width of the line drawn
			prevm = m.xy;
		} else {
			prevm = Pt(-1, -1);
		}
	}
}