Highlight selected thumbnail
This commit is contained in:
parent
095217b26f
commit
ef24ded6af
2
config.h
2
config.h
@ -6,6 +6,8 @@
|
||||
/* default color to use for window background: *
|
||||
* (see X(7) "COLOR NAMES" section for valid values) */
|
||||
#define BG_COLOR "#999999"
|
||||
/* default color to use for selections: */
|
||||
#define SEL_COLOR "#0000BB"
|
||||
|
||||
/* how should images be scaled when they are loaded?: *
|
||||
* (also controllable via -d/-s/-Z/-z options) *
|
||||
|
20
thumbs.c
20
thumbs.c
@ -88,8 +88,8 @@ void tns_render(tns_t *tns, win_t *win) {
|
||||
if (!tns || !win)
|
||||
return;
|
||||
|
||||
tns->cols = win->w / thumb_dim;
|
||||
tns->rows = win->h / thumb_dim;
|
||||
tns->cols = MAX(1, win->w / thumb_dim);
|
||||
tns->rows = MAX(1, win->h / thumb_dim);
|
||||
|
||||
cnt = tns->cols * tns->rows;
|
||||
if (tns->first && tns->first + cnt > tns->cnt)
|
||||
@ -114,6 +114,22 @@ 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) {
|
||||
thumb_t *t;
|
||||
|
||||
if (!tns || !win)
|
||||
return;
|
||||
|
||||
if (old >= 0 && old < tns->cnt) {
|
||||
t = &tns->thumbs[old];
|
||||
win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, False);
|
||||
}
|
||||
if (tns->sel < tns->cnt) {
|
||||
t = &tns->thumbs[tns->sel];
|
||||
win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, True);
|
||||
}
|
||||
}
|
||||
|
1
thumbs.h
1
thumbs.h
@ -46,5 +46,6 @@ void tns_free(tns_t*, win_t*);
|
||||
void tns_load(tns_t*, win_t*, const char*);
|
||||
|
||||
void tns_render(tns_t*, win_t*);
|
||||
void tns_highlight(tns_t*, win_t*, int);
|
||||
|
||||
#endif /* THUMBS_H */
|
||||
|
59
window.c
59
window.c
@ -29,7 +29,7 @@
|
||||
static Cursor carrow;
|
||||
static Cursor chand;
|
||||
static Cursor cwatch;
|
||||
static GC bgc;
|
||||
static GC gc;
|
||||
|
||||
Atom wm_delete_win;
|
||||
|
||||
@ -50,7 +50,8 @@ void win_set_sizehints(win_t *win) {
|
||||
void win_open(win_t *win) {
|
||||
win_env_t *e;
|
||||
XClassHint classhint;
|
||||
XColor bgcol;
|
||||
XColor col;
|
||||
XGCValues gcval;
|
||||
int gmask;
|
||||
|
||||
if (!win)
|
||||
@ -67,13 +68,18 @@ void win_open(win_t *win) {
|
||||
e->cmap = DefaultColormap(e->dpy, e->scr);
|
||||
e->depth = DefaultDepth(e->dpy, e->scr);
|
||||
|
||||
if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
|
||||
&bgcol, &bgcol))
|
||||
if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
|
||||
&col, &col))
|
||||
win->bgcol = col.pixel;
|
||||
else
|
||||
die("could not allocate color: %s", BG_COLOR);
|
||||
if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), SEL_COLOR,
|
||||
&col, &col))
|
||||
win->selcol = col.pixel;
|
||||
else
|
||||
die("could not allocate color: %s", BG_COLOR);
|
||||
|
||||
win->bgcol = bgcol.pixel;
|
||||
win->pm = 0;
|
||||
|
||||
win->fullscreen = 0;
|
||||
|
||||
/* determine window offsets, width & height */
|
||||
@ -112,7 +118,8 @@ void win_open(win_t *win) {
|
||||
chand = XCreateFontCursor(e->dpy, XC_fleur);
|
||||
cwatch = XCreateFontCursor(e->dpy, XC_watch);
|
||||
|
||||
bgc = XCreateGC(e->dpy, win->xwin, 0, None);
|
||||
gcval.line_width = 2;
|
||||
gc = XCreateGC(e->dpy, win->xwin, GCLineWidth, &gcval);
|
||||
|
||||
win_set_title(win, "sxiv");
|
||||
|
||||
@ -141,7 +148,7 @@ void win_close(win_t *win) {
|
||||
XFreeCursor(win->env.dpy, chand);
|
||||
XFreeCursor(win->env.dpy, cwatch);
|
||||
|
||||
XFreeGC(win->env.dpy, bgc);
|
||||
XFreeGC(win->env.dpy, gc);
|
||||
|
||||
XDestroyWindow(win->env.dpy, win->xwin);
|
||||
XCloseDisplay(win->env.dpy);
|
||||
@ -226,11 +233,6 @@ void win_free_pixmap(win_t *win, Pixmap pm) {
|
||||
XFreePixmap(win->env.dpy, pm);
|
||||
}
|
||||
|
||||
void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
|
||||
if (win)
|
||||
XCopyArea(win->env.dpy, pm, win->pm, bgc, 0, 0, w, h, x, y);
|
||||
}
|
||||
|
||||
void win_clear(win_t *win) {
|
||||
win_env_t *e;
|
||||
XGCValues gcval;
|
||||
@ -239,14 +241,37 @@ void win_clear(win_t *win) {
|
||||
return;
|
||||
|
||||
e = &win->env;
|
||||
gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : win->bgcol;
|
||||
|
||||
gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
|
||||
win->bgcol;
|
||||
if (win->pm)
|
||||
XFreePixmap(e->dpy, win->pm);
|
||||
win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
|
||||
|
||||
XChangeGC(e->dpy, bgc, GCForeground, &gcval);
|
||||
XFillRectangle(e->dpy, win->pm, bgc, 0, 0, e->scrw, e->scrh);
|
||||
XChangeGC(e->dpy, gc, GCForeground, &gcval);
|
||||
XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh);
|
||||
}
|
||||
|
||||
void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
|
||||
if (win)
|
||||
XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y);
|
||||
}
|
||||
|
||||
void win_draw_rect(win_t *win, int x, int y, int w, int h, Bool sel) {
|
||||
win_env_t *e;
|
||||
XGCValues gcval;
|
||||
|
||||
if (!win)
|
||||
return;
|
||||
|
||||
e = &win->env;
|
||||
|
||||
if (sel)
|
||||
gcval.foreground = win->selcol;
|
||||
else
|
||||
gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
|
||||
win->bgcol;
|
||||
XChangeGC(e->dpy, gc, GCForeground, &gcval);
|
||||
XDrawRectangle(e->dpy, win->pm, gc, x, y, w, h);
|
||||
}
|
||||
|
||||
void win_draw(win_t *win) {
|
||||
|
4
window.h
4
window.h
@ -43,6 +43,7 @@ typedef struct win_s {
|
||||
win_env_t env;
|
||||
|
||||
unsigned long bgcol;
|
||||
unsigned long selcol;
|
||||
Pixmap pm;
|
||||
|
||||
int x;
|
||||
@ -66,9 +67,10 @@ void win_toggle_fullscreen(win_t*);
|
||||
|
||||
Pixmap win_create_pixmap(win_t*, int, int);
|
||||
void win_free_pixmap(win_t*, Pixmap);
|
||||
void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
|
||||
|
||||
void win_clear(win_t*);
|
||||
void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
|
||||
void win_draw_rect(win_t*, int, int, int, int, Bool);
|
||||
void win_draw(win_t*);
|
||||
|
||||
void win_set_title(win_t*, const char*);
|
||||
|
Loading…
Reference in New Issue
Block a user