Date:2010-09-24 23:24:10 (8 years 9 months ago)
Author:Werner Almesberger
Commit:a7105addcbd924297e077d7203b94139f37224d7
Message: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
Files: solidify/overlap.c (4 diffs)
solidify/style.h (1 diff)

Change Details

solidify/overlap.c
309309}
310310
311311
312static void do_shift(struct matrix *m, int dx, int dy)
312static void do_shift(struct matrix *m, double dx, double dy)
313313{
314314    m->b[0] += dx;
315315    m->b[1] += dy;
316316}
317317
318318
319static void shift(struct matrix *m, int dx, int dy, int dir)
319static void shift(struct matrix *m, int dx, int dy, double dist)
320320{
321321    /*
322322     * Wheeling "up" in each quadrant shifts in the respective direction,
...... 
328328     */
329329
330330    if (dx > 0 && dy < dx && dy > -dx)
331        do_shift(m, dir, 0);
331        do_shift(m, dist, 0);
332332    if (dx < 0 && dy < -dx && dy > dx)
333        do_shift(m, -dir, 0);
333        do_shift(m, -dist, 0);
334334    if (dy > 0 && dx < dy && dx > -dy)
335        do_shift(m, 0, dir);
335        do_shift(m, 0, dist);
336336    if (dy < 0 && dx < -dy && dx > dy)
337        do_shift(m, 0, dir); /* exception ! */
337        do_shift(m, 0, dist); /* exception ! */
338338}
339339
340340
...... 
362362    int dy = event->y-sy(s)/2;
363363    double r = hypot(dx, dy);
364364    double rc = r_center(s);
365    double rs, rot;
365    double rs, rot, dist;
366366    int center = r < rc;
367367    int osd = osd_proximity(s, dx, dy);
368368
...... 
386386    rot = (r-rc)/(rs-rc);
387387    rot = SLOWEST_ROT*rs*exp(-rot*log(SLOWEST_ROT*rs/FASTEST_ROT));
388388
389    /*
390     * dist stays at 1 from 0...rc/DIST_STEPS, then linearly goes up to
391     * DIST_STEPS from rc/DIST_STEPS...rc
392     */
393    dist = r/rc*DIST_STEPS;
394    if (dist < 0)
395        dist = 1;
396
389397    switch (event->direction) {
390398    case GDK_SCROLL_UP:
391399        if (center)
392            shift(&s->a->m, dx, dy, 1);
400            shift(&s->a->m, dx, dy, dist);
393401        else
394402            rotate(&s->a->m, dx > 0 ? rot : -rot);
395403        draw_image(darea, s, osd);
396404        break;
397405    case GDK_SCROLL_DOWN:
398406        if (center)
399            shift(&s->a->m, dx, dy, -1);
407            shift(&s->a->m, dx, dy, -dist);
400408        else
401409            rotate(&s->a->m, dx > 0 ? -rot : rot);
402410        draw_image(darea, s, osd);
solidify/style.h
2525#define OVERLAP_CENTER_DIV 5 /* fraction of diagonal */
2626#define SLOWEST_ROT 3 /* thrice the half-diagonal */
2727#define FASTEST_ROT 2 /* one pixel in distance of 2 pixels */
28#define DIST_STEPS 5 /* fastest shift is 5 px/wheel step */
2829
2930
3031void init_style(GdkDrawable *da);

Archive Download the corresponding diff file

Branches:
master



interactive