aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--image.c15
-rw-r--r--image.h5
-rw-r--r--main.c7
3 files changed, 19 insertions, 8 deletions
diff --git a/image.c b/image.c
index c7e9e3a..e83e479 100644
--- a/image.c
+++ b/image.c
@@ -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;
diff --git a/image.h b/image.h
index e422384..1c25f63 100644
--- a/image.h
+++ b/image.h
@@ -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*);
diff --git a/main.c b/main.c
index e618288..5a278b3 100644
--- a/main.c
+++ b/main.c
@@ -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: