Refactored thumbnail size dependent calculations

This commit is contained in:
Bert Münnich 2014-09-29 08:47:01 +02:00
parent c3c70a6c3e
commit 8fa7247f69
3 changed files with 15 additions and 12 deletions

View file

@ -1,4 +1,4 @@
VERSION = git-20140928 VERSION = git-20140929
PREFIX = /usr/local PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man MANPREFIX = $(PREFIX)/share/man

View file

@ -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->loadnext = tns->first = tns->end = tns->r_first = tns->r_end = 0;
tns->sel = sel; tns->sel = sel;
tns->win = win; tns->win = win;
tns->zl = 1;
tns->dirty = false; tns->dirty = false;
tns->zl = 0;
tns_zoom(tns, 1);
if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') { if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') {
homedir = getenv("HOME"); homedir = getenv("HOME");
dsuffix = "/.cache"; dsuffix = "/.cache";
@ -392,7 +394,6 @@ void tns_render(tns_t *tns)
thumb_t *t; thumb_t *t;
win_t *win; win_t *win;
int i, cnt, r, x, y; int i, cnt, r, x, y;
int thumb_dim;
if (tns == NULL || tns->thumbs == NULL || tns->win == NULL) if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
return; return;
@ -403,9 +404,8 @@ void tns_render(tns_t *tns)
win_clear(win); win_clear(win);
imlib_context_set_drawable(win->buf.pm); imlib_context_set_drawable(win->buf.pm);
thumb_dim = thumb_size[tns->zl] + 10; tns->cols = MAX(1, win->w / tns->dim);
tns->cols = MAX(1, win->w / thumb_dim); tns->rows = MAX(1, win->h / tns->dim);
tns->rows = MAX(1, win->h / thumb_dim);
if (tns->cnt < tns->cols * tns->rows) { if (tns->cnt < tns->cols * tns->rows) {
tns->first = 0; tns->first = 0;
@ -419,8 +419,8 @@ void tns_render(tns_t *tns)
cnt -= r % tns->cols; cnt -= r % tns->cols;
} }
r = cnt % tns->cols ? 1 : 0; r = cnt % tns->cols ? 1 : 0;
tns->x = x = (win->w - MIN(cnt, tns->cols) * 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) * thumb_dim) / 2 + 5; tns->y = y = (win->h - (cnt / tns->cols + r) * tns->dim) / 2 + 5;
tns->loadnext = tns->cnt; tns->loadnext = tns->cnt;
tns->end = tns->first + cnt; tns->end = tns->first + cnt;
@ -445,9 +445,9 @@ void tns_render(tns_t *tns)
} }
if ((i + 1) % tns->cols == 0) { if ((i + 1) % tns->cols == 0) {
x = tns->x; x = tns->x;
y += thumb_dim; y += tns->dim;
} else { } else {
x += thumb_dim; x += tns->dim;
} }
} }
tns->dirty = false; tns->dirty = false;
@ -574,6 +574,8 @@ bool tns_zoom(tns_t *tns, int d)
tns->zl = MAX(tns->zl, 0); tns->zl = MAX(tns->zl, 0);
tns->zl = MIN(tns->zl, ARRLEN(thumb_size)-1); tns->zl = MIN(tns->zl, ARRLEN(thumb_size)-1);
tns->dim = thumb_size[tns->zl] + 10;
if (tns->zl != oldzl) { if (tns->zl != oldzl) {
for (i = 0; i < tns->cnt; i++) for (i = 0; i < tns->cnt; i++)
tns_unload(tns, 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) if (x < tns->x || y < tns->y)
return -1; return -1;
n = tns->first + (y - tns->y) / (thumb_size[tns->zl] + 10) * tns->cols + n = tns->first + (y - tns->y) / tns->dim * tns->cols +
(x - tns->x) / (thumb_size[tns->zl] + 10); (x - tns->x) / tns->dim;
if (n >= tns->cnt) if (n >= tns->cnt)
n = -1; n = -1;

View file

@ -48,6 +48,7 @@ typedef struct {
int cols; int cols;
int rows; int rows;
int zl; int zl;
int dim;
bool dirty; bool dirty;
} tns_t; } tns_t;