From 8013dbfa6ffe40fd9244fd5532d75e93ea40259f Mon Sep 17 00:00:00 2001 From: elioat Date: Thu, 25 May 2023 22:00:32 -0400 Subject: * --- p9c/keyboard.c | 37 ++++++++++++++++++++++++ p9c/lbforth/lbforth9.c | 7 +++-- p9c/menu.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ p9c/mouse.c | 38 +++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 p9c/keyboard.c create mode 100644 p9c/menu.c create mode 100644 p9c/mouse.c (limited to 'p9c') 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 +#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/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 +#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/mouse.c b/p9c/mouse.c new file mode 100644 index 0000000..214526a --- /dev/null +++ b/p9c/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