2 * imagebox.c - imagebox widget
4 * Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 /** The imagebox private data structure */
36 imagebox_extents(lua_State
*L
, widget_t
*widget
)
38 area_t geometry
= { .x
= 0, .y
= 0 };
39 imagebox_data_t
*d
= widget
->data
;
43 geometry
.width
= image_getwidth(d
->image
);
44 geometry
.height
= image_getheight(d
->image
);
56 * \param widget The widget.
57 * \param ctx The draw context.
58 * \param geometry The geometry we draw in.
59 * \param p A pointer to the object we're draw onto.
62 imagebox_draw(widget_t
*widget
, draw_context_t
*ctx
, area_t geometry
, wibox_t
*p
)
64 imagebox_data_t
*d
= widget
->data
;
66 if(d
->image
&& geometry
.width
&& geometry
.height
)
69 draw_rectangle(ctx
, geometry
, 1.0, true, &d
->bg
);
71 double ratio
= d
->resize
? (double) geometry
.height
/ image_getheight(d
->image
) : 1;
72 draw_image(ctx
, geometry
.x
, geometry
.y
, ratio
, d
->image
);
76 /** Delete a imagebox widget.
77 * \param w The widget to destroy.
80 imagebox_destructor(widget_t
*w
)
82 imagebox_data_t
*d
= w
->data
;
87 * \param L The Lua VM state.
88 * \param token The key token.
89 * \param resize Resize image.
90 * \return The number of elements pushed on stack.
92 * \lfield image The image to display.
93 * \lfield bg The background color to use.
96 luaA_imagebox_index(lua_State
*L
, awesome_token_t token
)
98 widget_t
*widget
= luaA_checkudata(L
, 1, &widget_class
);
99 imagebox_data_t
*d
= widget
->data
;
104 luaA_object_push_item(L
, 1, d
->image
);
107 luaA_pushcolor(L
, &d
->bg
);
110 lua_pushboolean(L
, d
->resize
);
119 /** The __newindex method for a imagebox object.
120 * \param L The Lua VM state.
121 * \param token The key token.
122 * \return The number of elements pushed on stack.
125 luaA_imagebox_newindex(lua_State
*L
, awesome_token_t token
)
127 widget_t
*widget
= luaA_checkudata(L
, 1, &widget_class
);
128 imagebox_data_t
*d
= widget
->data
;
136 luaA_object_unref_item(L
, 1, d
->image
);
137 d
->image
= luaA_object_ref_item(L
, 1, 3);
142 else if((buf
= luaL_checklstring(L
, 3, &len
)))
143 color_init_reply(color_init_unchecked(&d
->bg
, buf
, len
));
146 d
->resize
= luaA_checkboolean(L
, 3);
152 widget_invalidate_bywidget(widget
);
158 /** Create a new imagebox widget.
159 * \param w The widget to initialize.
160 * \return A brand new widget.
163 widget_imagebox(widget_t
*w
)
166 w
->draw
= imagebox_draw
;
167 w
->index
= luaA_imagebox_index
;
168 w
->newindex
= luaA_imagebox_newindex
;
169 w
->destructor
= imagebox_destructor
;
170 w
->extents
= imagebox_extents
;
171 w
->data
= d
= p_new(imagebox_data_t
, 1);
177 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80