Select and open thumbnails

This commit is contained in:
Bert 2011-02-17 16:57:55 +01:00
parent ef24ded6af
commit f08c24bbb3
3 changed files with 78 additions and 2 deletions

32
main.c
View file

@ -268,7 +268,7 @@ void redraw() {
} }
void on_keypress(XKeyEvent *kev) { void on_keypress(XKeyEvent *kev) {
int x, y; int sel, x, y;
unsigned int w, h; unsigned int w, h;
char key; char key;
KeySym ksym; KeySym ksym;
@ -388,6 +388,36 @@ void on_keypress(XKeyEvent *kev) {
break; break;
} }
} else { } else {
/* thumbnail mode */
sel = tns.sel;
switch (ksym) {
/* open selected image */
case XK_Return:
fileidx = sel;
load_image();
mode = MODE_NORMAL;
changed = 1;
break;
/* move selection */
case XK_h:
case XK_Left:
tns_move_selection(&tns, &win, MOVE_LEFT);
break;
case XK_j:
case XK_Down:
tns_move_selection(&tns, &win, MOVE_DOWN);
break;
case XK_k:
case XK_Up:
tns_move_selection(&tns, &win, MOVE_UP);
break;
case XK_l:
case XK_Right:
tns_move_selection(&tns, &win, MOVE_RIGHT);
break;
}
} }
/* common key mappings */ /* common key mappings */

View file

@ -115,7 +115,6 @@ void tns_render(tns_t *tns, win_t *win) {
} }
tns_highlight(tns, win, -1); tns_highlight(tns, win, -1);
win_draw(win);
} }
void tns_highlight(tns_t *tns, win_t *win, int old) { 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) {
t = &tns->thumbs[tns->sel]; t = &tns->thumbs[tns->sel];
win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, True); win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, True);
} }
win_draw(win);
}
void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
int sel;
if (!tns || !win)
return;
sel = tns->sel;
switch (dir) {
case MOVE_LEFT:
if (sel % tns->cols > 0) {
--tns->sel;
tns_highlight(tns, win, sel);
}
break;
case MOVE_RIGHT:
if (sel % tns->cols < tns->cols - 1 && sel < tns->cnt - 1) {
++tns->sel;
tns_highlight(tns, win, sel);
}
break;
case MOVE_UP:
if (sel / tns->cols > 0) {
tns->sel -= tns->cols;
tns_highlight(tns, win, sel);
}
break;
case MOVE_DOWN:
if (sel / tns->cols < tns->rows - 1 && sel + tns->cols < tns->cnt) {
tns->sel += tns->cols;
tns_highlight(tns, win, sel);
}
break;
}
} }

View file

@ -21,6 +21,13 @@
#include "window.h" #include "window.h"
typedef enum movedir_e {
MOVE_LEFT = 0,
MOVE_RIGHT,
MOVE_UP,
MOVE_DOWN
} movedir_t;
typedef struct thumb_s { typedef struct thumb_s {
Pixmap pm; Pixmap pm;
int x; int x;
@ -48,4 +55,6 @@ void tns_load(tns_t*, win_t*, const char*);
void tns_render(tns_t*, win_t*); void tns_render(tns_t*, win_t*);
void tns_highlight(tns_t*, win_t*, int); void tns_highlight(tns_t*, win_t*, int);
void tns_move_selection(tns_t*, win_t*, movedir_t);
#endif /* THUMBS_H */ #endif /* THUMBS_H */