Krolyxon
Commit ef24ded

Branches

Refs →

nsxivef24ded

Highlight selected thumbnail

Author
Bert
Date
2011-02-17 16:22 +0100
Parent
095217b
Commit
ef24ded6afeb185192e815868c28a31c4c2e6d97

+66 −20

5 files changed

  1. M config.h +2 −0
  2. M thumbs.c +18 −2
  3. M thumbs.h +1 −0
  4. M window.c +42 −17
  5. M window.h +3 −1
M config.h View
@@ -6,6 +6,8 @@
66 /* default color to use for window background: *
77 * (see X(7) "COLOR NAMES" section for valid values) */
88 #define BG_COLOR "#999999"
9+/* default color to use for selections: */
10+#define SEL_COLOR "#0000BB"
911
1012 /* how should images be scaled when they are loaded?: *
1113 * (also controllable via -d/-s/-Z/-z options) *
M thumbs.c View
@@ -88,8 +88,8 @@ void tns_render(tns_t *tns, win_t *win) {
8888 if (!tns || !win)
8989 return;
9090
91− tns->cols = win->w / thumb_dim;
92− tns->rows = win->h / thumb_dim;
91+ tns->cols = MAX(1, win->w / thumb_dim);
92+ tns->rows = MAX(1, win->h / thumb_dim);
9393
9494 cnt = tns->cols * tns->rows;
9595 if (tns->first && tns->first + cnt > tns->cnt)
@@ -114,6 +114,22 @@ void tns_render(tns_t *tns, win_t *win) {
114114 }
115115 }
116116
117+ tns_highlight(tns, win, -1);
117118 win_draw(win);
118119 }
119120
121+void tns_highlight(tns_t *tns, win_t *win, int old) {
122+ thumb_t *t;
123+
124+ if (!tns || !win)
125+ return;
126+
127+ if (old >= 0 && old < tns->cnt) {
128+ t = &tns->thumbs[old];
129+ win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, False);
130+ }
131+ if (tns->sel < tns->cnt) {
132+ t = &tns->thumbs[tns->sel];
133+ win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, True);
134+ }
135+}
M thumbs.h View
@@ -46,5 +46,6 @@ void tns_free(tns_t*, win_t*);
4646 void tns_load(tns_t*, win_t*, const char*);
4747
4848 void tns_render(tns_t*, win_t*);
49+void tns_highlight(tns_t*, win_t*, int);
4950
5051 #endif /* THUMBS_H */
M window.c View
@@ -29,7 +29,7 @@
2929 static Cursor carrow;
3030 static Cursor chand;
3131 static Cursor cwatch;
32−static GC bgc;
32+static GC gc;
3333
3434 Atom wm_delete_win;
3535
@@ -50,7 +50,8 @@ void win_set_sizehints(win_t *win) {
5050 void win_open(win_t *win) {
5151 win_env_t *e;
5252 XClassHint classhint;
53− XColor bgcol;
53+ XColor col;
54+ XGCValues gcval;
5455 int gmask;
5556
5657 if (!win)
@@ -67,13 +68,18 @@ void win_open(win_t *win) {
6768 e->cmap = DefaultColormap(e->dpy, e->scr);
6869 e->depth = DefaultDepth(e->dpy, e->scr);
6970
70− if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
71− &bgcol, &bgcol))
71+ if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
72+ &col, &col))
73+ win->bgcol = col.pixel;
74+ else
75+ die("could not allocate color: %s", BG_COLOR);
76+ if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), SEL_COLOR,
77+ &col, &col))
78+ win->selcol = col.pixel;
79+ else
7280 die("could not allocate color: %s", BG_COLOR);
7381
74− win->bgcol = bgcol.pixel;
7582 win->pm = 0;
76−
7783 win->fullscreen = 0;
7884
7985 /* determine window offsets, width & height */
@@ -112,7 +118,8 @@ void win_open(win_t *win) {
112118 chand = XCreateFontCursor(e->dpy, XC_fleur);
113119 cwatch = XCreateFontCursor(e->dpy, XC_watch);
114120
115− bgc = XCreateGC(e->dpy, win->xwin, 0, None);
121+ gcval.line_width = 2;
122+ gc = XCreateGC(e->dpy, win->xwin, GCLineWidth, &gcval);
116123
117124 win_set_title(win, "sxiv");
118125
@@ -141,7 +148,7 @@ void win_close(win_t *win) {
141148 XFreeCursor(win->env.dpy, chand);
142149 XFreeCursor(win->env.dpy, cwatch);
143150
144− XFreeGC(win->env.dpy, bgc);
151+ XFreeGC(win->env.dpy, gc);
145152
146153 XDestroyWindow(win->env.dpy, win->xwin);
147154 XCloseDisplay(win->env.dpy);
@@ -226,11 +233,6 @@ void win_free_pixmap(win_t *win, Pixmap pm) {
226233 XFreePixmap(win->env.dpy, pm);
227234 }
228235
229−void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
230− if (win)
231− XCopyArea(win->env.dpy, pm, win->pm, bgc, 0, 0, w, h, x, y);
232−}
233−
234236 void win_clear(win_t *win) {
235237 win_env_t *e;
236238 XGCValues gcval;
@@ -239,14 +241,37 @@ void win_clear(win_t *win) {
239241 return;
240242
241243 e = &win->env;
242− gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : win->bgcol;
243−
244+ gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
245+ win->bgcol;
244246 if (win->pm)
245247 XFreePixmap(e->dpy, win->pm);
246248 win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
247249
248− XChangeGC(e->dpy, bgc, GCForeground, &gcval);
249− XFillRectangle(e->dpy, win->pm, bgc, 0, 0, e->scrw, e->scrh);
250+ XChangeGC(e->dpy, gc, GCForeground, &gcval);
251+ XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh);
252+}
253+
254+void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
255+ if (win)
256+ XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y);
257+}
258+
259+void win_draw_rect(win_t *win, int x, int y, int w, int h, Bool sel) {
260+ win_env_t *e;
261+ XGCValues gcval;
262+
263+ if (!win)
264+ return;
265+
266+ e = &win->env;
267+
268+ if (sel)
269+ gcval.foreground = win->selcol;
270+ else
271+ gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
272+ win->bgcol;
273+ XChangeGC(e->dpy, gc, GCForeground, &gcval);
274+ XDrawRectangle(e->dpy, win->pm, gc, x, y, w, h);
250275 }
251276
252277 void win_draw(win_t *win) {
M window.h View
@@ -43,6 +43,7 @@ typedef struct win_s {
4343 win_env_t env;
4444
4545 unsigned long bgcol;
46+ unsigned long selcol;
4647 Pixmap pm;
4748
4849 int x;
@@ -66,9 +67,10 @@ void win_toggle_fullscreen(win_t*);
6667
6768 Pixmap win_create_pixmap(win_t*, int, int);
6869 void win_free_pixmap(win_t*, Pixmap);
69−void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
7070
7171 void win_clear(win_t*);
72+void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
73+void win_draw_rect(win_t*, int, int, int, int, Bool);
7274 void win_draw(win_t*);
7375
7476 void win_set_title(win_t*, const char*);