Corrected zoom level handling

This commit is contained in:
Bert Münnich 2012-08-16 13:09:44 +02:00
parent 4ce323213d
commit 8a652a786c
3 changed files with 21 additions and 9 deletions

View File

@ -1,4 +1,4 @@
VERSION = git-20120807
VERSION = git-20120816
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man

25
image.c
View File

@ -36,9 +36,14 @@ enum { MIN_GIF_DELAY = 50 };
float zoom_min;
float zoom_max;
bool zoomdiff(float z1, float z2) {
int zoomdiff(float z1, float z2) {
float d = z1 - z2;
const float mindelta = 0.001;
return (z1 - z2 > mindelta) || (z1 - z2 < mindelta);
if (ABS(d) < mindelta)
return 0;
else
return d < 0 ? -1 : 1;
}
void img_init(img_t *img, win_t *win) {
@ -380,7 +385,7 @@ bool img_fit(img_t *img) {
z = MAX(z, zoom_min);
z = MIN(z, zmax);
if (zoomdiff(z, img->zoom)) {
if (zoomdiff(z, img->zoom) != 0) {
img->zoom = z;
img->dirty = true;
return true;
@ -496,7 +501,7 @@ bool img_zoom(img_t *img, float z) {
img->scalemode = SCALE_ZOOM;
if (zoomdiff(z, img->zoom)) {
if (zoomdiff(z, img->zoom) != 0) {
img->x = img->win->w / 2 - (img->win->w / 2 - img->x) * z / img->zoom;
img->y = img->win->h / 2 - (img->win->h / 2 - img->y) * z / img->zoom;
img->zoom = z;
@ -510,26 +515,30 @@ bool img_zoom(img_t *img, float z) {
bool img_zoom_in(img_t *img) {
int i;
float z;
if (img == NULL || img->im == NULL)
return false;
for (i = 1; i < ARRLEN(zoom_levels); i++) {
if (zoom_levels[i] > img->zoom * 100.0)
return img_zoom(img, zoom_levels[i] / 100.0);
z = zoom_levels[i] / 100.0;
if (zoomdiff(z, img->zoom) > 0)
return img_zoom(img, z);
}
return false;
}
bool img_zoom_out(img_t *img) {
int i;
float z;
if (img == NULL || img->im == NULL)
return false;
for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) {
if (zoom_levels[i] < img->zoom * 100.0)
return img_zoom(img, zoom_levels[i] / 100.0);
z = zoom_levels[i] / 100.0;
if (zoomdiff(z, img->zoom) < 0)
return img_zoom(img, z);
}
return false;
}

3
util.h
View File

@ -27,6 +27,9 @@
#include "types.h"
#ifndef ABS
#define ABS(a) ((a) < 0 ? -(a) : (a))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif