imagebox: allow to not resize images
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
a7a8c2d024
commit
0b6b96131a
|
@ -30,6 +30,7 @@ typedef struct
|
||||||
/** Imagebox image */
|
/** Imagebox image */
|
||||||
image_t *image;
|
image_t *image;
|
||||||
xcolor_t bg;
|
xcolor_t bg;
|
||||||
|
bool resize;
|
||||||
} imagebox_data_t;
|
} imagebox_data_t;
|
||||||
|
|
||||||
static area_t
|
static area_t
|
||||||
|
@ -40,8 +41,12 @@ imagebox_geometry(widget_t *widget, int screen, int height, int width)
|
||||||
|
|
||||||
if(d->image)
|
if(d->image)
|
||||||
{
|
{
|
||||||
|
if(d->resize)
|
||||||
|
geometry.width = ((double) height / (double) d->image->height) * d->image->width;
|
||||||
|
else
|
||||||
|
geometry.width = d->image->width;
|
||||||
|
|
||||||
geometry.height = height;
|
geometry.height = height;
|
||||||
geometry.width = ((double) height / (double) d->image->height) * d->image->width;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -69,7 +74,7 @@ imagebox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry,
|
||||||
{
|
{
|
||||||
if(d->bg.initialized)
|
if(d->bg.initialized)
|
||||||
draw_rectangle(ctx, geometry, 1.0, true, &d->bg);
|
draw_rectangle(ctx, geometry, 1.0, true, &d->bg);
|
||||||
draw_image(ctx, geometry.x, geometry.y, ctx->height, d->image);
|
draw_image(ctx, geometry.x, geometry.y, d->resize ? ctx->height : 0, d->image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +92,7 @@ imagebox_destructor(widget_t *w)
|
||||||
/** Imagebox widget.
|
/** Imagebox widget.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
* \param token The key token.
|
* \param token The key token.
|
||||||
|
* \param resize Resize image.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
* \luastack
|
* \luastack
|
||||||
* \lfield image The image to display.
|
* \lfield image The image to display.
|
||||||
|
@ -108,6 +114,9 @@ luaA_imagebox_index(lua_State *L, awesome_token_t token)
|
||||||
case A_TK_BG:
|
case A_TK_BG:
|
||||||
luaA_pushcolor(L, &d->bg);
|
luaA_pushcolor(L, &d->bg);
|
||||||
break;
|
break;
|
||||||
|
case A_TK_RESIZE:
|
||||||
|
lua_pushboolean(L, d->resize);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -150,6 +159,9 @@ luaA_imagebox_newindex(lua_State *L, awesome_token_t token)
|
||||||
else if((buf = luaL_checklstring(L, 3, &len)))
|
else if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
xcolor_init_reply(xcolor_init_unchecked(&d->bg, buf, len));
|
xcolor_init_reply(xcolor_init_unchecked(&d->bg, buf, len));
|
||||||
break;
|
break;
|
||||||
|
case A_TK_RESIZE:
|
||||||
|
d->resize = luaA_checkboolean(L, 3);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +180,7 @@ widget_t *
|
||||||
imagebox_new(alignment_t align)
|
imagebox_new(alignment_t align)
|
||||||
{
|
{
|
||||||
widget_t *w = p_new(widget_t, 1);
|
widget_t *w = p_new(widget_t, 1);
|
||||||
|
imagebox_data_t *d;
|
||||||
widget_common_new(w);
|
widget_common_new(w);
|
||||||
w->align = align;
|
w->align = align;
|
||||||
w->draw = imagebox_draw;
|
w->draw = imagebox_draw;
|
||||||
|
@ -175,7 +188,8 @@ imagebox_new(alignment_t align)
|
||||||
w->newindex = luaA_imagebox_newindex;
|
w->newindex = luaA_imagebox_newindex;
|
||||||
w->destructor = imagebox_destructor;
|
w->destructor = imagebox_destructor;
|
||||||
w->geometry = imagebox_geometry;
|
w->geometry = imagebox_geometry;
|
||||||
w->data = p_new(imagebox_data_t, 1);
|
w->data = d = p_new(imagebox_data_t, 1);
|
||||||
|
d->resize = true;
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue