graph widget adopted to the latest statusbar changes
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
335334225d
commit
be0779d0fa
|
@ -158,81 +158,71 @@ draw_rectangle(DrawCtx *ctx, Area geometry, Bool filled, XColor color)
|
|||
|
||||
/* draw_graph functions */
|
||||
void
|
||||
draw_graph_init(DrawCtx *ctx, cairo_surface_t **pp_surface, cairo_t **pp_cr)
|
||||
draw_graph_setup(DrawCtx *ctx)
|
||||
{
|
||||
*pp_surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||
*pp_cr = cairo_create (*pp_surface);
|
||||
|
||||
cairo_set_antialias(*pp_cr, CAIRO_ANTIALIAS_NONE);
|
||||
cairo_set_line_width(*pp_cr, 1.0);
|
||||
cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
|
||||
cairo_set_line_width(ctx->cr, 1.0);
|
||||
/* without it, it can draw over the path on sharp angles (...too long lines) */
|
||||
cairo_set_line_join (*pp_cr, CAIRO_LINE_JOIN_ROUND);
|
||||
}
|
||||
|
||||
void
|
||||
draw_graph_end(cairo_surface_t *surface, cairo_t *cr)
|
||||
{
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(surface);
|
||||
cairo_set_line_join (ctx->cr, CAIRO_LINE_JOIN_ROUND);
|
||||
}
|
||||
|
||||
/* draws a graph; it takes the line-lengths from *from and *to. It cycles
|
||||
* backwards through those arrays (what have the length of w), beginning at
|
||||
* position cur_index, until cur_index is reached again (wrapped around). */
|
||||
void
|
||||
draw_graph(cairo_t *cr, int x, int y, int w, int *from, int *to, int cur_index, XColor color)
|
||||
draw_graph(DrawCtx *ctx, int x, int y, int w, int *from, int *to, int cur_index, XColor color)
|
||||
{
|
||||
int i;
|
||||
|
||||
cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
||||
cairo_set_source_rgb(ctx->cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
||||
|
||||
i = -1;
|
||||
while(++i < w)
|
||||
{
|
||||
cairo_move_to(cr, x, y - from[cur_index]);
|
||||
cairo_line_to(cr, x, y - to[cur_index]);
|
||||
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;
|
||||
}
|
||||
|
||||
cairo_stroke(cr);
|
||||
cairo_stroke(ctx->cr);
|
||||
}
|
||||
void
|
||||
draw_graph_line(cairo_t *cr, int x, int y, int w, int *to, int cur_index, XColor color)
|
||||
draw_graph_line(DrawCtx *ctx, int x, int y, int w, int *to, int cur_index, XColor color)
|
||||
{
|
||||
int i;
|
||||
int flag = 0; /* used to prevent drawing a line from 0 to 0 values */
|
||||
cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
||||
cairo_set_source_rgb(ctx->cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
||||
|
||||
/* 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. */
|
||||
cairo_move_to(cr, x - 1, y - to[cur_index]);
|
||||
cairo_move_to(ctx->cr, x - 1, y - to[cur_index]);
|
||||
|
||||
for (i = 0; i < w; i++)
|
||||
{
|
||||
if (to[cur_index] > 0)
|
||||
{
|
||||
cairo_line_to(cr, x, y - to[cur_index]);
|
||||
cairo_line_to(ctx->cr, x, y - to[cur_index]);
|
||||
flag = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(flag) /* only draw from values > 0 to 0-values */
|
||||
{
|
||||
cairo_line_to(cr, x, y);
|
||||
cairo_line_to(ctx->cr, x, y);
|
||||
flag = 0;
|
||||
}
|
||||
else
|
||||
cairo_move_to(cr, x, y);
|
||||
cairo_move_to(ctx->cr, x, y);
|
||||
}
|
||||
|
||||
if (--cur_index < 0) /* cycles around the index */
|
||||
cur_index = w - 1;
|
||||
x++;
|
||||
}
|
||||
cairo_stroke(cr);
|
||||
cairo_stroke(ctx->cr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -96,10 +96,9 @@ void draw_context_delete(DrawCtx *);
|
|||
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg);
|
||||
void draw_rectangle(DrawCtx *, Area, Bool, XColor);
|
||||
|
||||
void draw_graph_init(DrawCtx *, cairo_surface_t **, cairo_t **);
|
||||
void draw_graph(cairo_t *, int, int, int, int *, int *, int, XColor);
|
||||
void draw_graph_end(cairo_surface_t *, cairo_t *);
|
||||
void draw_graph_line(cairo_t *, int, int, int, int *, int, XColor);
|
||||
void draw_graph_setup(DrawCtx *);
|
||||
void draw_graph(DrawCtx *, int, int, int, int *, int *, int, XColor);
|
||||
void draw_graph_line(DrawCtx *, int, int, int, int *, int, XColor);
|
||||
|
||||
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
||||
void draw_image(DrawCtx *, int, int, int, const char *);
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <cairo.h>
|
||||
#include "common/draw.h"
|
||||
#include "widget.h"
|
||||
#include "screen.h"
|
||||
|
@ -74,8 +73,6 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
int z, y, x, tmp;
|
||||
Data *d = widget->data;
|
||||
Area rectangle;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
|
||||
if(d->width < 1 || !d->data_items)
|
||||
return 0;
|
||||
|
@ -106,7 +103,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
rectangle.height -= 2;
|
||||
draw_rectangle(ctx, rectangle, True, d->bg);
|
||||
|
||||
draw_graph_init(ctx, &surface, &cr); /* setup drawing surface etc */
|
||||
draw_graph_setup(ctx); /* setup some drawing options */
|
||||
|
||||
/* draw style = top */
|
||||
for(z = 0; z < d->filltop_total; z++)
|
||||
|
@ -124,7 +121,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
d->draw_from[y] = d->box_height - tmp;
|
||||
d->draw_to[y] = d->box_height - d->filltop[z][y];
|
||||
}
|
||||
draw_graph(cr,
|
||||
draw_graph(ctx,
|
||||
left_offset + 2, margin_top + d->box_height + 1,
|
||||
d->size, d->draw_from, d->draw_to, d->index,
|
||||
d->filltop_color[z]);
|
||||
|
@ -146,7 +143,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
d->draw_from[y] = tmp;
|
||||
}
|
||||
|
||||
draw_graph(cr,
|
||||
draw_graph(ctx,
|
||||
left_offset + 2, margin_top + d->box_height + 1,
|
||||
d->size, d->draw_from, d->fillbottom[z], d->index,
|
||||
d->fillbottom_color[z]);
|
||||
|
@ -155,14 +152,12 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
/* draw style = line */
|
||||
for(z = 0; z < d->drawline_total; z++)
|
||||
{
|
||||
draw_graph_line(cr,
|
||||
draw_graph_line(ctx,
|
||||
left_offset + 2, margin_top + d->box_height + 1,
|
||||
d->size, d->drawline[z], d->index,
|
||||
d->drawline_color[z]);
|
||||
}
|
||||
|
||||
draw_graph_end(surface, cr);
|
||||
|
||||
widget->area.width = d->width;
|
||||
widget->area.height = widget->statusbar->height;
|
||||
return widget->area.width;
|
||||
|
@ -314,19 +309,19 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
|||
|
||||
if ((type = cfg_getstr(cfg, "style")))
|
||||
{
|
||||
if(!strncmp(type, "bottom", sizeof("bottom")))
|
||||
if(!a_strncmp(type, "bottom", sizeof("bottom")))
|
||||
{
|
||||
d->fillbottom[d->fillbottom_total] = d->lines[i];
|
||||
d->fillbottom_color[d->fillbottom_total] = tmp_color;
|
||||
d->fillbottom_total++;
|
||||
}
|
||||
else if (!strncmp(type, "top", sizeof("top")))
|
||||
else if (!a_strncmp(type, "top", sizeof("top")))
|
||||
{
|
||||
d->filltop[d->filltop_total] = d->lines[i];
|
||||
d->filltop_color[d->filltop_total] = tmp_color;
|
||||
d->filltop_total++;
|
||||
}
|
||||
else if (!strncmp(type, "line", sizeof("line")))
|
||||
else if (!a_strncmp(type, "line", sizeof("line")))
|
||||
{
|
||||
d->drawline[d->drawline_total] = d->lines[i];
|
||||
d->drawline_color[d->drawline_total] = tmp_color;
|
||||
|
|
Loading…
Reference in New Issue