From 2eb6fda36ee24da3257851b92c210fe7f1e4bde1 Mon Sep 17 00:00:00 2001 From: marco candrian Date: Fri, 18 Apr 2008 00:58:42 +0200 Subject: [PATCH] [graph] simplify 'line' drawing; draw the border after the graph-drawing Drawing the border after the graph-drawing, allows to draw down to the border itself when 0 values occur. Signed-off-by: Julien Danjou --- common/draw.c | 42 +++++++++++++++--------------------------- widgets/graph.c | 18 ++++++++++-------- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/common/draw.c b/common/draw.c index 01997f4d5..260761945 100644 --- a/common/draw.c +++ b/common/draw.c @@ -493,51 +493,39 @@ 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; - int flag = 0; /* used to prevent drawing a line from 0 to 0 values */ + int i, x, w; + float y; cairo_pattern_t *pat; + /* some stuff below is based on 'try and error' */ + pat = draw_setup_cairo_color_source(ctx, patt_rect, pcolor, pcolor_center, pcolor_end); x = rect.x; - y = rect.y; + y = rect.y + 0.5; /* center of a pixel */ w = rect.width; - /* NOTE: think about about the cairo coordinates pointing to the upper left - * corner of a single pixel (what itself is a square) - and it draws from - * there! It fills the pixels placed on the bottom/right of that, or so */ + /* if grow == Right, go through the values from old to new. Setup the oldest below */ + if(grow == Right && ++cur_index > w - 1) + cur_index = 0; - if(grow == Right) /* draw from right to left */ - x += w; - - /* initial point */ cairo_move_to(ctx->cr, x, y - to[cur_index]); for(i = 0; i < w; i++) { + cairo_line_to(ctx->cr, ++x, y - to[cur_index]); + + /* cycles around the index */ if(grow == Right) - x--; - else - x++; - - if (to[cur_index] > 0) { - cairo_line_to(ctx->cr, x, y - to[cur_index]); - flag = 1; + if (++cur_index > w-1) + cur_index = 0; } else { - if(flag) /* only draw from values > 0 to 0-values */ - { - cairo_line_to(ctx->cr, x, y); - flag = 0; - } - else - cairo_move_to(ctx->cr, x, y); + if(--cur_index < 0) + cur_index = w - 1; } - - if (--cur_index < 0) /* cycles around the index */ - cur_index = w - 1; } cairo_stroke(ctx->cr); diff --git a/widgets/graph.c b/widgets/graph.c index 464d9f728..7e57a15ed 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -106,14 +106,9 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset, margin_top = (int)((widget->statusbar->height - (d->box_height + 2)) / 2 + 0.5) + widget->area.y; - rectangle.x = widget->area.x; - rectangle.y = margin_top; - rectangle.width = d->size + 2; - rectangle.height = d->box_height + 2; - draw_rectangle(ctx, rectangle, 1.0, False, d->bordercolor); - - rectangle.x++; - rectangle.y++; + /* draw background */ + rectangle.x = widget->area.x + 1; + rectangle.y = margin_top + 1; rectangle.width = d->size; rectangle.height = d->box_height; draw_rectangle(ctx, rectangle, 1.0, True, d->bg); @@ -271,6 +266,13 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset, } } + /* draw border (after line-drawing, what paints 0-values to the border) */ + rectangle.x = widget->area.x; + rectangle.y = margin_top; + rectangle.width = d->size + 2; + rectangle.height = d->box_height + 2; + draw_rectangle(ctx, rectangle, 1.0, False, d->bordercolor); + widget->area.width = d->width; widget->area.height = widget->statusbar->height; return widget->area.width;