diff options
author | Bert <ber.t@gmx.com> | 2011-01-21 12:13:52 +0100 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-01-21 12:13:52 +0100 |
commit | 629d37376d1c9b175a525e8c30f8d468996a3bd6 (patch) | |
tree | 7df76a1b9a505ac2a87bb788928bc12e03a0a981 | |
parent | 44921e07aaa36d553f2a4c81d7c431388b5c27e3 (diff) |
Merged img_display() into img_render()
-rw-r--r-- | image.c | 57 | ||||
-rw-r--r-- | image.h | 2 | ||||
-rw-r--r-- | main.c | 6 |
3 files changed, 32 insertions, 33 deletions
@@ -62,40 +62,13 @@ int img_load(img_t *img, const char *filename) { imlib_context_set_image(im); + img->re = 0; img->w = imlib_image_get_width(); img->h = imlib_image_get_height(); return 0; } -void img_display(img_t *img, win_t *win) { - float zw, zh; - - if (!img || !win || !imlib_context_get_image()) - return; - - /* set zoom level to fit image into window */ - if (img->scalemode != SCALE_ZOOM) { - zw = (float) win->w / (float) img->w; - zh = (float) win->h / (float) img->h; - img->zoom = MIN(zw, zh); - - if (img->zoom < zoom_min) - img->zoom = zoom_min; - else if (img->zoom > zoom_max) - img->zoom = zoom_max; - - if (img->scalemode == SCALE_DOWN && img->zoom > 1.0) - img->zoom = 1.0; - } - - /* center image in window */ - img->x = (win->w - img->w * img->zoom) / 2; - img->y = (win->h - img->h * img->zoom) / 2; - - img_render(img, win); -} - void img_check_pan(img_t *img, win_t *win) { if (!img) return; @@ -121,11 +94,37 @@ void img_check_pan(img_t *img, win_t *win) { void img_render(img_t *img, win_t *win) { int sx, sy, sw, sh; int dx, dy, dw, dh; + float zw, zh; if (!img || !win || !imlib_context_get_image()) return; - img_check_pan(img, win); + if (!img->re) { + /* rendered for the first time */ + img->re = 1; + + /* set zoom level to fit image into window */ + if (img->scalemode != SCALE_ZOOM) { + zw = (float) win->w / (float) img->w; + zh = (float) win->h / (float) img->h; + img->zoom = MIN(zw, zh); + + if (img->zoom < zoom_min) + img->zoom = zoom_min; + else if (img->zoom > zoom_max) + img->zoom = zoom_max; + + if (img->scalemode == SCALE_DOWN && img->zoom > 1.0) + img->zoom = 1.0; + } + + /* center image in window */ + img->x = (win->w - img->w * img->zoom) / 2; + img->y = (win->h - img->h * img->zoom) / 2; + } else { + /* typically after zooming and panning */ + img_check_pan(img, win); + } if (img->x < 0) { sx = -img->x / img->zoom; @@ -30,6 +30,7 @@ typedef enum scalemode_e { typedef struct img_s { float zoom; scalemode_t scalemode; + unsigned char re; int x; int y; int w; @@ -40,7 +41,6 @@ void imlib_init(win_t*); void imlib_destroy(); int img_load(img_t*, const char*); -void img_display(img_t*, win_t*); void img_render(img_t*, win_t*); int img_zoom_in(img_t*); @@ -93,7 +93,7 @@ int main(int argc, char **argv) { imlib_init(&win); img_load(&img, filenames[fileidx]); - img_display(&img, &win); + img_render(&img, &win); update_title(); run(); @@ -146,14 +146,14 @@ void on_keypress(XEvent *ev) { case 'n': if (fileidx + 1 < filecnt) { img_load(&img, filenames[++fileidx]); - img_display(&img, &win); + img_render(&img, &win); update_title(); } break; case 'p': if (fileidx > 0) { img_load(&img, filenames[--fileidx]); - img_display(&img, &win); + img_render(&img, &win); update_title(); } break; |