Preserve panning when switching images; fixes issue #131

This commit is contained in:
Bert Münnich 2014-02-04 21:02:02 +01:00
parent 2e758f78c1
commit eb82519a80
4 changed files with 29 additions and 57 deletions

View File

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

View File

@ -433,14 +433,12 @@ cmdreturn_t i_set_zoom(arg_t a)
cmdreturn_t i_fit_to_win(arg_t a) cmdreturn_t i_fit_to_win(arg_t a)
{ {
cmdreturn_t ret = CMD_INVALID;
scalemode_t sm = (scalemode_t) a; scalemode_t sm = (scalemode_t) a;
if (mode == MODE_IMAGE) { if (mode == MODE_IMAGE)
if ((ret = img_fit_win(&img, sm))) return img_fit_win(&img, sm);
img_center(&img); else
} return CMD_INVALID;
return ret;
} }
cmdreturn_t i_fit_to_img(arg_t a) cmdreturn_t i_fit_to_img(arg_t a)

73
image.c
View File

@ -334,8 +334,7 @@ bool img_load(img_t *img, const fileinfo_t *file)
img->w = imlib_image_get_width(); img->w = imlib_image_get_width();
img->h = imlib_image_get_height(); img->h = imlib_image_get_height();
img->scalemode = options->scalemode; img->scalemode = options->scalemode;
img->re = false; img->checkpan = true;
img->checkpan = false;
img->dirty = true; img->dirty = true;
return true; return true;
@ -372,30 +371,29 @@ void img_check_pan(img_t *img, bool moved)
{ {
win_t *win; win_t *win;
int ox, oy; int ox, oy;
float w, h;
if (img == NULL || img->im == NULL || img->win == NULL) if (img == NULL || img->im == NULL || img->win == NULL)
return; return;
win = img->win; win = img->win;
w = img->w * img->zoom;
h = img->h * img->zoom;
ox = img->x; ox = img->x;
oy = img->y; oy = img->y;
if (img->w * img->zoom > win->w) { if (w < win->w)
if (img->x > 0 && img->x + img->w * img->zoom > win->w) img->x = (win->w - w) / 2;
img->x = 0; else if (img->x > 0)
if (img->x < 0 && img->x + img->w * img->zoom < win->w) img->x = 0;
img->x = win->w - img->w * img->zoom; else if (img->x + w < win->w)
} else { img->x = win->w - w;
img->x = (win->w - img->w * img->zoom) / 2; if (h < win->h)
} img->y = (win->h - h) / 2;
if (img->h * img->zoom > win->h) { else if (img->y > 0)
if (img->y > 0 && img->y + img->h * img->zoom > win->h) img->y = 0;
img->y = 0; else if (img->y + h < win->h)
if (img->y < 0 && img->y + img->h * img->zoom < win->h) img->y = win->h - h;
img->y = win->h - img->h * img->zoom;
} else {
img->y = (win->h - img->h * img->zoom) / 2;
}
if (!moved && (ox != img->x || oy != img->y)) if (!moved && (ox != img->x || oy != img->y))
img->dirty = true; img->dirty = true;
@ -450,19 +448,6 @@ void img_render(img_t *img)
win = img->win; win = img->win;
img_fit(img); img_fit(img);
if (!img->re) {
/* rendered for the first time */
img->re = true;
if (img->zoom * img->w <= win->w)
img->x = (win->w - img->w * img->zoom) / 2;
else
img->x = 0;
if (img->zoom * img->h <= win->h)
img->y = (win->h - img->h * img->zoom) / 2;
else
img->y = 0;
}
if (img->checkpan) { if (img->checkpan) {
img_check_pan(img, false); img_check_pan(img, false);
img->checkpan = false; img->checkpan = false;
@ -511,28 +496,18 @@ void img_render(img_t *img)
bool img_fit_win(img_t *img, scalemode_t sm) bool img_fit_win(img_t *img, scalemode_t sm)
{ {
if (img == NULL || img->im == NULL) float oz;
return false;
img->scalemode = sm;
return img_fit(img);
}
bool img_center(img_t *img)
{
int ox, oy;
if (img == NULL || img->im == NULL || img->win == NULL) if (img == NULL || img->im == NULL || img->win == NULL)
return false; return false;
ox = img->x;
oy = img->y;
img->x = (img->win->w - img->w * img->zoom) / 2; oz = img->zoom;
img->y = (img->win->h - img->h * img->zoom) / 2; img->scalemode = sm;
if (ox != img->x || oy != img->y) { if (img_fit(img)) {
img->dirty = true; img->x = img->win->w / 2 - (img->win->w / 2 - img->x) * img->zoom / oz;
img->y = img->win->h / 2 - (img->win->h / 2 - img->y) * img->zoom / oz;
img->checkpan = true;
return true; return true;
} else { } else {
return false; return false;

View File

@ -76,7 +76,6 @@ void img_close(img_t*, bool);
void img_render(img_t*); void img_render(img_t*);
bool img_fit_win(img_t*, scalemode_t); bool img_fit_win(img_t*, scalemode_t);
bool img_center(img_t*);
bool img_zoom(img_t*, float); bool img_zoom(img_t*, float);
bool img_zoom_in(img_t*); bool img_zoom_in(img_t*);