summaryrefslogtreecommitdiffstats
path: root/thumbs.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-02-20 00:08:17 +0100
committerBert <ber.t@gmx.com>2011-02-20 00:08:17 +0100
commita30901210cfde971bac780b5c0bbdeda215ea809 (patch)
tree432ec101e77791c0ee9f61fb91a05b6630a47e47 /thumbs.c
parent4cc6ca939c1e111aa491d5c81ee63170eee00fbd (diff)
downloadnsxiv-a30901210cfde971bac780b5c0bbdeda215ea809.tar.zst
Mouse-wheel scrolling in thumb mode
Diffstat (limited to 'thumbs.c')
-rw-r--r--thumbs.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/thumbs.c b/thumbs.c
index 3de9518..aea40ee 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -88,21 +88,27 @@ void tns_load(tns_t *tns, win_t *win, const char *filename) {
}
void tns_check_view(tns_t *tns, Bool scrolled) {
+ int r;
+
if (!tns)
return;
tns->first -= tns->first % tns->cols;
+ r = fileidx % tns->cols;
if (scrolled) {
/* move selection into visible area */
+ if (fileidx >= tns->first + tns->cols * tns->rows)
+ fileidx = tns->first + r + tns->cols * (tns->rows - 1);
+ else if (fileidx < tns->first)
+ fileidx = tns->first + r;
} else {
/* scroll to selection */
if (tns->first + tns->cols * tns->rows <= fileidx) {
- tns->first = fileidx - fileidx % tns->cols -
- tns->cols * (tns->rows - 1);
+ tns->first = fileidx - r - tns->cols * (tns->rows - 1);
tns->dirty = 1;
} else if (tns->first > fileidx) {
- tns->first = fileidx - fileidx % tns->cols;
+ tns->first = fileidx - r;
tns->dirty = 1;
}
}
@@ -167,7 +173,7 @@ void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) {
win_draw(win);
}
-int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
+int tns_move_selection(tns_t *tns, win_t *win, tnsdir_t dir) {
int old;
if (!tns || !win)
@@ -176,19 +182,19 @@ int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
old = fileidx;
switch (dir) {
- case MOVE_LEFT:
+ case TNS_LEFT:
if (fileidx > 0)
--fileidx;
break;
- case MOVE_RIGHT:
+ case TNS_RIGHT:
if (fileidx < tns->cnt - 1)
++fileidx;
break;
- case MOVE_UP:
+ case TNS_UP:
if (fileidx >= tns->cols)
fileidx -= tns->cols;
break;
- case MOVE_DOWN:
+ case TNS_DOWN:
if (fileidx + tns->cols < tns->cnt)
fileidx += tns->cols;
break;
@@ -204,6 +210,28 @@ int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
return fileidx != old;
}
+int tns_scroll(tns_t *tns, tnsdir_t dir) {
+ int old;
+
+ if (!tns)
+ return 0;
+
+ old = tns->first;
+
+ if (dir == TNS_DOWN && tns->first + tns->cols * tns->rows < tns->cnt)
+ tns->first += tns->cols;
+ else if (dir == TNS_UP && tns->first >= tns->cols)
+ tns->first -= tns->cols;
+
+ if (tns->first != old) {
+ tns_check_view(tns, True);
+ tns->dirty = 1;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
int tns_translate(tns_t *tns, int x, int y) {
int n;
thumb_t *t;