sxiv

simple X image viewer
git clone git://git.suckless.org/sxiv
Log | Files | Refs | LICENSE

commit 8fa7247f69e1d8528572c43d3815a62e6bcdb75f
parent c3c70a6c3ed34eb27019e44143202800094860c7
Author: Bert M√ľnnich <ber.t@posteo.de>
Date:   Mon, 29 Sep 2014 08:47:01 +0200

Refactored thumbnail size dependent calculations

Diffstat:
Makefile | 2+-
thumbs.c | 24+++++++++++++-----------
thumbs.h | 1+
3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -VERSION = git-20140928 +VERSION = git-20140929 PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man diff --git a/thumbs.c b/thumbs.c @@ -170,9 +170,11 @@ void tns_init(tns_t *tns, const fileinfo_t *files, int cnt, int *sel, win_t *win tns->loadnext = tns->first = tns->end = tns->r_first = tns->r_end = 0; tns->sel = sel; tns->win = win; - tns->zl = 1; tns->dirty = false; + tns->zl = 0; + tns_zoom(tns, 1); + if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') { homedir = getenv("HOME"); dsuffix = "/.cache"; @@ -392,7 +394,6 @@ void tns_render(tns_t *tns) thumb_t *t; win_t *win; int i, cnt, r, x, y; - int thumb_dim; if (tns == NULL || tns->thumbs == NULL || tns->win == NULL) return; @@ -403,9 +404,8 @@ void tns_render(tns_t *tns) win_clear(win); imlib_context_set_drawable(win->buf.pm); - thumb_dim = thumb_size[tns->zl] + 10; - tns->cols = MAX(1, win->w / thumb_dim); - tns->rows = MAX(1, win->h / thumb_dim); + tns->cols = MAX(1, win->w / tns->dim); + tns->rows = MAX(1, win->h / tns->dim); if (tns->cnt < tns->cols * tns->rows) { tns->first = 0; @@ -419,8 +419,8 @@ void tns_render(tns_t *tns) cnt -= r % tns->cols; } r = cnt % tns->cols ? 1 : 0; - tns->x = x = (win->w - MIN(cnt, tns->cols) * thumb_dim) / 2 + 5; - tns->y = y = (win->h - (cnt / tns->cols + r) * thumb_dim) / 2 + 5; + tns->x = x = (win->w - MIN(cnt, tns->cols) * tns->dim) / 2 + 5; + tns->y = y = (win->h - (cnt / tns->cols + r) * tns->dim) / 2 + 5; tns->loadnext = tns->cnt; tns->end = tns->first + cnt; @@ -445,9 +445,9 @@ void tns_render(tns_t *tns) } if ((i + 1) % tns->cols == 0) { x = tns->x; - y += thumb_dim; + y += tns->dim; } else { - x += thumb_dim; + x += tns->dim; } } tns->dirty = false; @@ -574,6 +574,8 @@ bool tns_zoom(tns_t *tns, int d) tns->zl = MAX(tns->zl, 0); tns->zl = MIN(tns->zl, ARRLEN(thumb_size)-1); + tns->dim = thumb_size[tns->zl] + 10; + if (tns->zl != oldzl) { for (i = 0; i < tns->cnt; i++) tns_unload(tns, i); @@ -591,8 +593,8 @@ int tns_translate(tns_t *tns, int x, int y) if (x < tns->x || y < tns->y) return -1; - n = tns->first + (y - tns->y) / (thumb_size[tns->zl] + 10) * tns->cols + - (x - tns->x) / (thumb_size[tns->zl] + 10); + n = tns->first + (y - tns->y) / tns->dim * tns->cols + + (x - tns->x) / tns->dim; if (n >= tns->cnt) n = -1; diff --git a/thumbs.h b/thumbs.h @@ -48,6 +48,7 @@ typedef struct { int cols; int rows; int zl; + int dim; bool dirty; } tns_t;