aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-02-03 16:55:24 +0100
committerBert <ber.t@gmx.com>2011-02-03 16:55:24 +0100
commit414fa567ce3893c33bc3a7b313b329c783853624 (patch)
tree92e1fde8f1cf6928bac085913534247fd2b90679
parentc6556f8cc7a90909b2dd71747ab605954a3f7892 (diff)
Split img_fit into internal/external function
-rw-r--r--image.c40
-rw-r--r--image.h2
-rw-r--r--main.c2
3 files changed, 25 insertions, 19 deletions
diff --git a/image.c b/image.c
index e83e479..1f27a40 100644
--- a/image.c
+++ b/image.c
@@ -99,7 +99,7 @@ int img_load(img_t *img, const char *filename) {
}
void img_check_pan(img_t *img, win_t *win) {
- if (!img)
+ if (!img || !win)
return;
if (img->w * img->zoom > win->w) {
@@ -120,6 +120,23 @@ void img_check_pan(img_t *img, win_t *win) {
}
}
+int img_fit(img_t *img, win_t *win) {
+ float oz, zw, zh;
+
+ if (!img || !win)
+ return 0;
+
+ oz = img->zoom;
+ zw = (float) win->w / (float) img->w;
+ zh = (float) win->h / (float) img->h;
+
+ img->zoom = MIN(zw, zh);
+ img->zoom = MAX(img->zoom, zoom_min);
+ img->zoom = MIN(img->zoom, zoom_max);
+
+ return oz != img->zoom;
+}
+
void img_render(img_t *img, win_t *win) {
int sx, sy, sw, sh;
int dx, dy, dw, dh;
@@ -128,7 +145,7 @@ void img_render(img_t *img, win_t *win) {
return;
if (img->scalemode != SCALE_ZOOM) {
- img_fit(img, win, 0);
+ img_fit(img, win);
if (img->scalemode == SCALE_DOWN && img->zoom > 1.0)
img->zoom = 1.0;
}
@@ -176,24 +193,12 @@ void img_render(img_t *img, win_t *win) {
win_draw(win);
}
-int img_fit(img_t *img, win_t *win, unsigned char set) {
- float oz, zw, zh;
-
+int img_fit_win(img_t *img, win_t *win) {
if (!img || !win)
return 0;
- oz = img->zoom;
- zw = (float) win->w / (float) img->w;
- zh = (float) win->h / (float) img->h;
-
- img->zoom = MIN(zw, zh);
- img->zoom = MAX(img->zoom, zoom_min);
- img->zoom = MIN(img->zoom, zoom_max);
-
- if (set)
- img->scalemode = SCALE_FIT;
-
- return oz != img->zoom;
+ img->scalemode = SCALE_FIT;
+ return img_fit(img, win);
}
int img_center(img_t *img, win_t *win) {
@@ -217,6 +222,7 @@ 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) {
diff --git a/image.h b/image.h
index 1c25f63..de4f3cc 100644
--- a/image.h
+++ b/image.h
@@ -54,7 +54,7 @@ int img_load(img_t*, const char*);
void img_render(img_t*, win_t*);
-int img_fit(img_t*, win_t*, unsigned char);
+int img_fit_win(img_t*, win_t*);
int img_center(img_t*, win_t*);
int img_zoom(img_t*, float);
diff --git a/main.c b/main.c
index 5a278b3..4970e60 100644
--- a/main.c
+++ b/main.c
@@ -288,7 +288,7 @@ void on_keypress(XKeyEvent *kev) {
changed = img_zoom(&img, 1.0);
break;
case XK_w:
- if ((changed = img_fit(&img, &win, 1)))
+ if ((changed = img_fit_win(&img, &win)))
img_center(&img, &win);
break;