From 4a2e2bfe6c3993ed29c593adfb9069f7c50b9ced Mon Sep 17 00:00:00 2001 From: rodri Date: Wed, 15 Jun 2022 19:59:48 +0000 Subject: began work on a VModel editor. --- vmodeled/main.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vmodeled/mkfile | 24 ++++++++++ 2 files changed, 166 insertions(+) create mode 100644 vmodeled/main.c create mode 100644 vmodeled/mkfile diff --git a/vmodeled/main.c b/vmodeled/main.c new file mode 100644 index 0000000..1fe055f --- /dev/null +++ b/vmodeled/main.c @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include +#include +#include "../libgeometry/geometry.h" + +RFrame worldrf; + +void resized(void); + +Point +toscreen(Point2 p) +{ + p = invrframexform(p, worldrf); + return Pt(p.x,p.y); +} + +Point2 +fromscreen(Point p) +{ + return rframexform(Pt2(p.x,p.y,1), worldrf); +} + +void +redraw(void) +{ + lockdisplay(display); + draw(screen, screen->r, display->black, nil, ZP); + line(screen, toscreen(Pt2(0,512,1)), toscreen(Pt2(0,-512,1)), 0, 0, 0, display->white, ZP); + line(screen, toscreen(Pt2(512,0,1)), toscreen(Pt2(-512,0,1)), 0, 0, 0, display->white, ZP); + flushimage(display, 1); + unlockdisplay(display); +} + +void +rmb(Mousectl *, Keyboardctl *) +{ +} + +void +lmb(Mousectl *mc, Keyboardctl *) +{ + Point2 mpos; + + mpos = fromscreen(mc->xy); + fprint(2, "%v\n", mpos); +} + +void +mouse(Mousectl *mc, Keyboardctl *kc) +{ + if((mc->buttons&1) != 0) + lmb(mc, kc); + if((mc->buttons&4) != 0) + rmb(mc, kc); +} + +void +key(Rune r) +{ + switch(r){ + case Kdel: + case 'q': + threadexitsall(nil); + } +} + +void +usage(void) +{ + fprint(2, "usage: %s\n", argv0); + exits("usage"); +} + +void +threadmain(int argc, char *argv[]) +{ + Mousectl *mc; + Keyboardctl *kc; + Rune r; + + GEOMfmtinstall(); + ARGBEGIN{ + default: usage(); + }ARGEND; + if(argc > 0) + usage(); + + if(newwindow(nil) < 0) + sysfatal("newwindow: %r"); + if(initdraw(nil, nil, nil) < 0) + sysfatal("initdraw: %r"); + if((mc = initmouse(nil, screen)) == nil) + sysfatal("initmouse: %r"); + if((kc = initkeyboard(nil)) == nil) + sysfatal("initkeyboard: %r"); + + worldrf.p = Pt2(screen->r.min.x+Dx(screen->r)/2,screen->r.max.y-Dy(screen->r)/2,1); + worldrf.bx = Vec2(1, 0); + worldrf.by = Vec2(0,-1); + + display->locking = 1; + unlockdisplay(display); + redraw(); + + for(;;){ + enum { MOUSE, RESIZE, KEYBOARD }; + Alt a[] = { + {mc->c, &mc->Mouse, CHANRCV}, + {mc->resizec, nil, CHANRCV}, + {kc->c, &r, CHANRCV}, + {nil, nil, CHANEND} + }; + + switch(alt(a)){ + case MOUSE: + mouse(mc, kc); + break; + case RESIZE: + resized(); + break; + case KEYBOARD: + key(r); + break; + } + + redraw(); + } +} + +void +resized(void) +{ + lockdisplay(display); + if(getwindow(display, Refnone) < 0) + sysfatal("couldn't resize"); + unlockdisplay(display); + worldrf.p = Pt2(screen->r.min.x+Dx(screen->r)/2,screen->r.max.y-Dy(screen->r)/2,1); + redraw(); +} diff --git a/vmodeled/mkfile b/vmodeled/mkfile new file mode 100644 index 0000000..eba7c97 --- /dev/null +++ b/vmodeled/mkfile @@ -0,0 +1,24 @@ +