Use imlib-handles in thumbs.c instead of pixmaps
This commit is contained in:
		
							parent
							
								
									aadba6f7e5
								
							
						
					
					
						commit
						55659ffcc3
					
				
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | |||||||
| all: sxiv | all: sxiv | ||||||
| 
 | 
 | ||||||
| VERSION=git-20110310 | VERSION=git-20110315 | ||||||
| 
 | 
 | ||||||
| CC?=gcc | CC?=gcc | ||||||
| PREFIX?=/usr/local | PREFIX?=/usr/local | ||||||
|  | |||||||
							
								
								
									
										37
									
								
								thumbs.c
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								thumbs.c
									
									
									
									
									
								
							| @ -19,8 +19,6 @@ | |||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| 
 | 
 | ||||||
| #include <Imlib2.h> |  | ||||||
| 
 |  | ||||||
| #include "config.h" | #include "config.h" | ||||||
| #include "thumbs.h" | #include "thumbs.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
| @ -45,8 +43,12 @@ void tns_free(tns_t *tns, win_t *win) { | |||||||
| 	if (!tns || !tns->thumbs) | 	if (!tns || !tns->thumbs) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	for (i = 0; i < tns->cnt; ++i) | 	for (i = 0; i < tns->cnt; ++i) { | ||||||
| 		win_free_pixmap(win, tns->thumbs[i].pm); | 		if (tns->thumbs[i].im) { | ||||||
|  | 			imlib_context_set_image(tns->thumbs[i].im); | ||||||
|  | 			imlib_free_image(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	free(tns->thumbs); | 	free(tns->thumbs); | ||||||
| 	tns->thumbs = NULL; | 	tns->thumbs = NULL; | ||||||
| @ -66,6 +68,13 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||||||
| 	else if (n >= tns->cnt) | 	else if (n >= tns->cnt) | ||||||
| 		tns->cnt = n + 1; | 		tns->cnt = n + 1; | ||||||
| 
 | 
 | ||||||
|  | 	t = &tns->thumbs[n]; | ||||||
|  | 
 | ||||||
|  | 	if (t->im) { | ||||||
|  | 		imlib_context_set_image(t->im); | ||||||
|  | 		imlib_free_image(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	if ((im = imlib_load_image(filename))) | 	if ((im = imlib_load_image(filename))) | ||||||
| 		imlib_context_set_image(im); | 		imlib_context_set_image(im); | ||||||
| 	else | 	else | ||||||
| @ -79,23 +88,16 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||||||
| 	if (!im && z > 1.0) | 	if (!im && z > 1.0) | ||||||
| 		z = 1.0; | 		z = 1.0; | ||||||
| 
 | 
 | ||||||
| 	t = &tns->thumbs[n]; |  | ||||||
| 	t->w = z * w; | 	t->w = z * w; | ||||||
| 	t->h = z * h; | 	t->h = z * h; | ||||||
| 
 | 
 | ||||||
| 	if (t->pm) |  | ||||||
| 		win_free_pixmap(win, t->pm); |  | ||||||
| 	t->pm = win_create_pixmap(win, t->w, t->h); |  | ||||||
| 	imlib_context_set_drawable(t->pm); |  | ||||||
| 	imlib_context_set_anti_alias(1); | 	imlib_context_set_anti_alias(1); | ||||||
| 	if (imlib_image_has_alpha()) | 	if (!(t->im = imlib_create_cropped_scaled_image(0, 0, w, h, t->w, t->h))) | ||||||
| 		win_draw_rect(win, t->pm, 0, 0, t->w, t->h, True, 0, win->white); | 		die("could not allocate memory"); | ||||||
| 	imlib_render_image_part_on_drawable_at_size(0, 0, w, h, |  | ||||||
| 	                                            0, 0, t->w, t->h); |  | ||||||
| 	tns->dirty = 1; |  | ||||||
| 
 |  | ||||||
| 	if (im) | 	if (im) | ||||||
| 		imlib_free_image_and_decache(); | 		imlib_free_image_and_decache(); | ||||||
|  | 
 | ||||||
|  | 	tns->dirty = 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void tns_check_view(tns_t *tns, Bool scrolled) { | void tns_check_view(tns_t *tns, Bool scrolled) { | ||||||
| @ -133,6 +135,7 @@ void tns_render(tns_t *tns, win_t *win) { | |||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	win_clear(win); | 	win_clear(win); | ||||||
|  | 	imlib_context_set_drawable(win->pm); | ||||||
| 
 | 
 | ||||||
| 	tns->cols = MAX(1, win->w / thumb_dim); | 	tns->cols = MAX(1, win->w / thumb_dim); | ||||||
| 	tns->rows = MAX(1, win->h / thumb_dim); | 	tns->rows = MAX(1, win->h / thumb_dim); | ||||||
| @ -157,7 +160,9 @@ void tns_render(tns_t *tns, win_t *win) { | |||||||
| 		t = &tns->thumbs[tns->first + i]; | 		t = &tns->thumbs[tns->first + i]; | ||||||
| 		t->x = x + (THUMB_SIZE - t->w) / 2; | 		t->x = x + (THUMB_SIZE - t->w) / 2; | ||||||
| 		t->y = y + (THUMB_SIZE - t->h) / 2; | 		t->y = y + (THUMB_SIZE - t->h) / 2; | ||||||
| 		win_draw_pixmap(win, t->pm, t->x, t->y, t->w, t->h); | 		imlib_context_set_image(t->im); | ||||||
|  | 		imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h, | ||||||
|  | 		                                            t->x, t->y, t->w, t->h); | ||||||
| 		if ((i + 1) % tns->cols == 0) { | 		if ((i + 1) % tns->cols == 0) { | ||||||
| 			x = tns->x; | 			x = tns->x; | ||||||
| 			y += thumb_dim; | 			y += thumb_dim; | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								thumbs.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								thumbs.h
									
									
									
									
									
								
							| @ -19,6 +19,8 @@ | |||||||
| #ifndef THUMBS_H | #ifndef THUMBS_H | ||||||
| #define THUMBS_H | #define THUMBS_H | ||||||
| 
 | 
 | ||||||
|  | #include <Imlib2.h> | ||||||
|  | 
 | ||||||
| #include "window.h" | #include "window.h" | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
| @ -29,7 +31,7 @@ typedef enum { | |||||||
| } tnsdir_t; | } tnsdir_t; | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
| 	Pixmap pm; | 	Imlib_Image *im; | ||||||
| 	int x; | 	int x; | ||||||
| 	int y; | 	int y; | ||||||
| 	int w; | 	int w; | ||||||
|  | |||||||
							
								
								
									
										29
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								window.c
									
									
									
									
									
								
							| @ -232,18 +232,6 @@ void win_toggle_fullscreen(win_t *win) { | |||||||
| 	           SubstructureNotifyMask, &ev); | 	           SubstructureNotifyMask, &ev); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Pixmap win_create_pixmap(win_t *win, int w, int h) { |  | ||||||
| 	if (!win) |  | ||||||
| 		return 0; |  | ||||||
| 
 |  | ||||||
| 	return XCreatePixmap(win->env.dpy, win->xwin, w, h, win->env.depth); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void win_free_pixmap(win_t *win, Pixmap pm) { |  | ||||||
| 	if (win && pm) |  | ||||||
| 		XFreePixmap(win->env.dpy, pm); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void win_clear(win_t *win) { | void win_clear(win_t *win) { | ||||||
| 	win_env_t *e; | 	win_env_t *e; | ||||||
| 	XGCValues gcval; | 	XGCValues gcval; | ||||||
| @ -262,9 +250,12 @@ void win_clear(win_t *win) { | |||||||
| 	XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh); | 	XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) { | void win_draw(win_t *win) { | ||||||
| 	if (win) | 	if (!win) | ||||||
| 		XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y); | 		return; | ||||||
|  | 
 | ||||||
|  | 	XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm); | ||||||
|  | 	XClearWindow(win->env.dpy, win->xwin); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, | void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, | ||||||
| @ -284,14 +275,6 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, | |||||||
| 		XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h); | 		XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void win_draw(win_t *win) { |  | ||||||
| 	if (!win) |  | ||||||
| 		return; |  | ||||||
| 
 |  | ||||||
| 	XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm); |  | ||||||
| 	XClearWindow(win->env.dpy, win->xwin); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void win_set_title(win_t *win, const char *title) { | void win_set_title(win_t *win, const char *title) { | ||||||
| 	if (!win) | 	if (!win) | ||||||
| 		return; | 		return; | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								window.h
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								window.h
									
									
									
									
									
								
							| @ -68,14 +68,10 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int); | |||||||
| 
 | 
 | ||||||
| void win_toggle_fullscreen(win_t*); | void win_toggle_fullscreen(win_t*); | ||||||
| 
 | 
 | ||||||
| Pixmap win_create_pixmap(win_t*, int, int); |  | ||||||
| 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(win_t*); | ||||||
| void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int, | void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int, | ||||||
|                    unsigned long); |                    unsigned long); | ||||||
| void win_draw(win_t*); |  | ||||||
| 
 | 
 | ||||||
| void win_set_title(win_t*, const char*); | void win_set_title(win_t*, const char*); | ||||||
| void win_set_cursor(win_t*, win_cur_t); | void win_set_cursor(win_t*, win_cur_t); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Bert
						Bert