new widget to draw icons from PNG image

This commit is contained in:
Julien Danjou 2007-12-22 15:37:43 +01:00
parent 55be368539
commit 3f3748d4bd
6 changed files with 44 additions and 2 deletions

View File

@ -332,6 +332,11 @@ config_parse(const char *confpatharg)
{
CFG_END()
};
static cfg_opt_t widget_iconbox_opts[] =
{
CFG_STR((char *) "image", (char *) NULL, CFGF_NONE),
CFG_END()
};
static cfg_opt_t widget_textbox_opts[] =
{
CFG_STR((char *) "default", (char *) NULL, CFGF_NONE),
@ -346,6 +351,7 @@ config_parse(const char *confpatharg)
CFG_SEC((char *) "taglist", widget_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC((char *) "focustitle", widget_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC((char *) "layoutinfo", widget_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC((char *) "iconbox", widget_iconbox_opts, CFGF_TITLE | CFGF_MULTI),
CFG_END()
};
static cfg_opt_t tag_opts[] =

View File

@ -7,7 +7,7 @@ RELEASE = "Productivity Breaker"
# additional layouts
LAYOUTS = layouts/tile.c layouts/floating.c layouts/max.c layouts/fibonacci.c
WIDGETS = widgets/taglist.c widgets/layoutinfo.c widgets/textbox.c widgets/focustitle.c
WIDGETS = widgets/taglist.c widgets/layoutinfo.c widgets/textbox.c widgets/focustitle.c widgets/iconbox.c
# paths
PREFIX = /usr/local

31
draw.c
View File

@ -149,6 +149,37 @@ drawcircle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color)
cairo_surface_destroy(surface);
}
void
drawimage(DrawCtx *ctx, int x, int y, const char *filename)
{
cairo_surface_t *surface, *source;
cairo_t *cr;
source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
surface = cairo_image_surface_create_from_png(filename);
cr = cairo_create (source);
cairo_set_source_surface(cr, surface, x, y);
cairo_paint(cr);
cairo_destroy(cr);
cairo_surface_destroy(source);
cairo_surface_destroy(surface);
}
int draw_get_image_width(const char *filename)
{
int width;
cairo_surface_t *surface;
surface = cairo_image_surface_create_from_png(filename);
cairo_image_surface_get_width(surface);
width = cairo_image_surface_get_width(surface);
cairo_surface_destroy(surface);
return width;
}
Drawable
draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
{

2
draw.h
View File

@ -41,6 +41,8 @@ void draw_free_context(DrawCtx*);
void drawtext(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg);
void drawrectangle(DrawCtx *, int, int, int, int, Bool, XColor);
void drawcircle(DrawCtx *, int, int, int, Bool, XColor);
void drawimage(DrawCtx *, int, int, const char *);
int draw_get_image_width(const char *filename);
Drawable draw_rotate(DrawCtx *, int, double, int, int);
unsigned short textwidth(DrawCtx *, XftFont *, char *);
unsigned short textwidth_primitive(Display*, XftFont*, char*);

View File

@ -11,6 +11,7 @@ const NameFuncLink WidgetList[] =
{"layoutinfo", layoutinfo_new},
{"focustitle", focustitle_new},
{"textbox", textbox_new},
{"iconbox", iconbox_new},
{NULL, NULL}
};
@ -28,7 +29,8 @@ calculate_alignments(Widget *widget)
}
if(widget)
for(; widget; widget = widget->next){
for(; widget; widget = widget->next)
{
if (widget->alignment == AlignFlex)
warn("Multiple flex widgets in panel -"
" ignoring flex for all but the first.");

View File

@ -18,6 +18,7 @@ WidgetConstructor layoutinfo_new;
WidgetConstructor taglist_new;
WidgetConstructor textbox_new;
WidgetConstructor focustitle_new;
WidgetConstructor iconbox_new;
UICB_PROTO(uicb_widget_tell);