Procházet zdrojové kódy

Center zoomed area

master
Bert před 13 roky
rodič
revize
ba293b09df
4 změnil soubory, kde provedl 19 přidání a 19 odebrání
  1. +1
    -1
      Makefile
  2. +10
    -10
      image.c
  3. +3
    -3
      image.h
  4. +5
    -5
      main.c

+ 1
- 1
Makefile Zobrazit soubor

@@ -1,6 +1,6 @@
all: sxiv

VERSION=git-20110415
VERSION=git-20110419

CC?=gcc
PREFIX?=/usr/local


+ 10
- 10
image.c Zobrazit soubor

@@ -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;
}


+ 3
- 3
image.h Zobrazit soubor

@@ -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);


+ 5
- 5
main.c Zobrazit soubor

@@ -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


Načítá se…
Zrušit
Uložit