about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-05-25 22:00:32 -0400
committerelioat <elioat@tilde.institute>2023-05-25 22:00:32 -0400
commit8013dbfa6ffe40fd9244fd5532d75e93ea40259f (patch)
tree43b3bc985f38ad6c80746a984ebebfe07027fd99
parentb950e986561dd3718769ce6041971ee70880639f (diff)
downloadtour-8013dbfa6ffe40fd9244fd5532d75e93ea40259f.tar.gz
*
-rw-r--r--p9c/keyboard.c37
-rw-r--r--p9c/lbforth/lbforth9.c7
-rw-r--r--p9c/menu.c77
-rw-r--r--p9c/mouse.c38
4 files changed, 156 insertions, 3 deletions
diff --git a/p9c/keyboard.c b/p9c/keyboard.c
new file mode 100644
index 0000000..175658b
--- /dev/null
+++ b/p9c/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/lbforth/lbforth9.c b/p9c/lbforth/lbforth9.c
index 6ee5fa6..9673da4 100644
--- a/p9c/lbforth/lbforth9.c
+++ b/p9c/lbforth/lbforth9.c
@@ -414,8 +414,9 @@ parseNumber(byte* word, cell len, dcell* number, cell* notRead, byte* isDouble)
 {
 	int negative = 0;
 	cell i;
-	char c;
-	cell current;
+	charn
+    n
+    
 
 	*number = 0;
 	*isDouble = 0;
@@ -1211,4 +1212,4 @@ main()
 	initscript_pos = (char*)initScript;
 	quit();
 	return 0;
-}
\ No newline at end of file
+}
diff --git a/p9c/menu.c b/p9c/menu.c
new file mode 100644
index 0000000..97004d6
--- /dev/null
+++ b/p9c/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/mouse.c b/p9c/mouse.c
new file mode 100644
index 0000000..214526a
--- /dev/null
+++ b/p9c/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