Krolyxon
Commit d982b06

Branches

Refs →

nsxivd982b06

White background for images with alpha

Author
Bert
Date
2011-03-09 11:37 +0100
Parent
a82c454
Commit
d982b06eed04cb080a4dd730b75f93285d5b159b

+35 −17

4 files changed

  1. M image.c +3 −0
  2. M thumbs.c +13 −1
  3. M window.c +15 −15
  4. M window.h +4 −1
M image.c View
@@ -210,6 +210,9 @@ void img_render(img_t *img, win_t *win) {
210210 imlib_context_set_image(img->im);
211211 else
212212 imlib_context_set_image(im_broken);
213+
214+ if (imlib_image_has_alpha())
215+ win_draw_rect(win, win->pm, dx, dy, dw, dh, True, 0, win->white);
213216
214217 imlib_context_set_drawable(win->pm);
215218 imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
M thumbs.c View
@@ -88,6 +88,8 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
8888 t->pm = win_create_pixmap(win, t->w, t->h);
8989 imlib_context_set_drawable(t->pm);
9090 imlib_context_set_anti_alias(1);
91+ if (imlib_image_has_alpha())
92+ win_draw_rect(win, t->pm, 0, 0, t->w, t->h, True, 0, win->white);
9193 imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
9294 0, 0, t->w, t->h);
9395 tns->dirty = 1;
@@ -170,13 +172,23 @@ void tns_render(tns_t *tns, win_t *win) {
170172
171173 void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) {
172174 thumb_t *t;
175+ unsigned long col;
173176
174177 if (!tns || !win)
175178 return;
176179
177180 if (n >= 0 && n < tns->cnt) {
178181 t = &tns->thumbs[n];
179− win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, hl);
182+
183+ if (hl)
184+ col = win->selcol;
185+ else if (win->fullscreen)
186+ col = win->black;
187+ else
188+ col = win->bgcol;
189+
190+ win_draw_rect(win, win->pm, t->x - 2, t->y - 2, t->w + 4, t->h + 4,
191+ False, 2, col);
180192 }
181193
182194 win_draw(win);
M window.c View
@@ -52,7 +52,6 @@ void win_open(win_t *win) {
5252 win_env_t *e;
5353 XClassHint classhint;
5454 XColor col;
55− XGCValues gcval;
5655 char none_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
5756 Pixmap none;
5857 int gmask;
@@ -71,6 +70,9 @@ void win_open(win_t *win) {
7170 e->cmap = DefaultColormap(e->dpy, e->scr);
7271 e->depth = DefaultDepth(e->dpy, e->scr);
7372
73+ win->black = BlackPixel(e->dpy, e->scr);
74+ win->white = WhitePixel(e->dpy, e->scr);
75+
7476 if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
7577 &col, &col))
7678 win->bgcol = col.pixel;
@@ -127,8 +129,7 @@ void win_open(win_t *win) {
127129 none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8);
128130 cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0);
129131
130− gcval.line_width = 2;
131− gc = XCreateGC(e->dpy, win->xwin, GCLineWidth, &gcval);
132+ gc = XCreateGC(e->dpy, win->xwin, 0, None);
132133
133134 win_set_title(win, "sxiv");
134135
@@ -251,8 +252,8 @@ void win_clear(win_t *win) {
251252 return;
252253
253254 e = &win->env;
254− gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
255− win->bgcol;
255+ gcval.foreground = win->fullscreen ? win->black : win->bgcol;
256+
256257 if (win->pm)
257258 XFreePixmap(e->dpy, win->pm);
258259 win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
@@ -266,22 +267,21 @@ void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
266267 XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y);
267268 }
268269
269−void win_draw_rect(win_t *win, int x, int y, int w, int h, Bool sel) {
270− win_env_t *e;
270+void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
271+ Bool fill, int lw, unsigned long col) {
271272 XGCValues gcval;
272273
273− if (!win)
274+ if (!win || !pm)
274275 return;
275276
276− e = &win->env;
277+ gcval.line_width = lw;
278+ gcval.foreground = col;
279+ XChangeGC(win->env.dpy, gc, GCForeground | GCLineWidth, &gcval);
277280
278− if (sel)
279− gcval.foreground = win->selcol;
281+ if (fill)
282+ XFillRectangle(win->env.dpy, pm, gc, x, y, w, h);
280283 else
281− gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
282− win->bgcol;
283− XChangeGC(e->dpy, gc, GCForeground, &gcval);
284− XDrawRectangle(e->dpy, win->pm, gc, x, y, w, h);
284+ XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h);
285285 }
286286
287287 void win_draw(win_t *win) {
M window.h View
@@ -43,6 +43,8 @@ typedef struct {
4343 Window xwin;
4444 win_env_t env;
4545
46+ unsigned long black;
47+ unsigned long white;
4648 unsigned long bgcol;
4749 unsigned long selcol;
4850 Pixmap pm;
@@ -71,7 +73,8 @@ void win_free_pixmap(win_t*, Pixmap);
7173
7274 void win_clear(win_t*);
7375 void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
74−void win_draw_rect(win_t*, int, int, int, int, Bool);
76+void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int,
77+ unsigned long);
7578 void win_draw(win_t*);
7679
7780 void win_set_title(win_t*, const char*);