about summary refs log tree commit diff stats
path: root/p9c/scratch/mouse.c
blob: 21c6d33036bff3e7987159a710ca313ee0b51f14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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);
		}
	}
}