Krolyxon
Commit 8fa7247

Branches

Refs →

nsxiv8fa7247

Refactored thumbnail size dependent calculations

Author
Bert Münnich
Date
2014-09-29 08:47 +0200
Parent
c3c70a6
Commit
8fa7247f69e1d8528572c43d3815a62e6bcdb75f

+15 −12

3 files changed

  1. M Makefile +1 −1
  2. M thumbs.c +13 −11
  3. M thumbs.h +1 −0
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140928
1+VERSION = git-20140929
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M thumbs.c View
@@ -170,9 +170,11 @@ void tns_init(tns_t *tns, const fileinfo_t *files, int cnt, int *sel, win_t *win
170170 tns->loadnext = tns->first = tns->end = tns->r_first = tns->r_end = 0;
171171 tns->sel = sel;
172172 tns->win = win;
173− tns->zl = 1;
174173 tns->dirty = false;
175174
175+ tns->zl = 0;
176+ tns_zoom(tns, 1);
177+
176178 if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') {
177179 homedir = getenv("HOME");
178180 dsuffix = "/.cache";
@@ -392,7 +394,6 @@ void tns_render(tns_t *tns)
392394 thumb_t *t;
393395 win_t *win;
394396 int i, cnt, r, x, y;
395− int thumb_dim;
396397
397398 if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
398399 return;
@@ -403,9 +404,8 @@ void tns_render(tns_t *tns)
403404 win_clear(win);
404405 imlib_context_set_drawable(win->buf.pm);
405406
406− thumb_dim = thumb_size[tns->zl] + 10;
407− tns->cols = MAX(1, win->w / thumb_dim);
408− tns->rows = MAX(1, win->h / thumb_dim);
407+ tns->cols = MAX(1, win->w / tns->dim);
408+ tns->rows = MAX(1, win->h / tns->dim);
409409
410410 if (tns->cnt < tns->cols * tns->rows) {
411411 tns->first = 0;
@@ -419,8 +419,8 @@ void tns_render(tns_t *tns)
419419 cnt -= r % tns->cols;
420420 }
421421 r = cnt % tns->cols ? 1 : 0;
422− tns->x = x = (win->w - MIN(cnt, tns->cols) * thumb_dim) / 2 + 5;
423− tns->y = y = (win->h - (cnt / tns->cols + r) * thumb_dim) / 2 + 5;
422+ tns->x = x = (win->w - MIN(cnt, tns->cols) * tns->dim) / 2 + 5;
423+ tns->y = y = (win->h - (cnt / tns->cols + r) * tns->dim) / 2 + 5;
424424 tns->loadnext = tns->cnt;
425425 tns->end = tns->first + cnt;
426426
@@ -445,9 +445,9 @@ void tns_render(tns_t *tns)
445445 }
446446 if ((i + 1) % tns->cols == 0) {
447447 x = tns->x;
448− y += thumb_dim;
448+ y += tns->dim;
449449 } else {
450− x += thumb_dim;
450+ x += tns->dim;
451451 }
452452 }
453453 tns->dirty = false;
@@ -574,6 +574,8 @@ bool tns_zoom(tns_t *tns, int d)
574574 tns->zl = MAX(tns->zl, 0);
575575 tns->zl = MIN(tns->zl, ARRLEN(thumb_size)-1);
576576
577+ tns->dim = thumb_size[tns->zl] + 10;
578+
577579 if (tns->zl != oldzl) {
578580 for (i = 0; i < tns->cnt; i++)
579581 tns_unload(tns, i);
@@ -591,8 +593,8 @@ int tns_translate(tns_t *tns, int x, int y)
591593 if (x < tns->x || y < tns->y)
592594 return -1;
593595
594− n = tns->first + (y - tns->y) / (thumb_size[tns->zl] + 10) * tns->cols +
595− (x - tns->x) / (thumb_size[tns->zl] + 10);
596+ n = tns->first + (y - tns->y) / tns->dim * tns->cols +
597+ (x - tns->x) / tns->dim;
596598 if (n >= tns->cnt)
597599 n = -1;
598600
M thumbs.h View
@@ -48,6 +48,7 @@ typedef struct {
4848 int cols;
4949 int rows;
5050 int zl;
51+ int dim;
5152
5253 bool dirty;
5354 } tns_t;