From 9d9ec8ce5fef38f991f3a5a708d985b0f5225baa Mon Sep 17 00:00:00 2001 From: elioat Date: Thu, 25 May 2023 22:04:42 -0400 Subject: * --- p9c/scratch/build.sh | 4 +++ p9c/scratch/clean.sh | 3 ++ p9c/scratch/hi.c | 9 ++++++ p9c/scratch/keyboard.c | 37 ++++++++++++++++++++++++ p9c/scratch/menu.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ p9c/scratch/mouse.c | 38 +++++++++++++++++++++++++ 6 files changed, 168 insertions(+) create mode 100755 p9c/scratch/build.sh create mode 100755 p9c/scratch/clean.sh create mode 100644 p9c/scratch/hi.c create mode 100644 p9c/scratch/keyboard.c create mode 100644 p9c/scratch/menu.c create mode 100644 p9c/scratch/mouse.c (limited to 'p9c/scratch') 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 +#include + +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 +#include +#include +#include +#include + +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 +#include +#include +#include + +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 +#include +#include +#include + +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 -- cgit 1.4.1-2-gfad0