White background for images with alpha
This commit is contained in:
		
							parent
							
								
									a82c45431b
								
							
						
					
					
						commit
						d982b06eed
					
				
							
								
								
									
										3
									
								
								image.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								image.c
									
									
									
									
									
								
							| @ -211,6 +211,9 @@ void img_render(img_t *img, win_t *win) { | |||||||
| 	else | 	else | ||||||
| 		imlib_context_set_image(im_broken); | 		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_context_set_drawable(win->pm); | ||||||
| 	imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh); | 	imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh); | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								thumbs.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								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); | 	t->pm = win_create_pixmap(win, t->w, t->h); | ||||||
| 	imlib_context_set_drawable(t->pm); | 	imlib_context_set_drawable(t->pm); | ||||||
| 	imlib_context_set_anti_alias(1); | 	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, | 	imlib_render_image_part_on_drawable_at_size(0, 0, w, h, | ||||||
| 	                                            0, 0, t->w, t->h); | 	                                            0, 0, t->w, t->h); | ||||||
| 	tns->dirty = 1; | 	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) { | void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) { | ||||||
| 	thumb_t *t; | 	thumb_t *t; | ||||||
|  | 	unsigned long col; | ||||||
| 
 | 
 | ||||||
| 	if (!tns || !win) | 	if (!tns || !win) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	if (n >= 0 && n < tns->cnt) { | 	if (n >= 0 && n < tns->cnt) { | ||||||
| 		t = &tns->thumbs[n]; | 		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); | 	win_draw(win); | ||||||
|  | |||||||
							
								
								
									
										30
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								window.c
									
									
									
									
									
								
							| @ -52,7 +52,6 @@ void win_open(win_t *win) { | |||||||
| 	win_env_t *e; | 	win_env_t *e; | ||||||
| 	XClassHint classhint; | 	XClassHint classhint; | ||||||
| 	XColor col; | 	XColor col; | ||||||
| 	XGCValues gcval; |  | ||||||
| 	char none_data[] = {0, 0, 0, 0, 0, 0, 0, 0}; | 	char none_data[] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||||||
| 	Pixmap none; | 	Pixmap none; | ||||||
| 	int gmask; | 	int gmask; | ||||||
| @ -71,6 +70,9 @@ void win_open(win_t *win) { | |||||||
| 	e->cmap = DefaultColormap(e->dpy, e->scr); | 	e->cmap = DefaultColormap(e->dpy, e->scr); | ||||||
| 	e->depth = DefaultDepth(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, | 	if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR, | ||||||
| 		                   &col, &col)) | 		                   &col, &col)) | ||||||
| 		win->bgcol = col.pixel; | 		win->bgcol = col.pixel; | ||||||
| @ -127,8 +129,7 @@ void win_open(win_t *win) { | |||||||
| 	none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); | 	none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); | ||||||
| 	cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); | 	cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); | ||||||
| 
 | 
 | ||||||
| 	gcval.line_width = 2; | 	gc = XCreateGC(e->dpy, win->xwin, 0, None); | ||||||
| 	gc = XCreateGC(e->dpy, win->xwin, GCLineWidth, &gcval); |  | ||||||
| 
 | 
 | ||||||
| 	win_set_title(win, "sxiv"); | 	win_set_title(win, "sxiv"); | ||||||
| 
 | 
 | ||||||
| @ -251,8 +252,8 @@ void win_clear(win_t *win) { | |||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	e = &win->env; | 	e = &win->env; | ||||||
| 	gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : | 	gcval.foreground = win->fullscreen ? win->black : win->bgcol; | ||||||
| 	                                     win->bgcol; | 
 | ||||||
| 	if (win->pm) | 	if (win->pm) | ||||||
| 		XFreePixmap(e->dpy, win->pm); | 		XFreePixmap(e->dpy, win->pm); | ||||||
| 	win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth); | 	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); | 		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) { | void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, | ||||||
| 	win_env_t *e; | 		Bool fill, int lw, unsigned long col) { | ||||||
| 	XGCValues gcval; | 	XGCValues gcval; | ||||||
| 
 | 
 | ||||||
| 	if (!win) | 	if (!win || !pm) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	e = &win->env; | 	gcval.line_width = lw; | ||||||
|  | 	gcval.foreground = col; | ||||||
|  | 	XChangeGC(win->env.dpy, gc, GCForeground | GCLineWidth, &gcval); | ||||||
| 
 | 
 | ||||||
| 	if (sel) | 	if (fill) | ||||||
| 		gcval.foreground = win->selcol; | 		XFillRectangle(win->env.dpy, pm, gc, x, y, w, h); | ||||||
| 	else | 	else | ||||||
| 		gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : | 		XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h); | ||||||
| 		                                     win->bgcol; |  | ||||||
| 	XChangeGC(e->dpy, gc, GCForeground, &gcval); |  | ||||||
| 	XDrawRectangle(e->dpy, win->pm, gc, x, y, w, h); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void win_draw(win_t *win) { | void win_draw(win_t *win) { | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								window.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								window.h
									
									
									
									
									
								
							| @ -43,6 +43,8 @@ typedef struct { | |||||||
| 	Window xwin; | 	Window xwin; | ||||||
| 	win_env_t env; | 	win_env_t env; | ||||||
| 
 | 
 | ||||||
|  | 	unsigned long black; | ||||||
|  | 	unsigned long white; | ||||||
| 	unsigned long bgcol; | 	unsigned long bgcol; | ||||||
| 	unsigned long selcol; | 	unsigned long selcol; | ||||||
| 	Pixmap pm; | 	Pixmap pm; | ||||||
| @ -71,7 +73,8 @@ void win_free_pixmap(win_t*, Pixmap); | |||||||
| 
 | 
 | ||||||
| void win_clear(win_t*); | void win_clear(win_t*); | ||||||
| void win_draw_pixmap(win_t*, Pixmap, int, int, int, int); | 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_draw(win_t*); | ||||||
| 
 | 
 | ||||||
| void win_set_title(win_t*, const char*); | void win_set_title(win_t*, const char*); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Bert
						Bert