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 */
|
/* draw_graph functions */
|
||||||
void
|
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);
|
cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
|
||||||
*pp_cr = cairo_create (*pp_surface);
|
cairo_set_line_width(ctx->cr, 1.0);
|
||||||
|
|
||||||
cairo_set_antialias(*pp_cr, CAIRO_ANTIALIAS_NONE);
|
|
||||||
cairo_set_line_width(*pp_cr, 1.0);
|
|
||||||
/* without it, it can draw over the path on sharp angles (...too long lines) */
|
/* without it, it can draw over the path on sharp angles (...too long lines) */
|
||||||
cairo_set_line_join (*pp_cr, CAIRO_LINE_JOIN_ROUND);
|
cairo_set_line_join (ctx->cr, CAIRO_LINE_JOIN_ROUND);
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_graph_end(cairo_surface_t *surface, cairo_t *cr)
|
|
||||||
{
|
|
||||||
cairo_destroy(cr);
|
|
||||||
cairo_surface_destroy(surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draws a graph; it takes the line-lengths from *from and *to. It cycles
|
/* 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
|
* backwards through those arrays (what have the length of w), beginning at
|
||||||
* position cur_index, until cur_index is reached again (wrapped around). */
|
* position cur_index, until cur_index is reached again (wrapped around). */
|
||||||
void
|
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;
|
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;
|
i = -1;
|
||||||
while(++i < w)
|
while(++i < w)
|
||||||
{
|
{
|
||||||
cairo_move_to(cr, x, y - from[cur_index]);
|
cairo_move_to(ctx->cr, x, y - from[cur_index]);
|
||||||
cairo_line_to(cr, x, y - to[cur_index]);
|
cairo_line_to(ctx->cr, x, y - to[cur_index]);
|
||||||
x++;
|
x++;
|
||||||
|
|
||||||
if (--cur_index < 0)
|
if (--cur_index < 0)
|
||||||
cur_index = w - 1;
|
cur_index = w - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_stroke(cr);
|
cairo_stroke(ctx->cr);
|
||||||
}
|
}
|
||||||
void
|
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 i;
|
||||||
int flag = 0; /* used to prevent drawing a line from 0 to 0 values */
|
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) */
|
/* 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. */
|
/* 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++)
|
for (i = 0; i < w; i++)
|
||||||
{
|
{
|
||||||
if (to[cur_index] > 0)
|
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;
|
flag = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(flag) /* only draw from values > 0 to 0-values */
|
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;
|
flag = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cairo_move_to(cr, x, y);
|
cairo_move_to(ctx->cr, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (--cur_index < 0) /* cycles around the index */
|
if (--cur_index < 0) /* cycles around the index */
|
||||||
cur_index = w - 1;
|
cur_index = w - 1;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
cairo_stroke(cr);
|
cairo_stroke(ctx->cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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_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_graph_init(DrawCtx *, cairo_surface_t **, cairo_t **);
|
void draw_graph_setup(DrawCtx *);
|
||||||
void draw_graph(cairo_t *, int, int, int, int *, int *, int, XColor);
|
void draw_graph(DrawCtx *, int, int, int, int *, int *, int, XColor);
|
||||||
void draw_graph_end(cairo_surface_t *, cairo_t *);
|
void draw_graph_line(DrawCtx *, int, int, int, int *, int, XColor);
|
||||||
void draw_graph_line(cairo_t *, int, int, int, int *, int, XColor);
|
|
||||||
|
|
||||||
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
||||||
void draw_image(DrawCtx *, int, int, int, const char *);
|
void draw_image(DrawCtx *, int, int, int, const char *);
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cairo.h>
|
|
||||||
#include "common/draw.h"
|
#include "common/draw.h"
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
@ -74,8 +73,6 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
int z, y, x, tmp;
|
int z, y, x, tmp;
|
||||||
Data *d = widget->data;
|
Data *d = widget->data;
|
||||||
Area rectangle;
|
Area rectangle;
|
||||||
cairo_surface_t *surface;
|
|
||||||
cairo_t *cr;
|
|
||||||
|
|
||||||
if(d->width < 1 || !d->data_items)
|
if(d->width < 1 || !d->data_items)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -106,7 +103,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
rectangle.height -= 2;
|
rectangle.height -= 2;
|
||||||
draw_rectangle(ctx, rectangle, True, d->bg);
|
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 */
|
/* draw style = top */
|
||||||
for(z = 0; z < d->filltop_total; z++)
|
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_from[y] = d->box_height - tmp;
|
||||||
d->draw_to[y] = d->box_height - d->filltop[z][y];
|
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,
|
left_offset + 2, margin_top + d->box_height + 1,
|
||||||
d->size, d->draw_from, d->draw_to, d->index,
|
d->size, d->draw_from, d->draw_to, d->index,
|
||||||
d->filltop_color[z]);
|
d->filltop_color[z]);
|
||||||
|
@ -146,7 +143,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
d->draw_from[y] = tmp;
|
d->draw_from[y] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_graph(cr,
|
draw_graph(ctx,
|
||||||
left_offset + 2, margin_top + d->box_height + 1,
|
left_offset + 2, margin_top + d->box_height + 1,
|
||||||
d->size, d->draw_from, d->fillbottom[z], d->index,
|
d->size, d->draw_from, d->fillbottom[z], d->index,
|
||||||
d->fillbottom_color[z]);
|
d->fillbottom_color[z]);
|
||||||
|
@ -155,14 +152,12 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
/* draw style = line */
|
/* draw style = line */
|
||||||
for(z = 0; z < d->drawline_total; z++)
|
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,
|
left_offset + 2, margin_top + d->box_height + 1,
|
||||||
d->size, d->drawline[z], d->index,
|
d->size, d->drawline[z], d->index,
|
||||||
d->drawline_color[z]);
|
d->drawline_color[z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_graph_end(surface, cr);
|
|
||||||
|
|
||||||
widget->area.width = d->width;
|
widget->area.width = d->width;
|
||||||
widget->area.height = widget->statusbar->height;
|
widget->area.height = widget->statusbar->height;
|
||||||
return widget->area.width;
|
return widget->area.width;
|
||||||
|
@ -314,19 +309,19 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
||||||
|
|
||||||
if ((type = cfg_getstr(cfg, "style")))
|
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[d->fillbottom_total] = d->lines[i];
|
||||||
d->fillbottom_color[d->fillbottom_total] = tmp_color;
|
d->fillbottom_color[d->fillbottom_total] = tmp_color;
|
||||||
d->fillbottom_total++;
|
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[d->filltop_total] = d->lines[i];
|
||||||
d->filltop_color[d->filltop_total] = tmp_color;
|
d->filltop_color[d->filltop_total] = tmp_color;
|
||||||
d->filltop_total++;
|
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[d->drawline_total] = d->lines[i];
|
||||||
d->drawline_color[d->drawline_total] = tmp_color;
|
d->drawline_color[d->drawline_total] = tmp_color;
|
||||||
|
|
Loading…
Reference in New Issue