adds fg_half as an option to the progressbar

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
marco candrian 2008-02-05 01:27:39 +01:00 committed by Julien Danjou
parent a26b40fa28
commit 09e60cb95e
4 changed files with 41 additions and 15 deletions

View File

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

View File

@ -206,10 +206,18 @@ draw_rectangle(DrawCtx *ctx, Area geometry, Bool filled, XColor color)
}
}
/* 'fullwidth' represents a full color-pattern range */
/** Draw rectangle with gradient colors
* \param ctx Draw context
* \param geometry geometry
* \param fullwidth width of full bar in pixels
* \param filled filled rectangle?
* \param color color to use from 0%
* \param color_half color at 50%
* \param color_full color at 100%
*/
void
draw_rectangle_gradient(DrawCtx *ctx, Area geometry, int fullwidth, Bool filled,
XColor color, XColor color_full)
XColor color, XColor * color_half, XColor * color_full)
{
cairo_pattern_t *pat;
@ -219,8 +227,15 @@ draw_rectangle_gradient(DrawCtx *ctx, Area geometry, int fullwidth, Bool filled,
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);
if(color_half)
cairo_pattern_add_color_stop_rgb(pat, 0.5, color_half->red / 65535.0,
color_half->green / 65535.0, color_half->blue / 65535.0);
if(color_full)
cairo_pattern_add_color_stop_rgb(pat, 1, color_full->red / 65535.0,
color_full->green / 65535.0, color_full->blue / 65535.0);
else
cairo_pattern_add_color_stop_rgb(pat, 1, color.red / 65535.0,
color.green / 65535.0, color.blue / 65535.0);
cairo_set_source(ctx->cr, pat);
@ -232,7 +247,7 @@ draw_rectangle_gradient(DrawCtx *ctx, Area geometry, int fullwidth, Bool filled,
else
{
cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1);
cairo_set_source(ctx->cr, pat);
cairo_stroke(ctx->cr);
}
cairo_pattern_destroy(pat);

View File

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

View File

@ -42,8 +42,10 @@ typedef struct
float height;
/** Foreground color */
XColor *fg;
/** Foreground color when bar is half-full */
XColor **pfg_half;
/** Foreground color when bar is full */
XColor *fg_full;
XColor **pfg_full;
/** Background color */
XColor *bg;
/** Border color */
@ -74,7 +76,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
widget->area.y = 0;
margin_top = (int) (widget->statusbar->height * (1 - d->height)) / 2 + 0.5 + widget->area.y;
pb_height = (int) ((widget->statusbar->height * d->height - (d->gap * (d->bars - 1))) / d->bars + 0.5);
pb_height = (int) ((widget->statusbar->height * d->height - (d->gap * (d->bars - 1))) / d->bars + 0.5);
left_offset = widget->area.x + d->padding;
for(i = 0; i < d->bars; i++)
@ -94,7 +96,8 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
rectangle.y = margin_top + 1;
rectangle.width = pwidth;
rectangle.height = pb_height - 2;
draw_rectangle_gradient(ctx, rectangle, width - 2, True, d->fg[i], d->fg_full[i]);
draw_rectangle_gradient(ctx, rectangle, width - 2, True, d->fg[i],
d->pfg_half[i], d->pfg_full[i]);
}
if(width - 2 - pwidth > 0) /* not filled area */
@ -155,7 +158,8 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
}
d->fg = p_new(XColor, d->bars);
d->fg_full = p_new(XColor, d->bars);
d->pfg_full = p_new(XColor *, d->bars);
d->pfg_half = p_new(XColor *, d->bars);
d->bg = p_new(XColor, d->bars);
d->bordercolor = p_new(XColor, d->bars);
d->percent = p_new(int, d->bars);
@ -169,10 +173,17 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
else
d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((color = cfg_getstr(cfg, "fg_half")))
{
d->pfg_half[i] = p_new(XColor, 1);
*(d->pfg_half[i]) = draw_color_new(globalconf.display, phys_screen, color);
}
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];
{
d->pfg_full[i] = p_new(XColor, 1);
*(d->pfg_full[i]) = draw_color_new(globalconf.display, phys_screen, color);
}
if((color = cfg_getstr(cfg, "bg")))
d->bg[i] = draw_color_new(globalconf.display, phys_screen, color);
@ -183,8 +194,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
d->bordercolor[i] = draw_color_new(globalconf.display, phys_screen, color);
else
d->bordercolor[i] = d->fg[i];
}
}
d->height = cfg_getfloat(config, "height");
d->gap = cfg_getint(config, "gap");