about summary refs log tree commit diff stats
path: root/p9c/scratch
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-05-25 22:04:42 -0400
committerelioat <elioat@tilde.institute>2023-05-25 22:04:42 -0400
commit9d9ec8ce5fef38f991f3a5a708d985b0f5225baa (patch)
tree9c7c69f3efb0db15c3579766e075e9461c3df099 /p9c/scratch
parente85017e9cecfd5c41b9c9924a9355cad364c0b3e (diff)
downloadtour-9d9ec8ce5fef38f991f3a5a708d985b0f5225baa.tar.gz
*
Diffstat (limited to 'p9c/scratch')
-rwxr-xr-xp9c/scratch/build.sh4
-rwxr-xr-xp9c/scratch/clean.sh3
-rw-r--r--p9c/scratch/hi.c9
-rw-r--r--p9c/scratch/keyboard.c37
-rw-r--r--p9c/scratch/menu.c77
-rw-r--r--p9c/scratch/mouse.c38
6 files changed, 168 insertions, 0 deletions
diff --git a/p9c/scratch/build.sh b/p9c/scratch/build.sh
new file mode 100755
index 0000000..0238b83
--- /dev/null
+++ b/p9c/scratch/build.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+9 9c hi.c
+9 9l hi.o -o hi
diff --git a/p9c/scratch/clean.sh b/p9c/scratch/clean.sh
new file mode 100755
index 0000000..1ddbf65
--- /dev/null
+++ b/p9c/scratch/clean.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+rm hi.o hi
diff --git a/p9c/scratch/hi.c b/p9c/scratch/hi.c
new file mode 100644
index 0000000..cd6ba1c
--- /dev/null
+++ b/p9c/scratch/hi.c
@@ -0,0 +1,9 @@
+#include <u.h>
+#include <libc.h>
+
+void
+main(void)
+{
+  print("hello, world\n");
+  exits(0);
+}
diff --git a/p9c/scratch/keyboard.c b/p9c/scratch/keyboard.c
new file mode 100644
index 0000000..175658b
--- /dev/null
+++ b/p9c/scratch/keyboard.c
@@ -0,0 +1,37 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+#include <keyboard.h>
+
+void
+eresized(int new)
+{
+	if(new&& getwindow(display, Refnone) < 0)
+		sysfatal("can't reattach to window");
+}
+
+void
+main(int argc, char* argv[])
+{
+	// USED(argc, argv);
+
+	Event ev;
+	int e;
+	initdraw(0, 0, "Example: Keyboard");
+	eresized(0);
+	einit(Ekeyboard);
+
+	/* Main loop */
+	for(;;) {
+		e = event(&ev);
+		if(e == Ekeyboard) {
+			print("key: %d\n", ev.kbdc);
+			/* Break on escape */
+			if(ev.kbdc == 27) {
+				print("Escaped\n");
+				break;
+			}
+		}
+	}
+}
\ No newline at end of file
diff --git a/p9c/scratch/menu.c b/p9c/scratch/menu.c
new file mode 100644
index 0000000..97004d6
--- /dev/null
+++ b/p9c/scratch/menu.c
@@ -0,0 +1,77 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+
+char* options1[] = {"Middle Click", "", "Paste", "Snarf", "Exit", 0};
+char* options2[] = {"Right Click", "", "Option3", "Option4", "Exit", 0};
+
+Menu middlemenu = {options1};
+Menu rightmenu = {options2};
+
+void
+eresized(int new)
+{
+	if(new&& getwindow(display, Refnone) < 0)
+		sysfatal("can't reattach to window");
+}
+
+void
+dopaste(void)
+{
+	int f;
+	if((f = open("/dev/snarf", OREAD)) >= 0) {
+		char body[30];
+		read(f, body, 30);
+		print("Paste: %s\n", body);
+		close(f);
+	}
+}
+
+void
+dosnarf(void)
+{
+	int f;
+	if((f = open("/dev/snarf", OWRITE)) >= 0) {
+		char* body = "some text";
+		write(f, body, strlen(body));
+		print("Snarf: %s\n", body);
+		close(f);
+	}
+}
+
+void
+main(int argc, char* argv[])
+{
+	// USED(argc, argv);
+
+	Event ev;
+	int e;
+
+	initdraw(0, 0, "Example: Menu");
+	eresized(0);
+	einit(Emouse);
+
+	/* Main event loop */
+	for(;;) {
+		e = event(&ev);
+		/* Middle Click */
+		if((e == Emouse) && (ev.mouse.buttons & 3)) {
+			if(emenuhit(2, &ev.mouse, &middlemenu) == 2)
+				dopaste();
+			if(emenuhit(2, &ev.mouse, &middlemenu) == 3)
+				dosnarf();
+			if(emenuhit(2, &ev.mouse, &middlemenu) == 4)
+				exits(nil);
+		}
+		/* Right Click */
+		else if((e == Emouse) && (ev.mouse.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);
+		}
+	}
+}
\ No newline at end of file
diff --git a/p9c/scratch/mouse.c b/p9c/scratch/mouse.c
new file mode 100644
index 0000000..214526a
--- /dev/null
+++ b/p9c/scratch/mouse.c
@@ -0,0 +1,38 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+
+void
+eresized(int new)
+{
+	if(new&& getwindow(display, Refnone) < 0)
+		sysfatal("can't reattach to window");
+}
+
+void
+main(int argc, char* argv[])
+{
+	// USED(argc, argv);
+
+	Mouse m;
+	Point prevm;
+	initdraw(0, 0, "Example: Mouse");
+	eresized(0);
+	einit(Emouse);
+
+	/* Main loop */
+	for(;;) {
+		m = emouse();
+		if(m.buttons & 4)
+			break;
+		if(m.buttons & 1) {
+			line(screen,
+			     prevm.x == -1 ? m.xy : prevm,
+			     m.xy, Enddisc, Enddisc, 1, display->black, ZP);
+			prevm = m.xy;
+		} else {
+			prevm = Pt(-1, -1);
+		}
+	}
+}
\ No newline at end of file