draw_rectangle_gradient() for the progressbar widget; + fg_full option

Adds an optional additional foreground color option to a bar: fg_full = <color>

A value of 0 represents the fg-color, and a value of 100 (a full graph) the
fg_full-color.

Example:

progressbar xy
{
  bar { fg = "#111155" fg_full = "#3333cc"  bg = "#000000" bordercolor = "#4444cc"}
  ....
}

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
marco candrian 2008-02-04 11:16:30 +01:00 committed by Julien Danjou
parent 91d6a11fd3
commit b024b0c0cf
4 changed files with 46 additions and 3 deletions

View File

@ -152,6 +152,7 @@ cfg_opt_t widget_graph_opts[] =
cfg_opt_t widget_progressbar_bar_opts[] = cfg_opt_t widget_progressbar_bar_opts[] =
{ {
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "fg_full", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bordercolor", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bordercolor", (char *) NULL, CFGF_NONE),
CFG_END() CFG_END()

View File

@ -151,10 +151,43 @@ draw_rectangle(DrawCtx *ctx, Area geometry, Bool filled, XColor color)
cairo_fill(ctx->cr); cairo_fill(ctx->cr);
} }
else else
{
cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1); cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1);
cairo_stroke(ctx->cr); cairo_stroke(ctx->cr);
} }
}
/* 'fullwidth' represents a full color-pattern range */
void
draw_rectangle_gradient(DrawCtx *ctx, Area geometry, int fullwidth, Bool filled,
XColor color, XColor color_full)
{
cairo_pattern_t *pat;
cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
cairo_set_line_width(ctx->cr, 1.0);
pat = cairo_pattern_create_linear(geometry.x, geometry.y, geometry.x + fullwidth, geometry.y);
cairo_pattern_add_color_stop_rgb(pat, 0, color.red / 65535.0,
color.green / 65535.0, color.blue / 65535.0);
cairo_pattern_add_color_stop_rgb(pat, 1, color_full.red / 65535.0,
color_full.green / 65535.0, color_full.blue / 65535.0);
cairo_set_source(ctx->cr, pat);
if(filled)
{
cairo_rectangle(ctx->cr, geometry.x, geometry.y, geometry.width, geometry.height);
cairo_fill(ctx->cr);
}
else
{
cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1);
cairo_set_source(ctx->cr, pat);
}
cairo_pattern_destroy(pat);
}
/* draw_graph functions */ /* draw_graph functions */
void void

View File

@ -95,6 +95,7 @@ void draw_context_delete(DrawCtx *);
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg); void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg);
void draw_rectangle(DrawCtx *, Area, Bool, XColor); void draw_rectangle(DrawCtx *, Area, Bool, XColor);
void draw_rectangle_gradient(DrawCtx *, Area, int, Bool, XColor, XColor);
void draw_graph_setup(DrawCtx *); void draw_graph_setup(DrawCtx *);
void draw_graph(DrawCtx *, int, int, int, int *, int *, int, XColor); void draw_graph(DrawCtx *, int, int, int, int *, int *, int, XColor);

View File

@ -42,6 +42,8 @@ typedef struct
float height; float height;
/** Foreground color */ /** Foreground color */
XColor *fg; XColor *fg;
/** Foreground color when bar is full */
XColor *fg_full;
/** Background color */ /** Background color */
XColor *bg; XColor *bg;
/** Border color */ /** Border color */
@ -92,7 +94,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
rectangle.y = margin_top + 1; rectangle.y = margin_top + 1;
rectangle.width = pwidth; rectangle.width = pwidth;
rectangle.height = pb_height - 2; rectangle.height = pb_height - 2;
draw_rectangle(ctx, rectangle, True, d->fg[i]); draw_rectangle_gradient(ctx, rectangle, width - 2, True, d->fg[i], d->fg_full[i]);
} }
if(width - 2 - pwidth > 0) /* not filled area */ if(width - 2 - pwidth > 0) /* not filled area */
@ -152,8 +154,9 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
return w; return w;
} }
d->bg = p_new(XColor, d->bars);
d->fg = p_new(XColor, d->bars); d->fg = p_new(XColor, d->bars);
d->fg_full = p_new(XColor, d->bars);
d->bg = p_new(XColor, d->bars);
d->bordercolor = p_new(XColor, d->bars); d->bordercolor = p_new(XColor, d->bars);
d->percent = p_new(int, d->bars); d->percent = p_new(int, d->bars);
@ -166,6 +169,11 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
else else
d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((color = cfg_getstr(cfg, "fg_full")))
d->fg_full[i] = draw_color_new(globalconf.display, phys_screen, color);
else
d->fg_full[i] = d->fg[i];
if((color = cfg_getstr(cfg, "bg"))) if((color = cfg_getstr(cfg, "bg")))
d->bg[i] = draw_color_new(globalconf.display, phys_screen, color); d->bg[i] = draw_color_new(globalconf.display, phys_screen, color);
else else