add JAG to author list
[ardour.git] / gtk2_ardour / canvas-simplerect.c
index d59096e68b40279d28139eedd078b2399077f69b..91649b64bbca6f2f7ed7ecc2c3ad660b7ecb8584 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <math.h>
+#include <cairo.h>
 #include <libgnomecanvas/libgnomecanvas.h>
 
 #include "canvas-simplerect.h"
@@ -257,19 +258,20 @@ gnome_canvas_simplerect_bounds (GnomeCanvasItem *item, double *x1, double *y1, d
 
 }
 
+
 static void 
 gnome_canvas_simplerect_reset_bounds (GnomeCanvasItem *item)
 {
        GnomeCanvasSimpleRect* simplerect;
        double x1, x2, y1, y2;
        double old_x1, old_x2, old_y1, old_y2;
-       double a, b, c, d;
-       
+       ArtDRect unionrect, old, new;
+
        old_x1 = item->x1;
        old_y1 = item->y1;
        old_x2 = item->x2;
        old_y2 = item->y2;
-
+       
        gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
        gnome_canvas_item_i2w (item, &x1, &y1);
        gnome_canvas_item_i2w (item, &x2, &y2);
@@ -286,25 +288,75 @@ gnome_canvas_simplerect_reset_bounds (GnomeCanvasItem *item)
        gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simplerect->bbox_ulx, &simplerect->bbox_uly);
        gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simplerect->bbox_lrx, &simplerect->bbox_lry);
 
-       /* now queue redraws for changed areas */
-               
-               a = MIN(item->x1, old_x1); 
-               b = MAX(item->x1, old_x1);
+        /* now queue redraws for changed areas */
+
+       if (item->x1 == old_x1 && item->x2 == old_x2) {
+
+               /* no change in x-axis position */
+
+               if (item->y1 == old_y1) {
+                       /* top didn't change, so just draw bottom */
+
+                       double start_y = MIN (item->y2, old_y2);
+                       double end_y = MAX (item->y2, old_y2);
+
+                       gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
+                       return;
+
+               } else if (item->y2 == old_y2) {
+
+                       /* bottom didn't change, just draw top */
+
+                       double start_y = MIN (item->y1, old_y1);
+                       double end_y = MAX (item->y1, old_y1);
+
+                       gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
+                       return;
+
+               }
+
+       } else if (item->y1 == old_y1 && item->y2 == old_y2) {
+
+               /* no change in y-axis position */
+
+               if (item->x1 == old_x1) {
+                       /* start didn't change, so just draw at the end */
 
-               a = MIN(a, item->x2);
-               a = MIN(a, old_x2);
-               b = MAX(b, item->x2);
-               b = MAX(b, old_x2);
+                       double start_x = MIN (item->x2, old_x2);
+                       double end_x = MAX (item->x2, old_x2);
 
-               c = MIN(item->y1, old_y1);
-               d = MAX(item->y1, old_y1);
+                       gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2);
+                       return;
 
-               c = MIN(c,item->y2);
-               c = MIN(c, old_y2);
-               d = MAX(d,item->y2);
-               d = MAX(d, old_y2);
+               } else if (item->x2 == old_x2) {
 
-               gnome_canvas_request_redraw (item->canvas, a, c, b + 0.5, d + 0.5);
+                       /* end didn't change, so just draw at the start */
+                       
+                       double start_x = MIN (item->x1, old_x1);
+                       double end_x = MAX (item->x1, old_x1);
+
+                       gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2 + 0.5);
+                       return;
+
+               }
+       } 
+
+       new.x0 = x1;
+       new.y0 = y1;
+       new.x1 = x2;
+       new.y1 = y2;
+
+       old.x0 = old_x1;
+       old.y0 = old_y1;
+       old.x1 = old_x2;
+       old.y1 = old_y2;
+
+       art_drect_union (&unionrect, &old, &new);
+       gnome_canvas_request_redraw (item->canvas, 
+                                    unionrect.x0 - 0.5,
+                                    unionrect.y0 - 0.5,
+                                    unionrect.x1 + 1.5,
+                                    unionrect.y1 + 1.5);
 }
 
 /* 
@@ -509,7 +561,7 @@ gnome_canvas_simplerect_render (GnomeCanvasItem *item,
        if (parent_class->render) {
                (*parent_class->render) (item, buf);
        }
-
+       
        if (buf->is_bg) {
 
 #ifdef HARLEQUIN_DEBUGGING
@@ -663,12 +715,111 @@ gnome_canvas_simplerect_render (GnomeCanvasItem *item,
 
 static void
 gnome_canvas_simplerect_draw (GnomeCanvasItem *item,
-                           GdkDrawable *drawable,
-                           int x, int y,
-                           int width, int height)
+                             GdkDrawable *drawable,
+                             int x, int y,
+                             int width, int height)
 {
-       fprintf (stderr, "please don't use the CanvasSimpleRect item in a non-aa Canvas\n");
-       abort ();
+       GnomeCanvasSimpleRect *simplerect;
+       cairo_t* cr;
+       double ulx;
+       double uly;
+       double lrx;
+       double lry;
+
+       simplerect = GNOME_CANVAS_SIMPLERECT (item);
+
+       cr = gdk_cairo_create (drawable);       
+
+       if (x > simplerect->bbox_ulx) {
+               ulx = x;
+       } else {
+               ulx = simplerect->bbox_ulx;
+       }
+
+       if (y > simplerect->bbox_uly) {
+               uly = y;
+       } else {
+               uly = simplerect->bbox_uly;
+       }
+
+       if (x + width > simplerect->bbox_lrx) {
+               lrx = simplerect->bbox_lrx;
+       } else {
+               lrx = x + width;
+       }
+
+       if (y + height > simplerect->bbox_lry) {
+               lry = simplerect->bbox_lry;
+       } else {
+               lry = y + height;
+       }
+
+       ulx -= x;
+       uly -= y;
+       lrx -= x;
+       lry -= y;
+
+       cairo_rectangle (cr, ulx, uly, lrx - ulx, lry - uly);
+
+       if (simplerect->fill) {
+               cairo_set_source_rgba (cr,
+                                      simplerect->fill_r/255.0, 
+                                      simplerect->fill_g/255.0, 
+                                      simplerect->fill_b/255.0, 
+                                      simplerect->fill_a/255.0);
+               cairo_fill (cr);
+       }
+       
+       if (simplerect->outline_what && simplerect->outline_pixels) {
+
+#define x_in_range(a) (x <= (a) && (a) < x + width)
+#define y_in_range(a) (y <= (a) && (a) < y + height)
+
+               cairo_set_line_width (cr, simplerect->outline_pixels);
+               
+               cairo_set_source_rgb (cr,
+                                     simplerect->outline_r/255.0, 
+                                     simplerect->outline_g/255.0, 
+                                     simplerect->outline_b/255.0);
+
+               if (simplerect->outline_what & 0x1) {
+                       /* left edge, if visible */
+                       if (x_in_range (simplerect->bbox_ulx)) {
+                               cairo_move_to (cr, ulx+0.5, uly+0.5);
+                               cairo_line_to (cr, ulx+0.5, lry+0.5);
+                               cairo_stroke (cr);
+                       }
+               }
+               
+               if (simplerect->outline_what & 0x2) {
+                       /* right edge, if visible */
+                       if (x_in_range (simplerect->bbox_lrx)) {
+                               cairo_move_to (cr, lrx+0.5, uly+0.5);
+                               cairo_line_to (cr, lrx+0.5, lry+0.5);
+                               cairo_stroke (cr);
+                       }
+               }
+               
+               if (simplerect->outline_what & 0x4) {
+                       /* top edge */
+                       if (y_in_range (simplerect->bbox_uly)) {
+                               cairo_move_to (cr, ulx+0.5, uly+0.5);
+                               cairo_line_to (cr, lrx+0.5, uly+0.5);
+                               cairo_stroke (cr);
+                       }
+               }
+               
+               if (simplerect->outline_what & 0x8) {
+                       /* bottom edge */
+                       if (y_in_range (simplerect->bbox_lry)) {
+                               cairo_move_to (cr, ulx+0.5, lry+0.5);
+                               cairo_line_to (cr, lrx+0.5, lry+0.5);
+                               cairo_stroke (cr);
+                       }
+               }
+       }
+
+       cairo_destroy (cr);
 }
 
 static double