aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-04-30 21:07:54 +0000
committerrodri <rgl@antares-labs.eu>2023-04-30 21:07:54 +0000
commit983d1181b2be54d3dcf2e33d343044ea6dbb0e41 (patch)
treef69fda812c85c1fa240c0b39cbef67ab1f476f1f
parentb63b8b0e316fa4b8d4362cb2e538bf5d8a75552a (diff)
downloadmusw-983d1181b2be54d3dcf2e33d343044ea6dbb0e41.tar.gz
musw-983d1181b2be54d3dcf2e33d343044ea6dbb0e41.tar.bz2
musw-983d1181b2be54d3dcf2e33d343044ea6dbb0e41.zip
vmodeled: implemented the ability to move points around as a new mode/state.
-rw-r--r--vmodeled/main.c56
1 files changed, 51 insertions, 5 deletions
diff --git a/vmodeled/main.c b/vmodeled/main.c
index 258b142..34a0c4e 100644
--- a/vmodeled/main.c
+++ b/vmodeled/main.c
@@ -16,7 +16,9 @@ typedef enum {
typedef enum {
Drawing,
Zooming,
- Rotating
+ Rotating,
+ Movingpts,
+ NStates
} State;
/*
@@ -50,6 +52,13 @@ char *strokename[NStrokes] = {
[SCurve] "curve",
};
+char *statename[NStates] = {
+ [Drawing] "drawing",
+ [Zooming] "zooming",
+ [Rotating] "rotating",
+ [Movingpts] "moving",
+};
+
RFrame worldrf;
Object mainobj;
Stroke stroke;
@@ -282,6 +291,9 @@ drawinfo(void)
p.y += font->height;
snprint(buf, sizeof buf, "op %s", strokename[stroke]);
string(screen, addpt(screen->r.min, p), display->white, ZP, font, buf);
+ p.y += font->height;
+ snprint(buf, sizeof buf, "s %s", statename[curstate]);
+ string(screen, addpt(screen->r.min, p), display->white, ZP, font, buf);
}
void
@@ -421,6 +433,30 @@ plot(Mousectl *mc, Keyboardctl *)
}
void
+movept(Mousectl *mc, Keyboardctl *)
+{
+ Point2 p0, p1, *pp;
+ VModel *mdl;
+
+ p1 = fromscreen(mc->xy); /* screen to world */
+ mdl = mainobj.mdl;
+
+ for(pp = mdl->pts; pp < mdl->pts+mdl->npts; pp++){
+ p0 = invrframexform(*pp, mainobj); /* object to world */
+ if(vec2len(subpt2(p0, p1)) <= 2){
+ for(;;){
+ readmouse(mc);
+ if(mc->buttons != 1)
+ break;
+ *pp = rframexform(fromscreen(mc->xy), mainobj);
+ redraw();
+ }
+ break;
+ }
+ }
+}
+
+void
zoom(Mousectl *mc, Keyboardctl *)
{
double z; /* zooming factor */
@@ -467,11 +503,15 @@ rota(Mousectl *mc, Keyboardctl *)
void
mouse(Mousectl *mc, Keyboardctl *kc)
{
- if((mc->buttons&1) != 0)
- plot(mc, kc);
- if((mc->buttons&2) != 0)
+ if((mc->buttons & 1) != 0){
+ if(curstate == Drawing)
+ plot(mc, kc);
+ else if(curstate == Movingpts)
+ movept(mc, kc);
+ }
+ if((mc->buttons & 2) != 0)
zoom(mc, kc);
- if((mc->buttons&4) != 0)
+ if((mc->buttons & 4) != 0)
rota(mc, kc);
}
@@ -491,6 +531,12 @@ key(Rune r)
case 'c':
stroke = SCurve;
break;
+ case 'm':
+ curstate = Movingpts;
+ break;
+ case 'd':
+ curstate = Drawing;
+ break;
case 'z':
undo();
break;