stop reloading image on every draw
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
f95889f2ad
commit
321f855752
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *image;
|
draw_image_t *image;
|
||||||
bool resize;
|
bool resize;
|
||||||
} Data;
|
} Data;
|
||||||
|
|
||||||
|
@ -36,16 +36,16 @@ iconbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
|
||||||
void *p __attribute__ ((unused)))
|
void *p __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
Data *d = w->widget->data;
|
Data *d = w->widget->data;
|
||||||
area_t area = draw_get_image_size(d->image);
|
draw_image_t *image = d->image;
|
||||||
|
|
||||||
/* image not valid */
|
/* image not valid */
|
||||||
if(area.width < 0 || area.height < 0)
|
if(!image)
|
||||||
return (w->area.width = 0);
|
return (w->area.width = 0);
|
||||||
|
|
||||||
if(d->resize)
|
if(d->resize)
|
||||||
w->area.width = ((double) ctx->height / area.height) * area.width;
|
w->area.width = ((double) ctx->height / image->height) * image->width;
|
||||||
else
|
else
|
||||||
w->area.width = area.width;
|
w->area.width = image->width;
|
||||||
|
|
||||||
if(w->area.width > ctx->width - used)
|
if(w->area.width > ctx->width - used)
|
||||||
return (w->area.width = 0);
|
return (w->area.width = 0);
|
||||||
|
@ -59,8 +59,8 @@ iconbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
|
||||||
|
|
||||||
w->area.y = 0;
|
w->area.y = 0;
|
||||||
|
|
||||||
draw_image_from_file(ctx, w->area.x, w->area.y,
|
draw_image(ctx, w->area.x, w->area.y,
|
||||||
d->resize ? ctx->height : 0, d->image);
|
d->resize ? ctx->height : 0, image);
|
||||||
|
|
||||||
return w->area.width;
|
return w->area.width;
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,8 @@ iconbox_tell(widget_t *widget, const char *property, const char *new_value)
|
||||||
|
|
||||||
if(!a_strcmp(property, "image"))
|
if(!a_strcmp(property, "image"))
|
||||||
{
|
{
|
||||||
p_delete(&d->image);
|
draw_image_delete(&d->image);
|
||||||
d->image = a_strdup(new_value);
|
d->image = draw_image_new(new_value);
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "resize"))
|
else if(!a_strcmp(property, "resize"))
|
||||||
d->resize = a_strtobool(new_value);
|
d->resize = a_strtobool(new_value);
|
||||||
|
|
Loading…
Reference in New Issue