aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--thumbs.c11
-rw-r--r--thumbs.h2
3 files changed, 10 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 1a6c8a4..6743a29 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
all: sxiv
-VERSION=git-20110217
+VERSION=git-20110218
CC?=gcc
PREFIX?=/usr/local
diff --git a/thumbs.c b/thumbs.c
index 25a7fc1..2b77458 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -98,7 +98,9 @@ void tns_render(tns_t *tns, win_t *win) {
win_clear(win);
- x = y = 5;
+ i = 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 + i) * thumb_dim) / 2 + 5;
i = tns->first;
while (i < cnt) {
@@ -107,13 +109,14 @@ void tns_render(tns_t *tns, win_t *win) {
win_draw_pixmap(win, tns->thumbs[i].pm, tns->thumbs[i].x,
tns->thumbs[i].y, tns->thumbs[i].w, tns->thumbs[i].h);
if (++i % tns->cols == 0) {
- x = 5;
+ x = tns->x;
y += thumb_dim;
} else {
x += thumb_dim;
}
}
+ printf("%d, %d\n", tns->sel, tns->cnt);
tns_highlight(tns, win, -1);
}
@@ -175,10 +178,10 @@ int tns_translate(tns_t *tns, int x, int y) {
int n;
thumb_t *t;
- if (!tns || x < 5 || y < 5)
+ if (!tns || x < tns->x || y < tns->y)
return -1;
- if ((n = y / thumb_dim * tns-> cols + x / thumb_dim) < tns->cnt) {
+ if ((n = (y - tns->y) / thumb_dim * tns->cols + (x - tns->x) / thumb_dim) < tns->cnt) {
t = &tns->thumbs[n];
if (x > t->x && x < t->x + t->w && y > t->y && y < t->y + t->h)
return n;
diff --git a/thumbs.h b/thumbs.h
index 70d8b3c..157173d 100644
--- a/thumbs.h
+++ b/thumbs.h
@@ -39,6 +39,8 @@ typedef struct thumb_s {
typedef struct tns_s {
thumb_t *thumbs;
int cnt;
+ int x;
+ int y;
int cols;
int rows;
int first;