aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--image.c25
-rw-r--r--util.h3
3 files changed, 21 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index bb4acbb..9a8a3ed 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = git-20120807
+VERSION = git-20120816
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
diff --git a/image.c b/image.c
index cb71fe3..52696ca 100644
--- a/image.c
+++ b/image.c
@@ -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;
}
diff --git a/util.h b/util.h
index f1f4f14..2a139ec 100644
--- a/util.h
+++ b/util.h
@@ -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