Center zoomed area

This commit is contained in:
Bert 2011-04-19 13:27:20 +02:00
parent 548b383f0b
commit ba293b09df
4 changed files with 19 additions and 19 deletions

View file

@ -1,6 +1,6 @@
all: sxiv all: sxiv
VERSION=git-20110415 VERSION=git-20110419
CC?=gcc CC?=gcc
PREFIX?=/usr/local PREFIX?=/usr/local

20
image.c
View file

@ -212,8 +212,8 @@ int img_center(img_t *img, win_t *win) {
return ox != img->x || oy != img->y; return ox != img->x || oy != img->y;
} }
int img_zoom(img_t *img, float z) { int img_zoom(img_t *img, win_t *win, float z) {
if (!img || !img->im) if (!img || !img->im || !win)
return 0; return 0;
z = MAX(z, zoom_min); z = MAX(z, zoom_min);
@ -222,8 +222,8 @@ int img_zoom(img_t *img, float z) {
img->scalemode = SCALE_ZOOM; img->scalemode = SCALE_ZOOM;
if (z != img->zoom) { if (z != img->zoom) {
img->x -= (img->w * z - img->w * img->zoom) / 2; img->x = win->w / 2 - (win->w / 2 - img->x) * z / img->zoom;
img->y -= (img->h * z - img->h * img->zoom) / 2; img->y = win->h / 2 - (win->h / 2 - img->y) * z / img->zoom;
img->zoom = z; img->zoom = z;
img->checkpan = 1; img->checkpan = 1;
return 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; int i;
if (!img || !img->im) if (!img || !img->im || !win)
return 0; return 0;
for (i = 1; i < zl_cnt; ++i) { for (i = 1; i < zl_cnt; ++i) {
if (zoom_levels[i] > img->zoom * 100.0) 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; return 0;
} }
int img_zoom_out(img_t *img) { int img_zoom_out(img_t *img, win_t *win) {
int i; int i;
if (!img || !img->im) if (!img || !img->im || !win)
return 0; return 0;
for (i = zl_cnt - 2; i >= 0; --i) { for (i = zl_cnt - 2; i >= 0; --i) {
if (zoom_levels[i] < img->zoom * 100.0) 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; return 0;
} }

View file

@ -63,9 +63,9 @@ void img_render(img_t*, win_t*);
int img_fit_win(img_t*, win_t*); int img_fit_win(img_t*, win_t*);
int img_center(img_t*, win_t*); int img_center(img_t*, win_t*);
int img_zoom(img_t*, float); int img_zoom(img_t*, win_t*, float);
int img_zoom_in(img_t*); int img_zoom_in(img_t*, win_t*);
int img_zoom_out(img_t*); int img_zoom_out(img_t*, win_t*);
int img_move(img_t*, win_t*, int, int); int img_move(img_t*, win_t*, int, int);
int img_pan(img_t*, win_t*, pandir_t); int img_pan(img_t*, win_t*, pandir_t);

10
main.c
View file

@ -424,13 +424,13 @@ void on_keypress(XKeyEvent *kev) {
/* zooming */ /* zooming */
case XK_plus: case XK_plus:
case XK_equal: case XK_equal:
changed = img_zoom_in(&img); changed = img_zoom_in(&img, &win);
break; break;
case XK_minus: case XK_minus:
changed = img_zoom_out(&img); changed = img_zoom_out(&img, &win);
break; break;
case XK_0: case XK_0:
changed = img_zoom(&img, 1.0); changed = img_zoom(&img, &win, 1.0);
break; break;
case XK_w: case XK_w:
if ((changed = img_fit_win(&img, &win))) if ((changed = img_fit_win(&img, &win)))
@ -607,7 +607,7 @@ void on_buttonpress(XButtonEvent *bev) {
break; break;
case Button4: case Button4:
if (mask == ControlMask) if (mask == ControlMask)
changed = img_zoom_in(&img); changed = img_zoom_in(&img, &win);
else if (mask == ShiftMask) else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_LEFT); changed = img_pan(&img, &win, PAN_LEFT);
else else
@ -615,7 +615,7 @@ void on_buttonpress(XButtonEvent *bev) {
break; break;
case Button5: case Button5:
if (mask == ControlMask) if (mask == ControlMask)
changed = img_zoom_out(&img); changed = img_zoom_out(&img, &win);
else if (mask == ShiftMask) else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_RIGHT); changed = img_pan(&img, &win, PAN_RIGHT);
else else