X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fcanvas-simpleline.c;h=7bff05487e9c8121654a8dc8e4dd9247c345849a;hb=0c04eb8d83e53cf34716486ef85bd868c57f4cc1;hp=eaddc4058e2f7c8cda37698fc9dc49fde9b684b0;hpb=2d32c7da360194e33e821badaf2bff89f3ec70a0;p=ardour.git diff --git a/gtk2_ardour/canvas-simpleline.c b/gtk2_ardour/canvas-simpleline.c index eaddc4058e..7bff05487e 100644 --- a/gtk2_ardour/canvas-simpleline.c +++ b/gtk2_ardour/canvas-simpleline.c @@ -1,55 +1,89 @@ #include #include +#include #include #include "canvas-simpleline.h" #include "rgb_macros.h" +#include "gettext.h" +#define _(Text) dgettext (PACKAGE,Text) enum { - ARG_0, - ARG_X1, - ARG_Y1, - ARG_X2, - ARG_Y2, - ARG_COLOR_RGBA + PROP_0, + PROP_X1, + PROP_Y1, + PROP_X2, + PROP_Y2, + PROP_COLOR_RGBA }; -static void gnome_canvas_simpleline_class_init (GnomeCanvasSimpleLineClass *class); -static void gnome_canvas_simpleline_init (GnomeCanvasSimpleLine *simpleline); -static void gnome_canvas_simpleline_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void gnome_canvas_simpleline_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); - -static void gnome_canvas_simpleline_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags); -static void gnome_canvas_simpleline_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2); -static double gnome_canvas_simpleline_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item); -static void gnome_canvas_simpleline_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf); -static void gnome_canvas_simpleline_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w, int h); +static void gnome_canvas_simpleline_class_init (GnomeCanvasSimpleLineClass *class); + +static void gnome_canvas_simpleline_init (GnomeCanvasSimpleLine *simpleline); + +static void gnome_canvas_simpleline_destroy (GtkObject *object); + +static void gnome_canvas_simpleline_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void gnome_canvas_simpleline_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +static void gnome_canvas_simpleline_update (GnomeCanvasItem *item, + double *affine, + ArtSVP *clip_path, + int flags); + +static void gnome_canvas_simpleline_bounds (GnomeCanvasItem *item, + double *x1, + double *y1, + double *x2, + double *y2); + +static double gnome_canvas_simpleline_point (GnomeCanvasItem *item, + double x, + double y, + int cx, + int cy, + GnomeCanvasItem **actual_item); + +static void gnome_canvas_simpleline_render (GnomeCanvasItem *item, + GnomeCanvasBuf *buf); + +static void gnome_canvas_simpleline_draw (GnomeCanvasItem *item, + GdkDrawable *drawable, + int x, + int y, + int w, + int h); static GnomeCanvasItemClass *parent_class; -GtkType +GType gnome_canvas_simpleline_get_type (void) { - static GtkType simpleline_type = 0; + static GType simpleline_type; if (!simpleline_type) { - GtkTypeInfo simpleline_info = { - "GnomeCanvasSimpleLine", - sizeof (GnomeCanvasSimpleLine), + static const GTypeInfo object_info = { sizeof (GnomeCanvasSimpleLineClass), - (GtkClassInitFunc) gnome_canvas_simpleline_class_init, - (GtkObjectInitFunc) gnome_canvas_simpleline_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gnome_canvas_simpleline_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (GnomeCanvasSimpleLine), + 0, /* n_preallocs */ + (GInstanceInitFunc) gnome_canvas_simpleline_init, + NULL /* value_table */ }; - simpleline_type = gtk_type_unique (gnome_canvas_item_get_type (), &simpleline_info); + simpleline_type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM, "GnomeCanvasSimpleLine", + &object_info, 0); } return simpleline_type; @@ -58,22 +92,70 @@ gnome_canvas_simpleline_get_type (void) static void gnome_canvas_simpleline_class_init (GnomeCanvasSimpleLineClass *class) { + GObjectClass *gobject_class; GtkObjectClass *object_class; GnomeCanvasItemClass *item_class; + gobject_class = (GObjectClass *) class; object_class = (GtkObjectClass *) class; item_class = (GnomeCanvasItemClass *) class; - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - gtk_object_add_arg_type ("GnomeCanvasSimpleLine::x1", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X1); - gtk_object_add_arg_type ("GnomeCanvasSimpleLine::y1", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y1); - gtk_object_add_arg_type ("GnomeCanvasSimpleLine::x2", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X2); - gtk_object_add_arg_type ("GnomeCanvasSimpleLine::y2", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y2); - gtk_object_add_arg_type ("GnomeCanvasSimpleLine::color_rgba", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_COLOR_RGBA); - - object_class->set_arg = gnome_canvas_simpleline_set_arg; - object_class->get_arg = gnome_canvas_simpleline_get_arg; + parent_class = g_type_class_peek_parent (class); + + gobject_class->set_property = gnome_canvas_simpleline_set_property; + gobject_class->get_property = gnome_canvas_simpleline_get_property; + + g_object_class_install_property (gobject_class, + PROP_X1, + g_param_spec_double ("x1", + _("x1"), + _("x coordinate of upper left corner of rect"), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, + PROP_Y1, + g_param_spec_double ("y1", + _("y1"), + _("y coordinate of upper left corner of rect "), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + G_PARAM_READWRITE)); + + + g_object_class_install_property (gobject_class, + PROP_X2, + g_param_spec_double ("x2", + _("x2"), + _("x coordinate of lower right corner of rect"), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, + PROP_Y2, + g_param_spec_double ("y2", + _("y2"), + _("y coordinate of lower right corner of rect "), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, + PROP_COLOR_RGBA, + g_param_spec_uint ("color_rgba", + _("color rgba"), + _("color of line"), + 0, + G_MAXUINT, + 0, + G_PARAM_READWRITE)); + + object_class->destroy = gnome_canvas_simpleline_destroy; item_class->update = gnome_canvas_simpleline_update; item_class->bounds = gnome_canvas_simpleline_bounds; @@ -91,8 +173,20 @@ gnome_canvas_simpleline_init (GnomeCanvasSimpleLine *simpleline) simpleline->y2 = 0.0; simpleline->color = RGBA_TO_UINT(98,123,174,241); simpleline->horizontal = TRUE; /* reset in the _update() method */ - // GTK2FIX - // GNOME_CANVAS_ITEM(simpleline)->object.flags |= GNOME_CANVAS_ITEM_NO_AUTO_REDRAW; +} + +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 @@ -110,7 +204,7 @@ gnome_canvas_simpleline_bounds_world (GnomeCanvasItem *item, int* ix1, int* iy1, 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); @@ -131,7 +225,7 @@ gnome_canvas_simpleline_bounds_world (GnomeCanvasItem *item, int* ix1, int* iy1, } } -static void +static void gnome_canvas_simpleline_reset_bounds (GnomeCanvasItem *item) { int Ix1, Ix2, Iy1, Iy2; @@ -140,102 +234,102 @@ gnome_canvas_simpleline_reset_bounds (GnomeCanvasItem *item) gnome_canvas_update_bbox (item, Ix1, Iy1, Ix2, Iy2); } -/* - * CANVAS CALLBACKS +/* + * CANVAS CALLBACKS */ static void -gnome_canvas_simpleline_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) +gnome_canvas_simpleline_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) + { - GnomeCanvasItem *item; + (void) pspec; + GnomeCanvasSimpleLine *simpleline; - int redraw; - int calc_bounds; + int update = FALSE; + int bounds_changed = FALSE; - item = GNOME_CANVAS_ITEM (object); - simpleline = GNOME_CANVAS_SIMPLELINE (object); + g_return_if_fail (object != NULL); + g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object)); - redraw = FALSE; - calc_bounds = FALSE; + simpleline = GNOME_CANVAS_SIMPLELINE (object); - switch (arg_id) { - case ARG_X1: - if (simpleline->x1 != GTK_VALUE_DOUBLE (*arg)) { - simpleline->x1 = GTK_VALUE_DOUBLE (*arg); - calc_bounds = TRUE; + switch (prop_id) { + case PROP_X1: + if (simpleline->x1 != g_value_get_double (value)) { + simpleline->x1 = g_value_get_double (value); + bounds_changed = TRUE; } break; - case ARG_Y1: - if (simpleline->y1 != GTK_VALUE_DOUBLE (*arg)) { - simpleline->y1 = GTK_VALUE_DOUBLE (*arg); - calc_bounds = TRUE; + case PROP_Y1: + if (simpleline->y1 != g_value_get_double (value)) { + simpleline->y1 = g_value_get_double (value); + bounds_changed = TRUE; } break; - case ARG_X2: - if (simpleline->x2 != GTK_VALUE_DOUBLE (*arg)) { - simpleline->x2 = GTK_VALUE_DOUBLE (*arg); - calc_bounds = TRUE; + case PROP_X2: + if (simpleline->x2 != g_value_get_double (value)) { + simpleline->x2 = g_value_get_double (value); + bounds_changed = TRUE; } break; - case ARG_Y2: - if (simpleline->y2 != GTK_VALUE_DOUBLE (*arg)) { - simpleline->y2 = GTK_VALUE_DOUBLE (*arg); - calc_bounds = TRUE; + case PROP_Y2: + if (simpleline->y2 != g_value_get_double (value)) { + simpleline->y2 = g_value_get_double (value); + bounds_changed = TRUE; } break; - case ARG_COLOR_RGBA: - if (simpleline->color != GTK_VALUE_INT(*arg)) { - simpleline->color = GTK_VALUE_INT(*arg); + case PROP_COLOR_RGBA: + if (simpleline->color != g_value_get_uint(value)) { + simpleline->color = g_value_get_uint(value); UINT_TO_RGBA (simpleline->color, &simpleline->r, &simpleline->g, &simpleline->b, &simpleline->a); - redraw = TRUE; + update = TRUE; } break; - default: break; } - - if (calc_bounds) { - gnome_canvas_item_request_update (item); - - } else if (redraw) { - - int Ix1, Ix2, Iy1, Iy2; - gnome_canvas_simpleline_bounds_world (item, &Ix1, &Iy1, &Ix2, &Iy2); - gnome_canvas_request_redraw (item->canvas, Ix1, Iy1, Ix2, Iy2); + if (update || bounds_changed) { + gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(object)); } } static void -gnome_canvas_simpleline_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +gnome_canvas_simpleline_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - GnomeCanvasSimpleLine *simpleline; + g_return_if_fail (object != NULL); + g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object)); - simpleline = GNOME_CANVAS_SIMPLELINE (object); + GnomeCanvasSimpleLine *line = GNOME_CANVAS_SIMPLELINE (object); - switch (arg_id) { - case ARG_X1: - GTK_VALUE_DOUBLE (*arg) = simpleline->x1; + switch (prop_id) { + case PROP_X1: + g_value_set_double (value, line->x1); break; - case ARG_Y1: - GTK_VALUE_DOUBLE (*arg) = simpleline->y1; + case PROP_X2: + g_value_set_double (value, line->x2); break; - case ARG_X2: - GTK_VALUE_DOUBLE (*arg) = simpleline->x2; + case PROP_Y1: + g_value_set_double (value, line->y1); break; - case ARG_Y2: - GTK_VALUE_DOUBLE (*arg) = simpleline->y2; + case PROP_Y2: + g_value_set_double (value, line->y2); break; - case ARG_COLOR_RGBA: - GTK_VALUE_INT (*arg) = simpleline->color; + case PROP_COLOR_RGBA: + g_value_set_uint (value, line->color); break; default: - arg->type = GTK_TYPE_INVALID; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } @@ -285,18 +379,18 @@ gnome_canvas_simpleline_render (GnomeCanvasItem *item, buf->is_bg = FALSE; } - // begin = MAX(simpleline->bbox_ulx,buf->rect.x0); - // end = MIN(simpleline->bbox_lrx,buf->rect.x1); - + //begin = MAX(simpleline->bbox_ulx,buf->rect.x0); + //end = MIN(simpleline->bbox_lrx,buf->rect.x1); + begin = simpleline->bbox_ulx; end = simpleline->bbox_lrx; if (simpleline->color != 0) { if (simpleline->horizontal) { - PAINT_HORIZA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a, + 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, + PAINT_VERTA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a, begin, simpleline->bbox_uly, simpleline->bbox_lry); } } @@ -309,15 +403,54 @@ gnome_canvas_simpleline_draw (GnomeCanvasItem *item, int width, int height) { GnomeCanvasSimpleLine *simpleline; + cairo_t* cr; + double ulx; + double uly; + double lrx; + double lry; simpleline = GNOME_CANVAS_SIMPLELINE (item); - if (parent_class->draw) { - (* parent_class->draw) (item, drawable, x, y, width, height); + cr = gdk_cairo_create (drawable); + + if (x > simpleline->bbox_ulx) { + ulx = x; + } else { + ulx = simpleline->bbox_ulx; + } + + if (y > simpleline->bbox_uly) { + uly = y; + } else { + uly = simpleline->bbox_uly; } - fprintf (stderr, "please don't use the CanvasSimpleLine item in a non-aa Canvas\n"); - abort (); + if (x + width > simpleline->bbox_lrx) { + lrx = simpleline->bbox_lrx; + } else { + lrx = x + width; + } + + 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 @@ -334,6 +467,9 @@ gnome_canvas_simpleline_bounds (GnomeCanvasItem *item, double *x1, double *y1, d static double gnome_canvas_simpleline_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item) { + (void) cx; + (void) cy; + GnomeCanvasSimpleLine *simpleline; double x1, y1, x2, y2; double dx, dy; @@ -342,17 +478,17 @@ gnome_canvas_simpleline_point (GnomeCanvasItem *item, double x, double y, int cx *actual_item = item; - /* Find the bounds for the rectangle plus its outline width */ + /* Find the bounds for the line plus its outline width */ gnome_canvas_simpleline_bounds (item, &x1, &y1, &x2, &y2); - /* Is point inside rectangle */ - + /* Is point inside line */ + if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) { return 0.0; } - /* Point is outside rectangle */ + /* Point is outside line */ if (x < x1) dx = x1 - x;