New key mappings: 0/w, zoom to 100%/to fit window

This commit is contained in:
Bert 2011-02-03 16:14:49 +01:00
parent bad9a70a48
commit c6556f8cc7
3 changed files with 19 additions and 8 deletions

15
image.c
View File

@ -88,9 +88,9 @@ int img_load(img_t *img, const char *filename) {
imlib_context_set_anti_alias(img->aa);
img->scalemode = options->scalemode;
img->re = 0;
img->checkpan = 0;
img->zoomed = 0;
img->w = imlib_image_get_width();
img->h = imlib_image_get_height();
@ -127,9 +127,9 @@ void img_render(img_t *img, win_t *win) {
if (!img || !win || !imlib_context_get_image())
return;
if (!img->zoomed && options->scalemode != SCALE_ZOOM) {
img_fit(img, win);
if (options->scalemode == SCALE_DOWN && img->zoom > 1.0)
if (img->scalemode != SCALE_ZOOM) {
img_fit(img, win, 0);
if (img->scalemode == SCALE_DOWN && img->zoom > 1.0)
img->zoom = 1.0;
}
@ -176,7 +176,7 @@ void img_render(img_t *img, win_t *win) {
win_draw(win);
}
int img_fit(img_t *img, win_t *win) {
int img_fit(img_t *img, win_t *win, unsigned char set) {
float oz, zw, zh;
if (!img || !win)
@ -190,6 +190,9 @@ int img_fit(img_t *img, win_t *win) {
img->zoom = MAX(img->zoom, zoom_min);
img->zoom = MIN(img->zoom, zoom_max);
if (set)
img->scalemode = SCALE_FIT;
return oz != img->zoom;
}
@ -214,13 +217,13 @@ int img_zoom(img_t *img, float z) {
z = MAX(z, zoom_min);
z = MIN(z, zoom_max);
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->zoom = z;
img->checkpan = 1;
img->zoomed = 1;
return 1;
} else {
return 0;

View File

@ -36,9 +36,9 @@ typedef enum pandir_e {
typedef struct img_s {
float zoom;
scalemode_t scalemode;
unsigned char re;
unsigned char checkpan;
unsigned char zoomed;
unsigned char aa;
int x;
int y;
@ -54,9 +54,10 @@ int img_load(img_t*, const char*);
void img_render(img_t*, win_t*);
int img_fit(img_t*, win_t*);
int img_fit(img_t*, win_t*, unsigned char);
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*);

7
main.c
View File

@ -284,6 +284,13 @@ void on_keypress(XKeyEvent *kev) {
case XK_minus:
changed = img_zoom_out(&img);
break;
case XK_0:
changed = img_zoom(&img, 1.0);
break;
case XK_w:
if ((changed = img_fit(&img, &win, 1)))
img_center(&img, &win);
break;
/* panning */
case XK_h: