X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_gfx.c;h=c4236dec9f0b886621adc0babe18aff2be08549d;hp=fa938617f51ba22d763332829d062fdd20458ddf;hb=0cab41a011f053fa84ac481849380f69ded26147;hpb=219fd9224e3117dcf59df8818d4e9e3eab26022a diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index fa93861..c4236de 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010 **************************************************************************** * rrd_gfx.c graphics wrapper for rrdtool **************************************************************************/ @@ -105,6 +105,42 @@ void gfx_add_point( cairo_line_to(cr, x, y); } +/* add a point to a line or to an area */ +void gfx_add_rect_fadey( + image_desc_t *im, + double x1,double y1, + double x2,double y2, + double py, + gfx_color_t color1, + gfx_color_t color2, + double height) +{ + cairo_t *cr = im->cr; + + cairo_new_path(cr); + gfx_area_fit(im, &x1, &y1); + gfx_area_fit(im, &x2, &y2); + cairo_line_to(cr, x1, y1); + cairo_line_to(cr, x1, y2); + cairo_line_to(cr, x2, y2); + cairo_line_to(cr, x2, y1); + cairo_close_path(cr); + cairo_pattern_t* p; + if (height < 0) { + p = cairo_pattern_create_linear(x1,y1,x2,y1+height); + } else if (height > 0) { + p = cairo_pattern_create_linear(x1,(y2+py)/2+height,x2,(y2+py)/2); + } else { + p = cairo_pattern_create_linear(x1,y1,x2,(y2+py)/2); + } + //cairo_pattern_t* p = cairo_pattern_create_linear(x1,py+50,x2,py); + cairo_pattern_add_color_stop_rgba(p, 1, color1.red,color1.green,color1.blue,color1.alpha); + cairo_pattern_add_color_stop_rgba(p, 0, color2.red,color2.green,color2.blue,color2.alpha); + cairo_set_source(cr, p); + cairo_pattern_destroy(p); + cairo_fill(cr); +} + void gfx_close_path( image_desc_t *im) { @@ -124,7 +160,7 @@ static PangoLayout *gfx_prep_text( const char *text) { PangoLayout *layout = im->layout; - PangoFontDescription *pfd; + const PangoFontDescription *pfd; cairo_t *cr = im->cr; static double last_tabwidth = -1; @@ -293,10 +329,10 @@ void gfx_line_fit( line_width = cairo_get_line_width(cr); line_height = line_width; cairo_user_to_device_distance(cr, &line_width, &line_height); - line_width = line_width / 2.0 - (long) (line_width / 2.0); - line_height = line_height / 2.0 - (long) (line_height / 2.0); - *x = (double) ((long) (*x + 0.5)) - line_width; - *y = (double) ((long) (*y + 0.5)) + line_height; + line_width = line_width / 2.0 - ceil(line_width / 2.0); + line_height = line_height / 2.0 - ceil(line_height / 2.0); + *x = floor(*x - 0.5) - line_width; + *y = ceil(*y + 0.5) + line_height; cairo_device_to_user(cr, x, y); } @@ -312,7 +348,7 @@ void gfx_area_fit( if (!im->gridfit) return; cairo_user_to_device(cr, x, y); - *x = (double) ((long) (*x + 0.5)); - *y = (double) ((long) (*y + 0.5)); + *x = floor(*x); + *y = ceil(*y); cairo_device_to_user(cr, x, y); }