new graph-widget option: grow = <{right, left}>
Signed-off-by: Marco Candrian <mac@calmar.ws> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
08f1e90384
commit
214a5c4bfa
|
@ -481,7 +481,7 @@ This widget shows a graph.
|
|||
Defines a data-stream section;
|
||||
Options: max, scale, fg, fg_center, fg_end and draw_style.
|
||||
*max*::
|
||||
This value prints a full graph (default = 100)
|
||||
This value prints a full graph (default = 100).
|
||||
*scale*::
|
||||
Re-scales when input > max (see below).
|
||||
*fg*::
|
||||
|
@ -499,9 +499,11 @@ This widget shows a graph.
|
|||
*width*::
|
||||
Set width.
|
||||
*height*::
|
||||
Set height (i.e. 0.9 = 90%)
|
||||
Set height (i.e. 0.9 = 90%).
|
||||
*padding_left*::
|
||||
Empty space on the left.
|
||||
*grow*::
|
||||
Put new values onto the 'left' or 'right'.
|
||||
*bg*::
|
||||
Background color.
|
||||
*bordercolor*::
|
||||
|
@ -706,6 +708,7 @@ screen <integer> [MULTI]
|
|||
width = <integer>
|
||||
height = <float>
|
||||
padding_left = <integer>
|
||||
grow = <{left, right}>
|
||||
bg = <color>
|
||||
bordercolor = <color>
|
||||
x = <integer> y = <integer>
|
||||
|
|
|
@ -189,6 +189,7 @@ cfg_opt_t widget_graph_opts[] =
|
|||
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
||||
CFG_SEC((char *) "data", widget_graph_data_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
|
||||
CFG_INT((char *) "width", 100, CFGF_NONE),
|
||||
CFG_STR((char *) "grow", (char *) "left", CFGF_NONE),
|
||||
CFG_INT((char *) "padding_left", 0, CFGF_NONE),
|
||||
CFG_FLOAT((char *) "height", 0.67, CFGF_NONE),
|
||||
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
|
||||
|
|
|
@ -398,12 +398,13 @@ draw_graph_setup(DrawCtx *ctx)
|
|||
* \param from array of starting-point offsets to draw a graph-lines
|
||||
* \param to array of end-point offsets to draw a graph-lines
|
||||
* \param cur_index current position in data-array (cycles around)
|
||||
* \param grow put new values to the left or to the right
|
||||
* \param pcolor color at the left
|
||||
* \param pcolor_center color in the center
|
||||
* \param pcolor_end color at the right
|
||||
*/
|
||||
void
|
||||
draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index,
|
||||
draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index, Position grow,
|
||||
area_t patt_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end)
|
||||
{
|
||||
int i, x, y, w;
|
||||
|
@ -416,6 +417,21 @@ draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index,
|
|||
w = rect.width;
|
||||
|
||||
i = -1;
|
||||
if(grow == Right) /* draw from right to left */
|
||||
{
|
||||
x += w - 1;
|
||||
while(++i < w)
|
||||
{
|
||||
cairo_move_to(ctx->cr, x, y - from[cur_index]);
|
||||
cairo_line_to(ctx->cr, x, y - to[cur_index]);
|
||||
x--;
|
||||
|
||||
if (--cur_index < 0)
|
||||
cur_index = w - 1;
|
||||
}
|
||||
}
|
||||
else /* draw from left to right */
|
||||
{
|
||||
while(++i < w)
|
||||
{
|
||||
cairo_move_to(ctx->cr, x, y - from[cur_index]);
|
||||
|
@ -425,6 +441,7 @@ draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index,
|
|||
if (--cur_index < 0)
|
||||
cur_index = w - 1;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_stroke(ctx->cr);
|
||||
|
||||
|
@ -439,12 +456,13 @@ draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index,
|
|||
* \param w width in pixels
|
||||
* \param to array of offsets to draw the line through...
|
||||
* \param cur_index current position in data-array (cycles around)
|
||||
* \param grow put new values to the left or to the right
|
||||
* \param pcolor color at the left
|
||||
* \param pcolor_center color in the center
|
||||
* \param pcolor_end color at the right
|
||||
*/
|
||||
void
|
||||
draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index,
|
||||
draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index, Position grow,
|
||||
area_t patt_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end)
|
||||
{
|
||||
int i, x, y, w;
|
||||
|
@ -457,9 +475,17 @@ draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index,
|
|||
y = rect.y;
|
||||
w = rect.width;
|
||||
|
||||
if(grow == Right) /* draw from right to left */
|
||||
{
|
||||
x += w - 1;
|
||||
cairo_move_to(ctx->cr, x, y - to[cur_index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* x-1 (on the border), paints *from* the last point (... not included itself) */
|
||||
/* makes sense when you assume there is already some line drawn to it. */
|
||||
/* may makes sense when you assume there is already some line drawn to it - anyway */
|
||||
cairo_move_to(ctx->cr, x - 1, y - to[cur_index]);
|
||||
}
|
||||
|
||||
for (i = 0; i < w; i++)
|
||||
{
|
||||
|
@ -481,6 +507,10 @@ draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index,
|
|||
|
||||
if (--cur_index < 0) /* cycles around the index */
|
||||
cur_index = w - 1;
|
||||
|
||||
if(grow == Right)
|
||||
x--;
|
||||
else
|
||||
x++;
|
||||
}
|
||||
cairo_stroke(ctx->cr);
|
||||
|
|
|
@ -127,8 +127,8 @@ void draw_rectangle(DrawCtx *, area_t, Bool, XColor);
|
|||
void draw_rectangle_gradient(DrawCtx *, area_t, Bool, area_t, XColor *, XColor *, XColor *);
|
||||
|
||||
void draw_graph_setup(DrawCtx *);
|
||||
void draw_graph(DrawCtx *, area_t, int *, int *, int, area_t, XColor *, XColor *, XColor *);
|
||||
void draw_graph_line(DrawCtx *, area_t, int *, int, area_t, XColor *, XColor *, XColor *);
|
||||
void draw_graph(DrawCtx *, area_t, int *, int *, int, Position, area_t, XColor *, XColor *, XColor *);
|
||||
void draw_graph_line(DrawCtx *, area_t, int *, int, Position, area_t, XColor *, XColor *, XColor *);
|
||||
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
||||
void draw_image(DrawCtx *, int, int, int, const char *);
|
||||
void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *);
|
||||
|
|
|
@ -40,6 +40,7 @@ typedef struct
|
|||
int size; /** Size of lines-array (also innerbox-lenght) */
|
||||
XColor bg; /** Background color */
|
||||
XColor bordercolor; /** Border color */
|
||||
Position grow; /** grow: Left or Right */
|
||||
|
||||
/* markers... */
|
||||
int *index; /** Index of current (new) value */
|
||||
|
@ -181,7 +182,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
if (--cur_index < 0) /* next index to compare to other values */
|
||||
cur_index = d->size - 1;
|
||||
}
|
||||
draw_graph(ctx, rectangle , d->draw_from, d->draw_to, *(d->filltop_index[z]), pattern_area,
|
||||
draw_graph(ctx, rectangle , d->draw_from, d->draw_to, *(d->filltop_index[z]), d->grow, pattern_area,
|
||||
&(d->filltop_color[z]), d->filltop_pcolor_center[z], d->filltop_pcolor_end[z]);
|
||||
}
|
||||
}
|
||||
|
@ -229,8 +230,8 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
if (--cur_index < 0)
|
||||
cur_index = d->size - 1;
|
||||
}
|
||||
draw_graph(ctx, rectangle, d->draw_from, d->fillbottom[z], *(d->fillbottom_index[z]), pattern_area,
|
||||
&(d->fillbottom_color[z]), d->fillbottom_pcolor_center[z], d->fillbottom_pcolor_end[z]);
|
||||
draw_graph(ctx, rectangle, d->draw_from, d->fillbottom[z], *(d->fillbottom_index[z]), d->grow,
|
||||
pattern_area, &(d->fillbottom_color[z]), d->fillbottom_pcolor_center[z], d->fillbottom_pcolor_end[z]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,7 +252,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
/* draw style = line */
|
||||
for(z = 0; z < d->drawline_total; z++)
|
||||
{
|
||||
draw_graph_line(ctx, rectangle, d->drawline[z], *(d->drawline_index[z]), pattern_area,
|
||||
draw_graph_line(ctx, rectangle, d->drawline[z], *(d->drawline_index[z]), d->grow, pattern_area,
|
||||
&(d->drawline_color[z]), d->drawline_pcolor_center[z], d->drawline_pcolor_end[z]);
|
||||
}
|
||||
}
|
||||
|
@ -346,6 +347,19 @@ graph_tell(Widget *widget, char *property, char *command)
|
|||
command, &d->bordercolor))
|
||||
return WIDGET_ERROR_FORMAT_COLOR;
|
||||
}
|
||||
else if(!a_strcmp(property, "grow"))
|
||||
{
|
||||
if(!a_strcmp(command, "left"))
|
||||
d->grow = Left;
|
||||
else if(!a_strcmp(command, "right"))
|
||||
d->grow = Right;
|
||||
else
|
||||
{
|
||||
warn("error changing property %s of widget %s, must be 'left' or 'right'\n",
|
||||
property, widget->name);
|
||||
return WIDGET_ERROR_CUSTOM;
|
||||
}
|
||||
}
|
||||
else
|
||||
return WIDGET_ERROR;
|
||||
|
||||
|
@ -391,6 +405,14 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
|||
return w;
|
||||
}
|
||||
|
||||
d->grow = position_get_from_str(cfg_getstr(config, "grow"));
|
||||
if(d->grow != Left && d->grow != Right)
|
||||
{
|
||||
warn("graph widget: 'grow' argument must be 'left' or 'right'\n");
|
||||
d->data_items = 0; /* disable widget drawing */
|
||||
return w;
|
||||
}
|
||||
|
||||
d->draw_from = p_new(int, d->size);
|
||||
d->draw_to = p_new(int, d->size);
|
||||
|
||||
|
|
Loading…
Reference in New Issue