diff options
author | Bert Münnich <ber.t@posteo.de> | 2018-01-22 10:37:06 +0100 |
---|---|---|
committer | Bert Münnich <ber.t@posteo.de> | 2018-01-22 10:37:10 +0100 |
commit | 727939b3e6380e623540b4dfae497ead2c3c6e04 (patch) | |
tree | 1cd43e6fa110ce09124362a196a5f73ed2c6502a | |
parent | 4c294011a9771dd1ef38903cab31328a95224217 (diff) |
Make zoomdiff compare impact on image dimensions
Before that zoomdiff was a merely heuristic.
Related to issue #303
-rw-r--r-- | image.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -39,9 +39,9 @@ enum { DEF_GIF_DELAY = 75 }; float zoom_min; float zoom_max; -static int zoomdiff(float z1, float z2) +static int zoomdiff(img_t *img, float z) { - return (int) (z1 * 1000.0 - z2 * 1000.0); + return (int) ((img->w * z - img->w * img->zoom) + (img->h * z - img->h * img->zoom)); } void img_init(img_t *img, win_t *win) @@ -417,7 +417,7 @@ bool img_fit(img_t *img) z = MAX(z, zoom_min); z = MIN(z, zmax); - if (zoomdiff(z, img->zoom) != 0) { + if (zoomdiff(img, z) != 0) { img->zoom = z; img->dirty = true; return true; @@ -539,7 +539,7 @@ bool img_zoom(img_t *img, float z) img->scalemode = SCALE_ZOOM; - if (zoomdiff(z, img->zoom) != 0) { + if (zoomdiff(img, z) != 0) { int x, y; win_cursor_pos(img->win, &x, &y); @@ -565,7 +565,7 @@ bool img_zoom_in(img_t *img) for (i = 1; i < ARRLEN(zoom_levels); i++) { z = zoom_levels[i] / 100.0; - if (zoomdiff(z, img->zoom) > 0) + if (zoomdiff(img, z) > 0) return img_zoom(img, z); } return false; @@ -578,7 +578,7 @@ bool img_zoom_out(img_t *img) for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) { z = zoom_levels[i] / 100.0; - if (zoomdiff(z, img->zoom) < 0) + if (zoomdiff(img, z) < 0) return img_zoom(img, z); } return false; |