Load warning icon only once

This commit is contained in:
Bert 2011-02-09 17:05:09 +01:00
parent 8e5835d1fd
commit ea65610747

13
image.c
View File

@ -29,11 +29,15 @@ int zl_cnt;
float zoom_min; float zoom_min;
float zoom_max; float zoom_max;
Imlib_Image *im_warn;
void img_init(img_t *img, win_t *win) { void img_init(img_t *img, win_t *win) {
zl_cnt = sizeof(zoom_levels) / sizeof(zoom_levels[0]); zl_cnt = sizeof(zoom_levels) / sizeof(zoom_levels[0]);
zoom_min = zoom_levels[0] / 100.0; zoom_min = zoom_levels[0] / 100.0;
zoom_max = zoom_levels[zl_cnt - 1] / 100.0; zoom_max = zoom_levels[zl_cnt - 1] / 100.0;
im_warn = imlib_create_image_using_data(32, 32, icon_warn);
if (img) { if (img) {
img->zoom = options->zoom; img->zoom = options->zoom;
img->zoom = MAX(img->zoom, zoom_min); img->zoom = MAX(img->zoom, zoom_min);
@ -49,7 +53,9 @@ void img_init(img_t *img, win_t *win) {
} }
void img_free(img_t* img) { void img_free(img_t* img) {
if (imlib_context_get_image()) if (img && img->valid && imlib_context_get_image())
imlib_free_image();
imlib_context_set_image(im_warn);
imlib_free_image(); imlib_free_image();
} }
@ -79,19 +85,16 @@ int img_check(const char *filename) {
} }
int img_load(img_t *img, const char *filename) { int img_load(img_t *img, const char *filename) {
Imlib_Image *im_warn;
if (!img || !filename) if (!img || !filename)
return 0; return 0;
if (imlib_context_get_image()) if (img->valid && imlib_context_get_image())
imlib_free_image(); imlib_free_image();
if ((img->valid = _imlib_load_image(filename))) { if ((img->valid = _imlib_load_image(filename))) {
imlib_context_set_anti_alias(img->aa); imlib_context_set_anti_alias(img->aa);
img->scalemode = options->scalemode; img->scalemode = options->scalemode;
} else { } else {
im_warn = imlib_create_image_using_data(32, 32, icon_warn);
imlib_context_set_image(im_warn); imlib_context_set_image(im_warn);
imlib_image_set_has_alpha(1); imlib_image_set_has_alpha(1);
imlib_context_set_anti_alias(0); imlib_context_set_anti_alias(0);