diff options
author | rodri <rgl@antares-labs.eu> | 2022-06-15 19:59:48 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2022-06-15 19:59:48 +0000 |
commit | 4a2e2bfe6c3993ed29c593adfb9069f7c50b9ced (patch) | |
tree | 3528011649942f98a823ff2f90184a9f5e8c3d03 | |
parent | b69fdfbf30beb998c1817784e748ae78806becf8 (diff) | |
download | musw-4a2e2bfe6c3993ed29c593adfb9069f7c50b9ced.tar.gz musw-4a2e2bfe6c3993ed29c593adfb9069f7c50b9ced.tar.bz2 musw-4a2e2bfe6c3993ed29c593adfb9069f7c50b9ced.zip |
began work on a VModel editor.
-rw-r--r-- | vmodeled/main.c | 142 | ||||
-rw-r--r-- | vmodeled/mkfile | 24 |
2 files changed, 166 insertions, 0 deletions
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 <u.h> +#include <libc.h> +#include <thread.h> +#include <draw.h> +#include <mouse.h> +#include <keyboard.h> +#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 @@ +</$objtype/mkfile + +BIN=/$objtype/bin/musw +TARG=vmodeled +OFILES=\ + main.$O\ + +HFILES=\ + ../libgeometry/geometry.h\ + +LIB=\ + ../libgeometry/libgeometry.a$O\ + +CFLAGS=$CFLAGS + +</sys/src/cmd/mkone + +../libgeometry/libgeometry.a$O: + cd ../libgeometry + mk install + +clean nuke:V: + rm -f *.[$OS] [$OS].??* $TARG + @{cd ../libgeometry; mk $target} |