2 * imagebox.c - imagebox widget
4 * Copyright © 2008 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.
25 extern awesome_t globalconf
;
27 /** The imagebox private data structure */
36 imagebox_geometry(widget_t
*widget
, int screen
, int height
, int width
)
39 imagebox_data_t
*d
= widget
->data
;
43 geometry
.height
= height
;
44 geometry
.width
= ((double) height
/ (double) d
->image
->height
) * d
->image
->width
;
56 * \param widget The widget.
57 * \param ctx The draw context.
58 * \param geometry The geometry we draw in.
59 * \param screen The screen.
60 * \param p A pointer to the object we're draw onto.
63 imagebox_draw(widget_t
*widget
, draw_context_t
*ctx
, area_t geometry
,
64 int screen
, wibox_t
*p
)
66 imagebox_data_t
*d
= widget
->data
;
71 draw_rectangle(ctx
, geometry
, 1.0, true, &d
->bg
);
72 draw_image(ctx
, geometry
.x
, geometry
.y
, ctx
->height
, 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
;
83 image_unref(&d
->image
);
88 * \param L The Lua VM state.
89 * \param token The key token.
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");
99 imagebox_data_t
*d
= (*widget
)->data
;
105 return luaA_image_userdata_new(L
, d
->image
);
107 luaA_pushcolor(L
, &d
->bg
);
115 /** The __newindex method for a imagebox object.
116 * \param L The Lua VM state.
117 * \param token The key token.
118 * \return The number of elements pushed on stack.
121 luaA_imagebox_newindex(lua_State
*L
, awesome_token_t token
)
123 widget_t
**widget
= luaA_checkudata(L
, 1, "widget");
124 image_t
**image
= NULL
;
125 imagebox_data_t
*d
= (*widget
)->data
;
134 || (image
= luaA_checkudata(L
, 3, "image")))
137 image_unref(&d
->image
);
139 d
->image
= image_ref(image
);
147 else if((buf
= luaL_checklstring(L
, 3, &len
)))
148 xcolor_init_reply(xcolor_init_unchecked(&d
->bg
, buf
, len
));
154 widget_invalidate_bywidget(*widget
);
160 /** Create a new imagebox widget.
161 * \param align Widget alignment.
162 * \return A brand new widget.
165 imagebox_new(alignment_t align
)
167 widget_t
*w
= p_new(widget_t
, 1);
168 widget_common_new(w
);
170 w
->draw
= imagebox_draw
;
171 w
->index
= luaA_imagebox_index
;
172 w
->newindex
= luaA_imagebox_newindex
;
173 w
->destructor
= imagebox_destructor
;
174 w
->geometry
= imagebox_geometry
;
175 w
->data
= p_new(imagebox_data_t
, 1);
180 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80