Krolyxon
Commit f08c24b

Branches

Refs →

nsxivf08c24b

Select and open thumbnails

Author
Bert
Date
2011-02-17 16:57 +0100
Parent
ef24ded
Commit
f08c24bbb31ae0e3f7001d5d4d0e8f31b0c817f8

+78 −2

3 files changed

  1. M main.c +31 −1
  2. M thumbs.c +38 −1
  3. M thumbs.h +9 −0
M main.c View
@@ -268,7 +268,7 @@ void redraw() {
268268 }
269269
270270 void on_keypress(XKeyEvent *kev) {
271− int x, y;
271+ int sel, x, y;
272272 unsigned int w, h;
273273 char key;
274274 KeySym ksym;
@@ -388,6 +388,36 @@ void on_keypress(XKeyEvent *kev) {
388388 break;
389389 }
390390 } else {
391+ /* thumbnail mode */
392+ sel = tns.sel;
393+
394+ switch (ksym) {
395+ /* open selected image */
396+ case XK_Return:
397+ fileidx = sel;
398+ load_image();
399+ mode = MODE_NORMAL;
400+ changed = 1;
401+ break;
402+
403+ /* move selection */
404+ case XK_h:
405+ case XK_Left:
406+ tns_move_selection(&tns, &win, MOVE_LEFT);
407+ break;
408+ case XK_j:
409+ case XK_Down:
410+ tns_move_selection(&tns, &win, MOVE_DOWN);
411+ break;
412+ case XK_k:
413+ case XK_Up:
414+ tns_move_selection(&tns, &win, MOVE_UP);
415+ break;
416+ case XK_l:
417+ case XK_Right:
418+ tns_move_selection(&tns, &win, MOVE_RIGHT);
419+ break;
420+ }
391421 }
392422
393423 /* common key mappings */
M thumbs.c View
@@ -115,7 +115,6 @@ void tns_render(tns_t *tns, win_t *win) {
115115 }
116116
117117 tns_highlight(tns, win, -1);
118− win_draw(win);
119118 }
120119
121120 void tns_highlight(tns_t *tns, win_t *win, int old) {
@@ -132,4 +131,42 @@ void tns_highlight(tns_t *tns, win_t *win, int old) {
132131 t = &tns->thumbs[tns->sel];
133132 win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, True);
134133 }
134+
135+ win_draw(win);
136+}
137+
138+void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
139+ int sel;
140+
141+ if (!tns || !win)
142+ return;
143+
144+ sel = tns->sel;
145+
146+ switch (dir) {
147+ case MOVE_LEFT:
148+ if (sel % tns->cols > 0) {
149+ --tns->sel;
150+ tns_highlight(tns, win, sel);
151+ }
152+ break;
153+ case MOVE_RIGHT:
154+ if (sel % tns->cols < tns->cols - 1 && sel < tns->cnt - 1) {
155+ ++tns->sel;
156+ tns_highlight(tns, win, sel);
157+ }
158+ break;
159+ case MOVE_UP:
160+ if (sel / tns->cols > 0) {
161+ tns->sel -= tns->cols;
162+ tns_highlight(tns, win, sel);
163+ }
164+ break;
165+ case MOVE_DOWN:
166+ if (sel / tns->cols < tns->rows - 1 && sel + tns->cols < tns->cnt) {
167+ tns->sel += tns->cols;
168+ tns_highlight(tns, win, sel);
169+ }
170+ break;
171+ }
135172 }
M thumbs.h View
@@ -21,6 +21,13 @@
2121
2222 #include "window.h"
2323
24+typedef enum movedir_e {
25+ MOVE_LEFT = 0,
26+ MOVE_RIGHT,
27+ MOVE_UP,
28+ MOVE_DOWN
29+} movedir_t;
30+
2431 typedef struct thumb_s {
2532 Pixmap pm;
2633 int x;
@@ -48,4 +55,6 @@ void tns_load(tns_t*, win_t*, const char*);
4855 void tns_render(tns_t*, win_t*);
4956 void tns_highlight(tns_t*, win_t*, int);
5057
58+void tns_move_selection(tns_t*, win_t*, movedir_t);
59+
5160 #endif /* THUMBS_H */