aboutsummaryrefslogtreecommitdiffstats
path: root/image.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-01-21 12:13:52 +0100
committerBert <ber.t@gmx.com>2011-01-21 12:13:52 +0100
commit629d37376d1c9b175a525e8c30f8d468996a3bd6 (patch)
tree7df76a1b9a505ac2a87bb788928bc12e03a0a981 /image.c
parent44921e07aaa36d553f2a4c81d7c431388b5c27e3 (diff)
downloadnsxiv-629d37376d1c9b175a525e8c30f8d468996a3bd6.tar.zst
Merged img_display() into img_render()
Diffstat (limited to 'image.c')
-rw-r--r--image.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/image.c b/image.c
index 688e83e..b6c10bf 100644
--- a/image.c
+++ b/image.c
@@ -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;