* MIDI control lanes: Set Interpolationtype according to Parameter
[ardour.git] / gtk2_ardour / canvas-simpleline.c
index e776d46ca7b955411496de99734a1dfd1ad2ce3a..576eedc369855e7e4de9423080360ebcbcc16f96 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <math.h>
+#include <cairo.h>
 #include <libgnomecanvas/libgnomecanvas.h>
 
 #include "canvas-simpleline.h"
@@ -172,8 +173,6 @@ 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
@@ -182,7 +181,7 @@ gnome_canvas_simpleline_destroy (GtkObject *object)
        GnomeCanvasSimpleLine *line;
 
        g_return_if_fail (object != NULL);
-       g_return_if_fail (GNOME_IS_CANVAS_LINE (object));
+       g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object));
 
        line = GNOME_CANVAS_SIMPLELINE (object);
 
@@ -287,6 +286,7 @@ gnome_canvas_simpleline_set_property (GObject      *object,
        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);
                        update = TRUE;
                }
                break;
@@ -377,8 +377,8 @@ 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;
@@ -388,7 +388,7 @@ gnome_canvas_simpleline_render (GnomeCanvasItem *item,
                        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);
                }
        }
@@ -401,15 +401,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;
+       }
+
+       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;
        }
 
-       fprintf (stderr, "please don't use the CanvasSimpleLine item in a non-aa Canvas\n");
-       abort ();
+       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
@@ -434,17 +473,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;