aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--image.c20
-rw-r--r--image.h6
-rw-r--r--main.c10
4 files changed, 19 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 1178c8b..163596f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
all: sxiv
-VERSION=git-20110415
+VERSION=git-20110419
CC?=gcc
PREFIX?=/usr/local
diff --git a/image.c b/image.c
index e3e9dc2..7368854 100644
--- a/image.c
+++ b/image.c
@@ -212,8 +212,8 @@ int img_center(img_t *img, win_t *win) {
return ox != img->x || oy != img->y;
}
-int img_zoom(img_t *img, float z) {
- if (!img || !img->im)
+int img_zoom(img_t *img, win_t *win, float z) {
+ if (!img || !img->im || !win)
return 0;
z = MAX(z, zoom_min);
@@ -222,8 +222,8 @@ int img_zoom(img_t *img, float z) {
img->scalemode = SCALE_ZOOM;
if (z != img->zoom) {
- img->x -= (img->w * z - img->w * img->zoom) / 2;
- img->y -= (img->h * z - img->h * img->zoom) / 2;
+ img->x = win->w / 2 - (win->w / 2 - img->x) * z / img->zoom;
+ img->y = win->h / 2 - (win->h / 2 - img->y) * z / img->zoom;
img->zoom = z;
img->checkpan = 1;
return 1;
@@ -232,28 +232,28 @@ int img_zoom(img_t *img, float z) {
}
}
-int img_zoom_in(img_t *img) {
+int img_zoom_in(img_t *img, win_t *win) {
int i;
- if (!img || !img->im)
+ if (!img || !img->im || !win)
return 0;
for (i = 1; i < zl_cnt; ++i) {
if (zoom_levels[i] > img->zoom * 100.0)
- return img_zoom(img, zoom_levels[i] / 100.0);
+ return img_zoom(img, win, zoom_levels[i] / 100.0);
}
return 0;
}
-int img_zoom_out(img_t *img) {
+int img_zoom_out(img_t *img, win_t *win) {
int i;
- if (!img || !img->im)
+ if (!img || !img->im || !win)
return 0;
for (i = zl_cnt - 2; i >= 0; --i) {
if (zoom_levels[i] < img->zoom * 100.0)
- return img_zoom(img, zoom_levels[i] / 100.0);
+ return img_zoom(img, win, zoom_levels[i] / 100.0);
}
return 0;
}
diff --git a/image.h b/image.h
index ed7302d..0bc7b9d 100644
--- a/image.h
+++ b/image.h
@@ -63,9 +63,9 @@ void img_render(img_t*, win_t*);
int img_fit_win(img_t*, win_t*);
int img_center(img_t*, win_t*);
-int img_zoom(img_t*, float);
-int img_zoom_in(img_t*);
-int img_zoom_out(img_t*);
+int img_zoom(img_t*, win_t*, float);
+int img_zoom_in(img_t*, win_t*);
+int img_zoom_out(img_t*, win_t*);
int img_move(img_t*, win_t*, int, int);
int img_pan(img_t*, win_t*, pandir_t);
diff --git a/main.c b/main.c
index 5892f18..da05211 100644
--- a/main.c
+++ b/main.c
@@ -424,13 +424,13 @@ void on_keypress(XKeyEvent *kev) {
/* zooming */
case XK_plus:
case XK_equal:
- changed = img_zoom_in(&img);
+ changed = img_zoom_in(&img, &win);
break;
case XK_minus:
- changed = img_zoom_out(&img);
+ changed = img_zoom_out(&img, &win);
break;
case XK_0:
- changed = img_zoom(&img, 1.0);
+ changed = img_zoom(&img, &win, 1.0);
break;
case XK_w:
if ((changed = img_fit_win(&img, &win)))
@@ -607,7 +607,7 @@ void on_buttonpress(XButtonEvent *bev) {
break;
case Button4:
if (mask == ControlMask)
- changed = img_zoom_in(&img);
+ changed = img_zoom_in(&img, &win);
else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_LEFT);
else
@@ -615,7 +615,7 @@ void on_buttonpress(XButtonEvent *bev) {
break;
case Button5:
if (mask == ControlMask)
- changed = img_zoom_out(&img);
+ changed = img_zoom_out(&img, &win);
else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_RIGHT);
else