From a7105addcbd924297e077d7203b94139f37224d7 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 24 Sep 2010 18:24:10 -0300 Subject: [PATCH] Like rotations, shifts can now be accelerated by changing the mouse position. - solidify/overlap.c (do_shift, shift): instead of passing an integer direction, pass a floating-point distance - solidify/overlap.c (scroll_event): weight shifts as well. Closer to the circle means faster. - solidify/style.h (DIST_STEPS): acceleration factor for shifts --- solidify/overlap.c | 26 +++++++++++++++++--------- solidify/style.h | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/solidify/overlap.c b/solidify/overlap.c index a8c7805..e47e13a 100644 --- a/solidify/overlap.c +++ b/solidify/overlap.c @@ -309,14 +309,14 @@ static void rotate(struct matrix *m, double r) } -static void do_shift(struct matrix *m, int dx, int dy) +static void do_shift(struct matrix *m, double dx, double dy) { m->b[0] += dx; m->b[1] += dy; } -static void shift(struct matrix *m, int dx, int dy, int dir) +static void shift(struct matrix *m, int dx, int dy, double dist) { /* * Wheeling "up" in each quadrant shifts in the respective direction, @@ -328,13 +328,13 @@ static void shift(struct matrix *m, int dx, int dy, int dir) */ if (dx > 0 && dy < dx && dy > -dx) - do_shift(m, dir, 0); + do_shift(m, dist, 0); if (dx < 0 && dy < -dx && dy > dx) - do_shift(m, -dir, 0); + do_shift(m, -dist, 0); if (dy > 0 && dx < dy && dx > -dy) - do_shift(m, 0, dir); + do_shift(m, 0, dist); if (dy < 0 && dx < -dy && dx > dy) - do_shift(m, 0, dir); /* exception ! */ + do_shift(m, 0, dist); /* exception ! */ } @@ -362,7 +362,7 @@ static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, int dy = event->y-sy(s)/2; double r = hypot(dx, dy); double rc = r_center(s); - double rs, rot; + double rs, rot, dist; int center = r < rc; int osd = osd_proximity(s, dx, dy); @@ -386,17 +386,25 @@ static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, rot = (r-rc)/(rs-rc); rot = SLOWEST_ROT*rs*exp(-rot*log(SLOWEST_ROT*rs/FASTEST_ROT)); + /* + * dist stays at 1 from 0...rc/DIST_STEPS, then linearly goes up to + * DIST_STEPS from rc/DIST_STEPS...rc + */ + dist = r/rc*DIST_STEPS; + if (dist < 0) + dist = 1; + switch (event->direction) { case GDK_SCROLL_UP: if (center) - shift(&s->a->m, dx, dy, 1); + shift(&s->a->m, dx, dy, dist); else rotate(&s->a->m, dx > 0 ? rot : -rot); draw_image(darea, s, osd); break; case GDK_SCROLL_DOWN: if (center) - shift(&s->a->m, dx, dy, -1); + shift(&s->a->m, dx, dy, -dist); else rotate(&s->a->m, dx > 0 ? -rot : rot); draw_image(darea, s, osd); diff --git a/solidify/style.h b/solidify/style.h index e678b15..39085fb 100644 --- a/solidify/style.h +++ b/solidify/style.h @@ -25,6 +25,7 @@ extern GdkGC *gc_osd; #define OVERLAP_CENTER_DIV 5 /* fraction of diagonal */ #define SLOWEST_ROT 3 /* thrice the half-diagonal */ #define FASTEST_ROT 2 /* one pixel in distance of 2 pixels */ +#define DIST_STEPS 5 /* fastest shift is 5 px/wheel step */ void init_style(GdkDrawable *da);