From d49f349fa03bb37058608178ba482bcf55ad1dd1 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 24 Sep 2010 01:11:57 -0300 Subject: [PATCH] The top face can now be shifted. - solidify/overlap.c (scroll_event): use center of canvas as center, not center of the top face - solidify/overlap.c (do_shift, shift, scroll_event): added translation (shifting) --- solidify/overlap.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/solidify/overlap.c b/solidify/overlap.c index a9dd805..c2f045b 100644 --- a/solidify/overlap.c +++ b/solidify/overlap.c @@ -180,25 +180,51 @@ static void rotate(struct matrix *m, double r) } +static void do_shift(struct matrix *m, int dx, int dy) +{ + m->b[0] -= dx; + m->b[1] += dy; +} + + +static void shift(struct matrix *m, int dx, int dy, int dir) +{ + if (dx > 0 && dy < dx && dy > -dx) + do_shift(m, dir, 0); + if (dx < 0 && dy < -dx && dy > dx) + do_shift(m, -dir, 0); + if (dy > 0 && dx < dy && dx > -dy) + do_shift(m, 0, dir); + if (dy < 0 && dx < -dy && dx > dy) + do_shift(m, 0, -dir); +} + + static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) { GtkWidget *da = gtk_bin_get_child(GTK_BIN(widget)); struct solid *s = data; - struct face *f = s->a; - int dx = event->x-f->sx/2; - int dy = event->y-f->sy/2; + int dx = event->x-sx(s)/2; + int dy = event->y-sy(s)/2; double r = hypot(dx, dy); + int center = r/hypot(sx(s), sy(s)) < 0.25; if (r < 1) return TRUE; switch (event->direction) { case GDK_SCROLL_UP: - rotate(&f->m, r); + if (center) + shift(&s->a->m, dx, dy, 1); + else + rotate(&s->a->m, r); draw_image(da, s); break; case GDK_SCROLL_DOWN: - rotate(&f->m, -r); + if (center) + shift(&s->a->m, dx, dy, -1); + else + rotate(&s->a->m, -r); draw_image(da, s); break; default: