Procházet zdrojové kódy

Select and open thumbnails

master
Bert před 14 roky
rodič
revize
f08c24bbb3
3 změnil soubory, kde provedl 78 přidání a 2 odebrání
  1. +31
    -1
      main.c
  2. +38
    -1
      thumbs.c
  3. +9
    -0
      thumbs.h

+ 31
- 1
main.c Zobrazit soubor

@@ -268,7 +268,7 @@ void redraw() {
}

void on_keypress(XKeyEvent *kev) {
int x, y;
int sel, x, y;
unsigned int w, h;
char key;
KeySym ksym;
@@ -388,6 +388,36 @@ void on_keypress(XKeyEvent *kev) {
break;
}
} 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 */


+ 38
- 1
thumbs.c Zobrazit soubor

@@ -115,7 +115,6 @@ void tns_render(tns_t *tns, win_t *win) {
}

tns_highlight(tns, win, -1);
win_draw(win);
}

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];
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;
}
}

+ 9
- 0
thumbs.h Zobrazit soubor

@@ -21,6 +21,13 @@

#include "window.h"

typedef enum movedir_e {
MOVE_LEFT = 0,
MOVE_RIGHT,
MOVE_UP,
MOVE_DOWN
} movedir_t;

typedef struct thumb_s {
Pixmap pm;
int x;
@@ -48,4 +55,6 @@ void tns_load(tns_t*, win_t*, const char*);
void tns_render(tns_t*, win_t*);
void tns_highlight(tns_t*, win_t*, int);

void tns_move_selection(tns_t*, win_t*, movedir_t);

#endif /* THUMBS_H */

Načítá se…
Zrušit
Uložit