Переглянути джерело

White background for images with alpha

master
Bert 14 роки тому
джерело
коміт
d982b06eed
4 змінених файлів з 35 додано та 17 видалено
  1. +3
    -0
      image.c
  2. +13
    -1
      thumbs.c
  3. +15
    -15
      window.c
  4. +4
    -1
      window.h

+ 3
- 0
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);


+ 13
- 1
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);


+ 15
- 15
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) {


+ 4
- 1
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*);


||||||
x
 
000:0
Завантаження…
Відмінити
Зберегти