X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fcanvas-simpleline.c;h=efff5034f95f4ca7070b8b337dec98e8404aca99;hb=4d5782781939126a41702cb27453553d0041aa54;hp=7bff05487e9c8121654a8dc8e4dd9247c345849a;hpb=bb9cc45cd22af67ac275a5e73accbe14fee664d8;p=ardour.git diff --git a/gtk2_ardour/canvas-simpleline.c b/gtk2_ardour/canvas-simpleline.c index 7bff05487e..efff5034f9 100644 --- a/gtk2_ardour/canvas-simpleline.c +++ b/gtk2_ardour/canvas-simpleline.c @@ -172,68 +172,18 @@ gnome_canvas_simpleline_init (GnomeCanvasSimpleLine *simpleline) simpleline->x2 = 0.0; simpleline->y2 = 0.0; simpleline->color = RGBA_TO_UINT(98,123,174,241); - simpleline->horizontal = TRUE; /* reset in the _update() method */ } static void gnome_canvas_simpleline_destroy (GtkObject *object) { - GnomeCanvasSimpleLine *line; - g_return_if_fail (object != NULL); g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object)); - line = GNOME_CANVAS_SIMPLELINE (object); - if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } -static void -gnome_canvas_simpleline_bounds_world (GnomeCanvasItem *item, int* ix1, int* iy1, int* ix2, int* iy2) -{ - double x1, x2, y1, y2; - ArtPoint i1, i2; - ArtPoint w1, w2; - double i2w[6]; - GnomeCanvasSimpleLine *simpleline = GNOME_CANVAS_SIMPLELINE(item); - - gnome_canvas_simpleline_bounds (item, &x1, &y1, &x2, &y2); - - i1.x = x1; - i1.y = y1; - i2.x = x2; - i2.y = y2; - - gnome_canvas_item_i2w_affine (item, i2w); - art_affine_point (&w1, &i1, i2w); - art_affine_point (&w2, &i2, i2w); - - *ix1 = (int) rint(w1.x); - *ix2 = (int) rint(w2.x); - *iy1 = (int) rint(w1.y); - *iy2 = (int) rint(w2.y); - - /* the update rect has to be of non-zero width and height */ - - if (x1 == x2) { - simpleline->horizontal = FALSE; - *ix2 += 1; - } else { - simpleline->horizontal = TRUE; - *iy2 += 1; - } -} - -static void -gnome_canvas_simpleline_reset_bounds (GnomeCanvasItem *item) -{ - int Ix1, Ix2, Iy1, Iy2; - - gnome_canvas_simpleline_bounds_world (item, &Ix1, &Iy1, &Ix2, &Iy2); - gnome_canvas_update_bbox (item, Ix1, Iy1, Ix2, Iy2); -} - /* * CANVAS CALLBACKS */ @@ -250,6 +200,7 @@ gnome_canvas_simpleline_set_property (GObject *object, GnomeCanvasSimpleLine *simpleline; int update = FALSE; int bounds_changed = FALSE; + double d; g_return_if_fail (object != NULL); g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object)); @@ -258,29 +209,33 @@ gnome_canvas_simpleline_set_property (GObject *object, switch (prop_id) { case PROP_X1: - if (simpleline->x1 != g_value_get_double (value)) { - simpleline->x1 = g_value_get_double (value); + d = g_value_get_double (value); + if (simpleline->x1 != d) { + simpleline->x1 = d; bounds_changed = TRUE; } break; case PROP_Y1: - if (simpleline->y1 != g_value_get_double (value)) { - simpleline->y1 = g_value_get_double (value); + d = g_value_get_double (value); + if (simpleline->y1 != d) { + simpleline->y1 = d; bounds_changed = TRUE; } break; case PROP_X2: - if (simpleline->x2 != g_value_get_double (value)) { - simpleline->x2 = g_value_get_double (value); + d = g_value_get_double (value); + if (simpleline->x2 != d) { + simpleline->x2 = d; bounds_changed = TRUE; } break; case PROP_Y2: - if (simpleline->y2 != g_value_get_double (value)) { - simpleline->y2 = g_value_get_double (value); + d = g_value_get_double (value); + if (simpleline->y2 != d) { + simpleline->y2 = d; bounds_changed = TRUE; } break; @@ -338,119 +293,108 @@ static void gnome_canvas_simpleline_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) { GnomeCanvasSimpleLine *simpleline; - double x; - double y; + double x1, x2, y1, y2; simpleline = GNOME_CANVAS_SIMPLELINE (item); if (parent_class->update) (* parent_class->update) (item, affine, clip_path, flags); - gnome_canvas_simpleline_reset_bounds (item); + /* redraw old location */ - x = simpleline->x1; - y = simpleline->y1; + gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - gnome_canvas_item_i2w (item, &x, &y); - gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x, y, &simpleline->bbox_ulx, &simpleline->bbox_uly); + /* get current bounding box in parent-relative world coordinates */ - x = simpleline->x2; - y = simpleline->y2; + gnome_canvas_simpleline_bounds (item, &x1, &y1, &x2, &y2); - gnome_canvas_item_i2w (item, &x, &y); - gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x, y, &simpleline->bbox_lrx, &simpleline->bbox_lry); -} + /* convert parent-relative item coordinates to world coordinates */ -static void -gnome_canvas_simpleline_render (GnomeCanvasItem *item, - GnomeCanvasBuf *buf) -{ - GnomeCanvasSimpleLine *simpleline; - int end, begin; + gnome_canvas_item_i2w (item, &x1, &y1); + gnome_canvas_item_i2w (item, &x2, &y2); - simpleline = GNOME_CANVAS_SIMPLELINE (item); + /* don't suffer from rounding errors */ - if (parent_class->render) { - (*parent_class->render) (item, buf); - } + x1 = floor (x1); + y1 = floor (y1); + x2 = ceil (x2); + y2 = ceil (y2); - if (buf->is_bg) { - gnome_canvas_buf_ensure_buf (buf); - buf->is_bg = FALSE; - } + /* force non-zero dimensionality for both axes */ - //begin = MAX(simpleline->bbox_ulx,buf->rect.x0); - //end = MIN(simpleline->bbox_lrx,buf->rect.x1); + if (x1 == x2) { + x2 += 1.0; + } - begin = simpleline->bbox_ulx; - end = simpleline->bbox_lrx; + if (y1 == y2) { + y2 += 1.0; + } - if (simpleline->color != 0) { - if (simpleline->horizontal) { - PAINT_HORIZA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a, - begin, end, simpleline->bbox_uly); - } else { - PAINT_VERTA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a, - begin, simpleline->bbox_uly, simpleline->bbox_lry); - } - } + /* reset item bounding box (canvas coordinates, so integral. but stored in doubles) */ + + gnome_canvas_w2c_d (GNOME_CANVAS(item->canvas), x1, y1, &item->x1, &item->y1); + gnome_canvas_w2c_d (GNOME_CANVAS(item->canvas), x2, y2, &item->x2, &item->y2); + + /* redraw new location */ + + gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); + + /* store actual line coords as canvas coordinates for use in render() */ + + x1 = simpleline->x1; + y1 = simpleline->y1; + x2 = simpleline->x2; + y2 = simpleline->y2; + /* convert to world */ + gnome_canvas_item_i2w (item, &x1, &y1); + gnome_canvas_item_i2w (item, &x2, &y2); + /* avoid rounding errors */ + x1 = (int) floor (item->x1); + y1 = (int) floor (item->y1); + x2 = (int) ceil (item->x2); + y2 = (int) ceil (item->y2); + /* convert to canvas coordinates, integral, stored in integers */ + gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simpleline->cx1, &simpleline->cy1); + gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simpleline->cx2, &simpleline->cy2); } static void -gnome_canvas_simpleline_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height) +gnome_canvas_simpleline_render (GnomeCanvasItem *item, + GnomeCanvasBuf *buf) { GnomeCanvasSimpleLine *simpleline; - cairo_t* cr; - double ulx; - double uly; - double lrx; - double lry; + int x1, x2; + int y1, y2; simpleline = GNOME_CANVAS_SIMPLELINE (item); - cr = gdk_cairo_create (drawable); - - if (x > simpleline->bbox_ulx) { - ulx = x; - } else { - ulx = simpleline->bbox_ulx; - } + x1 = simpleline->cx1; + x2 = simpleline->cx2; + y1 = simpleline->cy1; - if (y > simpleline->bbox_uly) { - uly = y; - } else { - uly = simpleline->bbox_uly; + if (buf->is_bg) { + gnome_canvas_buf_ensure_buf (buf); + buf->is_bg = FALSE; } - if (x + width > simpleline->bbox_lrx) { - lrx = simpleline->bbox_lrx; - } else { - lrx = x + width; - } + if (simpleline->x1 != simpleline->x2) { + PAINT_HORIZA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a, + x1, x2, y1); + } else { + y2 = simpleline->cy2; + PAINT_VERTA (buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a, + x1, y1, y2); - if (y + height > simpleline->bbox_lry) { - lry = simpleline->bbox_lry; - } else { - lry = y + height; - } + } +} - ulx -= x; - uly -= y; - lrx -= x; - lry -= y; - - cairo_set_source_rgba (cr, - simpleline->r/255.0, - simpleline->g/255.0, - simpleline->b/255.0, - simpleline->a/255.0); - cairo_set_line_width (cr, 1); - cairo_move_to (cr, ulx+0.5, uly+0.5); - cairo_line_to (cr, lrx+0.5, lry+0.5); - cairo_stroke (cr); +static void +gnome_canvas_simpleline_draw (GnomeCanvasItem* canvas, + GdkDrawable* drawable, + int x, int y, + int width, int height) +{ + /* XXX not implemented */ } static void @@ -458,10 +402,10 @@ gnome_canvas_simpleline_bounds (GnomeCanvasItem *item, double *x1, double *y1, d { GnomeCanvasSimpleLine *simpleline = GNOME_CANVAS_SIMPLELINE (item); - *x1 = simpleline->x1; - *y1 = simpleline->y1; - *x2 = simpleline->x2; - *y2 = simpleline->y2; + *x1 = simpleline->x1; + *y1 = simpleline->y1; + *x2 = simpleline->x1; + *y2 = simpleline->y2; } static double @@ -470,15 +414,12 @@ gnome_canvas_simpleline_point (GnomeCanvasItem *item, double x, double y, int cx (void) cx; (void) cy; - GnomeCanvasSimpleLine *simpleline; double x1, y1, x2, y2; double dx, dy; - simpleline = GNOME_CANVAS_SIMPLELINE (item); - *actual_item = item; - /* Find the bounds for the line plus its outline width */ + /* Find the bounds for the line */ gnome_canvas_simpleline_bounds (item, &x1, &y1, &x2, &y2); @@ -487,7 +428,6 @@ gnome_canvas_simpleline_point (GnomeCanvasItem *item, double x, double y, int cx if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) { return 0.0; } - /* Point is outside line */ if (x < x1)