aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-03-09 11:37:49 +0100
committerBert <ber.t@gmx.com>2011-03-09 11:37:49 +0100
commitd982b06eed04cb080a4dd730b75f93285d5b159b (patch)
tree1be5b16d7ecb6a692603fa3f80bce7134c74412e
parenta82c45431bd31bfedaad00d77cc2ab4c772774d0 (diff)
White background for images with alpha
-rw-r--r--image.c3
-rw-r--r--thumbs.c14
-rw-r--r--window.c30
-rw-r--r--window.h5
4 files changed, 35 insertions, 17 deletions
diff --git a/image.c b/image.c
index c8fab6a..854e50b 100644
--- a/image.c
+++ b/image.c
@@ -210,6 +210,9 @@ void img_render(img_t *img, win_t *win) {
imlib_context_set_image(img->im);
else
imlib_context_set_image(im_broken);
+
+ if (imlib_image_has_alpha())
+ win_draw_rect(win, win->pm, dx, dy, dw, dh, True, 0, win->white);
imlib_context_set_drawable(win->pm);
imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
diff --git a/thumbs.c b/thumbs.c
index 78380ec..4669967 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -88,6 +88,8 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
t->pm = win_create_pixmap(win, t->w, t->h);
imlib_context_set_drawable(t->pm);
imlib_context_set_anti_alias(1);
+ if (imlib_image_has_alpha())
+ win_draw_rect(win, t->pm, 0, 0, t->w, t->h, True, 0, win->white);
imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
0, 0, t->w, t->h);
tns->dirty = 1;
@@ -170,13 +172,23 @@ void tns_render(tns_t *tns, win_t *win) {
void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) {
thumb_t *t;
+ unsigned long col;
if (!tns || !win)
return;
if (n >= 0 && n < tns->cnt) {
t = &tns->thumbs[n];
- win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, hl);
+
+ if (hl)
+ col = win->selcol;
+ else if (win->fullscreen)
+ col = win->black;
+ else
+ col = win->bgcol;
+
+ win_draw_rect(win, win->pm, t->x - 2, t->y - 2, t->w + 4, t->h + 4,
+ False, 2, col);
}
win_draw(win);
diff --git a/window.c b/window.c
index 200e1c5..75eac60 100644
--- a/window.c
+++ b/window.c
@@ -52,7 +52,6 @@ void win_open(win_t *win) {
win_env_t *e;
XClassHint classhint;
XColor col;
- XGCValues gcval;
char none_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
Pixmap none;
int gmask;
@@ -71,6 +70,9 @@ void win_open(win_t *win) {
e->cmap = DefaultColormap(e->dpy, e->scr);
e->depth = DefaultDepth(e->dpy, e->scr);
+ win->black = BlackPixel(e->dpy, e->scr);
+ win->white = WhitePixel(e->dpy, e->scr);
+
if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
&col, &col))
win->bgcol = col.pixel;
@@ -127,8 +129,7 @@ void win_open(win_t *win) {
none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8);
cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0);
- gcval.line_width = 2;
- gc = XCreateGC(e->dpy, win->xwin, GCLineWidth, &gcval);
+ gc = XCreateGC(e->dpy, win->xwin, 0, None);
win_set_title(win, "sxiv");
@@ -251,8 +252,8 @@ 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 ? win->black : win->bgcol;
+
if (win->pm)
XFreePixmap(e->dpy, win->pm);
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) {
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;
+void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
+ Bool fill, int lw, unsigned long col) {
XGCValues gcval;
- if (!win)
+ if (!win || !pm)
return;
- e = &win->env;
+ gcval.line_width = lw;
+ gcval.foreground = col;
+ XChangeGC(win->env.dpy, gc, GCForeground | GCLineWidth, &gcval);
- if (sel)
- gcval.foreground = win->selcol;
+ if (fill)
+ XFillRectangle(win->env.dpy, pm, gc, x, y, w, h);
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);
+ XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h);
}
void win_draw(win_t *win) {
diff --git a/window.h b/window.h
index 87f3a0f..4848395 100644
--- a/window.h
+++ b/window.h
@@ -43,6 +43,8 @@ typedef struct {
Window xwin;
win_env_t env;
+ unsigned long black;
+ unsigned long white;
unsigned long bgcol;
unsigned long selcol;
Pixmap pm;
@@ -71,7 +73,8 @@ void win_free_pixmap(win_t*, Pixmap);
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_rect(win_t*, Pixmap, int, int, int, int, Bool, int,
+ unsigned long);
void win_draw(win_t*);
void win_set_title(win_t*, const char*);