add GPROFILE scons option; fix spectacular CPU usage sawtooth caused by constant...
[ardour.git] / gtk2_ardour / canvas-simplerect.c
1 #include <stdio.h>
2 #include <math.h>
3 #include <libgnomecanvas/libgnomecanvas.h>
4
5 #include "canvas-simplerect.h"
6 #include "rgb_macros.h"
7 #include "gettext.h"
8 #define _(Text)  dgettext (PACKAGE,Text)
9
10 enum {
11         PROP_0,
12         PROP_X1,
13         PROP_Y1,
14         PROP_X2,
15         PROP_Y2,
16         PROP_OUTLINE_PIXELS,
17         PROP_OUTLINE_WHAT,
18         PROP_FILL,
19         PROP_FILL_COLOR_RGBA,
20         PROP_OUTLINE_COLOR_RGBA,
21         PROP_DRAW
22         
23 };
24
25 static void   gnome_canvas_simplerect_class_init    (GnomeCanvasSimpleRectClass *class);
26
27 static void   gnome_canvas_simplerect_init          (GnomeCanvasSimpleRect      *simplerect);
28
29 static void   gnome_canvas_simplerect_destroy       (GtkObject                  *object);
30
31 static void   gnome_canvas_simplerect_set_property  (GObject        *object,
32                                                      guint            prop_id,
33                                                      const GValue   *value,
34                                                      GParamSpec     *pspec);
35
36 static void   gnome_canvas_simplerect_get_property  (GObject        *object,
37                                                      guint           prop_id,
38                                                      GValue         *value,
39                                                      GParamSpec     *pspec);
40
41 static void   gnome_canvas_simplerect_update        (GnomeCanvasItem *item,
42                                                      double          *affine,
43                                                      ArtSVP          *clip_path,
44                                                      int              flags);
45
46 static void   gnome_canvas_simplerect_bounds        (GnomeCanvasItem *item,
47                                                      double          *x1,
48                                                      double          *y1,
49                                                      double          *x2,
50                                                      double          *y2);
51
52 static double gnome_canvas_simplerect_point         (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item);
53
54 static void   gnome_canvas_simplerect_render        (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
55
56 static void   gnome_canvas_simplerect_draw          (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w, int h);
57
58 static GnomeCanvasItemClass *parent_class;
59
60
61 GType
62 gnome_canvas_simplerect_get_type (void)
63 {
64         static GType simplerect_type;
65
66         if (!simplerect_type) {
67                 static const GTypeInfo object_info = {
68                         sizeof (GnomeCanvasSimpleRectClass),
69                         (GBaseInitFunc) NULL,
70                         (GBaseFinalizeFunc) NULL,
71                         (GClassInitFunc) gnome_canvas_simplerect_class_init,
72                         (GClassFinalizeFunc) NULL,
73                         NULL,                   /* class_data */
74                         sizeof (GnomeCanvasSimpleRect),
75                         0,                      /* n_preallocs */
76                         (GInstanceInitFunc) gnome_canvas_simplerect_init,
77                         NULL                    /* value_table */
78                 };
79
80                 simplerect_type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM, "GnomeCanvasSimpleRect",
81                                                           &object_info, 0);
82         }
83
84         return simplerect_type;
85 }
86
87 static void
88 gnome_canvas_simplerect_class_init (GnomeCanvasSimpleRectClass *class)
89 {
90         GObjectClass *gobject_class;
91         GtkObjectClass *object_class;
92         GnomeCanvasItemClass *item_class;
93
94         gobject_class = (GObjectClass *) class;
95         object_class = (GtkObjectClass *) class;
96         item_class = (GnomeCanvasItemClass *) class;
97         
98         parent_class = g_type_class_peek_parent (class);
99
100         gobject_class->set_property = gnome_canvas_simplerect_set_property;
101         gobject_class->get_property = gnome_canvas_simplerect_get_property;
102         
103         g_object_class_install_property (gobject_class,
104                                          PROP_X1,
105                                          g_param_spec_double ("x1",
106                                                               _("x1"),
107                                                               _("x coordinate of upper left corner of rect"),
108                                                               -G_MAXDOUBLE,
109                                                               G_MAXDOUBLE,
110                                                               0.0,
111                                                               G_PARAM_READWRITE));  
112         
113         g_object_class_install_property (gobject_class,
114                                          PROP_Y1,
115                                          g_param_spec_double ("y1",
116                                                               _("y1"),
117                                                               _("y coordinate of upper left corner of rect "),
118                                                               -G_MAXDOUBLE,
119                                                               G_MAXDOUBLE,
120                                                               0.0,
121                                                               G_PARAM_READWRITE));  
122         
123
124         g_object_class_install_property (gobject_class,
125                                          PROP_X2,
126                                          g_param_spec_double ("x2",
127                                                               _("x2"),
128                                                               _("x coordinate of lower right corner of rect"),
129                                                               -G_MAXDOUBLE,
130                                                               G_MAXDOUBLE,
131                                                               0.0,
132                                                               G_PARAM_READWRITE));  
133         
134         g_object_class_install_property (gobject_class,
135                                          PROP_Y2,
136                                          g_param_spec_double ("y2",
137                                                               _("y2"),
138                                                               _("y coordinate of lower right corner of rect "),
139                                                               -G_MAXDOUBLE,
140                                                               G_MAXDOUBLE,
141                                                               0.0,
142                                                               G_PARAM_READWRITE));  
143         
144
145         g_object_class_install_property (gobject_class,
146                                          PROP_OUTLINE_PIXELS,
147                                          g_param_spec_uint ("outline_pixels",
148                                                               _("outline pixels"),
149                                                               _("width in pixels of outline"),
150                                                               0,
151                                                               G_MAXUINT,
152                                                               0,
153                                                               G_PARAM_READWRITE));  
154         
155
156         g_object_class_install_property (gobject_class,
157                                          PROP_OUTLINE_WHAT,
158                                          g_param_spec_uint ("outline_what",
159                                                               _("outline what"),
160                                                               _("which boundaries to outline (mask)"),
161                                                               0,
162                                                               G_MAXUINT,
163                                                               0,
164                                                               G_PARAM_READWRITE));  
165         
166
167
168         g_object_class_install_property (gobject_class,
169                                          PROP_FILL,
170                                          g_param_spec_boolean ("fill",
171                                                                _("fill"),
172                                                                _("fill rectangle"),
173                                                                TRUE,
174                                                                G_PARAM_READWRITE));  
175         
176         g_object_class_install_property (gobject_class,
177                                          PROP_DRAW,
178                                          g_param_spec_boolean ("draw",
179                                                                _("draw"),
180                                                                _("draw rectangle"),
181                                                                TRUE,
182                                                                G_PARAM_READWRITE));  
183         
184
185         g_object_class_install_property (gobject_class,
186                                          PROP_OUTLINE_COLOR_RGBA,
187                                          g_param_spec_uint ("outline_color_rgba",
188                                                             _("outline color rgba"),
189                                                             _("color of outline"),
190                                                             0,
191                                                             G_MAXUINT,
192                                                             0,
193                                                             G_PARAM_READWRITE));  
194         
195
196         g_object_class_install_property (gobject_class,
197                                          PROP_FILL_COLOR_RGBA,
198                                          g_param_spec_uint ("fill_color_rgba",
199                                                             _("fill color rgba"),
200                                                             _("color of fill"),
201                                                             0,
202                                                             G_MAXUINT,
203                                                             0,
204                                                             G_PARAM_READWRITE));  
205
206         object_class->destroy = gnome_canvas_simplerect_destroy;
207
208         item_class->update = gnome_canvas_simplerect_update;
209         item_class->draw = gnome_canvas_simplerect_draw;
210         item_class->bounds = gnome_canvas_simplerect_bounds;
211         item_class->point = gnome_canvas_simplerect_point;
212         item_class->render = gnome_canvas_simplerect_render;
213
214 }
215
216 static void
217 gnome_canvas_simplerect_init (GnomeCanvasSimpleRect *simplerect)
218 {
219         simplerect->x1 = 0.0;
220         simplerect->y1 = 0.0;
221         simplerect->x2 = 0.0;
222         simplerect->y2 = 0.0;
223         simplerect->fill = TRUE;
224         simplerect->draw = TRUE;
225         simplerect->full_draw_on_update = TRUE;
226         simplerect->fill_color = 0;
227         simplerect->outline_color = 0;
228         simplerect->outline_pixels = 1;
229         simplerect->outline_what = 0xf;
230 }
231
232 static void
233 gnome_canvas_simplerect_destroy (GtkObject *object)
234 {
235         GnomeCanvasSimpleRect *rect;
236         
237         g_return_if_fail (object != NULL);
238         g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
239
240         rect = GNOME_CANVAS_SIMPLERECT (object);
241
242         /* remember, destroy can be run multiple times! */
243
244         if (GTK_OBJECT_CLASS (parent_class)->destroy)
245               (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
246 }
247
248 static void
249 gnome_canvas_simplerect_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
250 {
251         GnomeCanvasSimpleRect *simplerect = GNOME_CANVAS_SIMPLERECT (item);
252
253         *x1 = simplerect->x1;
254         *y1 = simplerect->y1;
255         *x2 = simplerect->x2 + 1;
256         *y2 = simplerect->y2 + 1;
257
258 }
259
260 static void 
261 gnome_canvas_simplerect_reset_bounds (GnomeCanvasItem *item)
262 {
263         GnomeCanvasSimpleRect* simplerect;
264         double x1, x2, y1, y2;
265         double old_x1, old_x2, old_y1, old_y2;
266         double a, b, c, d;
267         ArtIRect intersection, old, new;
268
269         old.x0 = old_x1 = item->x1;
270         old.y0 = old_y1 = item->y1;
271         old.x1 = old_x2 = item->x2;
272         old.y1 = old_y2 = item->y2;
273
274         new.x0 = x1;
275         new.y0 = y1;
276         new.x1 = x2;
277         new.y1 = y2;
278
279         gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
280         gnome_canvas_item_i2w (item, &x1, &y1);
281         gnome_canvas_item_i2w (item, &x2, &y2);
282
283         item->x1 = x1;
284         item->y1 = y1;
285         item->x2 = x2;
286         item->y2 = y2;
287
288         /* now compute bounding box in canvas units */
289
290         simplerect = GNOME_CANVAS_SIMPLERECT (item);
291
292         gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simplerect->bbox_ulx, &simplerect->bbox_uly);
293         gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simplerect->bbox_lrx, &simplerect->bbox_lry);
294
295         /* now queue redraws for changed areas */
296                 
297         art_irect_intersect (&intersection, &old, &new);
298 #if 0
299                 a = MIN(item->x1, old_x1); 
300                 b = MAX(item->x1, old_x1);
301
302                 a = MIN(a, item->x2);
303                 a = MIN(a, old_x2);
304                 b = MAX(b, item->x2);
305                 b = MAX(b, old_x2);
306
307                 c = MIN(item->y1, old_y1);
308                 d = MAX(item->y1, old_y1);
309
310                 c = MIN(c,item->y2);
311                 c = MIN(c, old_y2);
312                 d = MAX(d,item->y2);
313                 d = MAX(d, old_y2);
314
315                 fprintf (stderr, "%p REDRAW %g,%g %g,%g\n", simplerect, a, c, b + 0.5, d + 0.5);
316                 gnome_canvas_request_redraw (item->canvas, a, c, b + 0.5, d + 0.5);
317 #else 
318                 gnome_canvas_request_redraw (item->canvas, 
319                                              intersection.x0,
320                                              intersection.y0,
321                                              intersection.x1,
322                                              intersection.y1);
323 #endif
324 }
325
326 /* 
327  * CANVAS CALLBACKS 
328  */
329
330 static void
331 gnome_canvas_simplerect_set_property (GObject      *object,
332                                       guint         prop_id,
333                                       const GValue *value,
334                                       GParamSpec   *pspec)
335
336 {
337         GnomeCanvasSimpleRect *simplerect;
338         int update = FALSE;
339         int bounds_changed = FALSE;
340         g_return_if_fail (object != NULL);
341         g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
342
343         simplerect = GNOME_CANVAS_SIMPLERECT (object);
344
345         switch (prop_id) {
346         case PROP_X1:
347                 if (simplerect->x1 != g_value_get_double (value)) {
348                         simplerect->x1 = g_value_get_double (value);
349                         bounds_changed = TRUE;
350                 }
351                 break;
352
353         case PROP_Y1:
354                 if (simplerect->y1 != g_value_get_double (value)) {
355                         simplerect->y1 = g_value_get_double (value);
356                         bounds_changed = TRUE;
357                 }
358                 break;
359
360         case PROP_X2:
361                 if (simplerect->x2 != g_value_get_double (value)) {
362                         simplerect->x2 = g_value_get_double (value);
363                         bounds_changed = TRUE;
364                 }
365                 break;
366
367         case PROP_Y2:
368                 if (simplerect->y2 != g_value_get_double (value)) {
369                         simplerect->y2 = g_value_get_double (value);
370                         bounds_changed = TRUE;
371                 }
372                 break;
373
374         case PROP_DRAW:
375                 if (simplerect->draw != g_value_get_boolean (value)) {
376                         simplerect->draw = g_value_get_boolean (value);
377                         update = TRUE;
378                 }
379                 break;
380
381
382         case PROP_FILL:
383                 if (simplerect->fill != g_value_get_boolean (value)) {
384                         simplerect->fill = g_value_get_boolean (value);
385                         update = TRUE;
386                 }
387                 break;
388
389         case PROP_FILL_COLOR_RGBA:
390                 if (simplerect->fill_color != g_value_get_uint(value)) {
391                         simplerect->fill_color = g_value_get_uint(value);
392                         update = TRUE;
393                 }
394                 break;
395
396         case PROP_OUTLINE_COLOR_RGBA:
397                 if (simplerect->outline_color != g_value_get_uint(value)) {
398                         simplerect->outline_color = g_value_get_uint(value);
399                         update = TRUE;
400                 }
401                 break;
402
403         case PROP_OUTLINE_PIXELS:
404                 if (simplerect->outline_pixels != g_value_get_uint(value)) {
405                         simplerect->outline_pixels = g_value_get_uint(value);
406                         update = TRUE;
407                 }
408                 break;
409
410         case PROP_OUTLINE_WHAT:
411                 if (simplerect->outline_what != g_value_get_uint(value)) {
412                         simplerect->outline_what = g_value_get_uint(value);
413                         update = TRUE;
414                 }
415                 break;
416
417         default:
418                 break;
419         }
420
421         simplerect->full_draw_on_update = update;
422
423         if (update || bounds_changed) {
424                 gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(object));
425         }
426 }
427
428 static void
429 gnome_canvas_simplerect_get_property (GObject      *object,
430                                       guint         prop_id,
431                                       GValue       *value,
432                                       GParamSpec   *pspec)
433 {
434         GnomeCanvasSimpleRect *rect = GNOME_CANVAS_SIMPLERECT (object);
435         
436         g_return_if_fail (object != NULL);
437         g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
438
439         switch (prop_id) {
440         case PROP_X1:
441                 g_value_set_double (value, rect->x1);
442                 break;
443         case PROP_X2:
444                 g_value_set_double (value, rect->x2);
445                 break;
446         case PROP_Y1:
447                 g_value_set_double (value, rect->y1);
448                 break;
449         case PROP_Y2:
450                 g_value_set_double (value, rect->y2);
451                 break;
452         case PROP_OUTLINE_WHAT:
453                 g_value_set_uint (value, rect->outline_what);
454                 break;
455         case PROP_FILL:
456                 g_value_set_boolean (value, rect->fill);
457                 break;
458         case PROP_OUTLINE_PIXELS:
459                 g_value_set_uint (value, rect->outline_pixels);
460                 break;
461         case PROP_FILL_COLOR_RGBA:
462                 g_value_set_uint (value, rect->fill_color);
463                 break;
464         case PROP_OUTLINE_COLOR_RGBA:
465                 g_value_set_uint (value, rect->outline_color);
466                 break;
467         case PROP_DRAW:
468                 g_value_set_boolean (value, rect->draw);
469                 break;
470                 
471         default:
472                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
473                 break;
474         }
475 }
476
477
478 static void
479 gnome_canvas_simplerect_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
480 {
481         GnomeCanvasSimpleRect *simplerect;
482         unsigned char foo;
483
484         simplerect = GNOME_CANVAS_SIMPLERECT (item);
485
486         if (parent_class->update)
487                 (* parent_class->update) (item, affine, clip_path, flags);
488
489         gnome_canvas_simplerect_reset_bounds (item);
490
491         if (simplerect->full_draw_on_update) {
492                 gnome_canvas_request_redraw (item->canvas, 
493                                            simplerect->bbox_ulx,
494                                            simplerect->bbox_uly,
495                                            simplerect->bbox_lrx+0.5,
496                                            simplerect->bbox_lry+0.5);
497                 simplerect->full_draw_on_update = FALSE;
498         }
499
500         UINT_TO_RGBA (simplerect->fill_color, &simplerect->fill_r, &simplerect->fill_g, &simplerect->fill_b, &simplerect->fill_a);
501         UINT_TO_RGBA (simplerect->outline_color, &simplerect->outline_r, &simplerect->outline_g, &simplerect->outline_b, &foo);
502 }
503
504 // this can be useful for debugging/understanding how the canvas redraws
505 // stuff.
506
507 #undef HARLEQUIN_DEBUGGING
508
509 #undef SIMPLERECT_FAST_RENDERER
510 #ifdef SIMPLERECT_FAST_RENDERER
511
512 static void
513 gnome_canvas_simplerect_render (GnomeCanvasItem *item,
514                               GnomeCanvasBuf *buf)
515 {
516         GnomeCanvasSimpleRect *simplerect;
517         int end, begin;
518         int ey, sy;
519         unsigned int i;
520         ArtIRect intersection;
521         ArtIRect self;
522
523         simplerect = GNOME_CANVAS_SIMPLERECT (item);
524
525         if (parent_class->render) {
526                 (*parent_class->render) (item, buf);
527         }
528         
529         if (buf->is_bg) {
530
531 #ifdef HARLEQUIN_DEBUGGING
532                 gint randr, randg, randb;
533                 randr = random() % 255;
534                 randg = random() % 255;
535                 randb = random() % 255;
536                 PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
537 #endif
538                 gnome_canvas_buf_ensure_buf (buf);
539                 buf->is_bg = FALSE;
540         }
541
542         if (!simplerect->draw) {
543                 return;
544         }
545         
546         self.x0 = simplerect->bbox_ulx;
547         self.y0 = simplerect->bbox_uly;
548         self.x1 = simplerect->bbox_lrx;
549         self.y1 = simplerect->bbox_lry;
550
551         art_irect_intersect (&intersection, &self, &buf->rect);
552
553         begin = MAX(simplerect->bbox_ulx, buf->rect.x0);
554         end = MIN((simplerect->bbox_lrx-1), buf->rect.x1);
555
556         sy = simplerect->bbox_uly;
557         ey = simplerect->bbox_lry-1;
558
559         if (simplerect->fill) {
560                 
561                 // this can be useful for debugging/understanding how the canvas redraws
562                 // stuff.
563
564 #ifdef HARLEQUIN_DEBUGGING
565                 gint randr, randg, randb;
566                 randr = random() % 255;
567                 randg = random() % 255;
568                 randb = random() % 255;
569                 PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
570 #else           
571                 PAINT_BOX (buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a, 
572                            intersection.x0, intersection.y0,
573                            intersection.x1, intersection.y1);
574 #endif
575                 
576         }
577
578         for (i = 0; i < simplerect->outline_pixels; ++i) {
579
580                 if (simplerect->outline_what & 0x1) {
581                         if (begin == simplerect->bbox_ulx) {
582                                 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin + i, sy, ey);
583                         }
584                 }
585
586                 if (simplerect->outline_what & 0x2) {
587                         if (end == (simplerect->bbox_lrx - 1)) {
588                                 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, end - i, sy, ey + 1);
589                         }
590                 }
591
592                 if (simplerect->outline_what & 0x4) {
593                         PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end, sy+i);
594                 }
595         
596                 if (simplerect->outline_what & 0x8) {
597                         PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end + 1, ey-i);
598                 }
599         }
600 }
601
602 #else /* SIMPLERECT_FAST_RENDERER */
603
604 static void
605 gnome_canvas_simplerect_render (GnomeCanvasItem *item,
606                               GnomeCanvasBuf *buf)
607 {
608         GnomeCanvasSimpleRect *simplerect;
609         int end, begin;
610         int ey, sy;
611         unsigned int i;
612
613         simplerect = GNOME_CANVAS_SIMPLERECT (item);
614
615         if (parent_class->render) {
616                 (*parent_class->render) (item, buf);
617         }
618
619         if (buf->is_bg) {
620
621 #ifdef HARLEQUIN_DEBUGGING
622                 gint randr, randg, randb;
623                 randr = random() % 255;
624                 randg = random() % 255;
625                 randb = random() % 255;
626                 PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
627 #endif
628                 gnome_canvas_buf_ensure_buf (buf);
629                 buf->is_bg = FALSE;
630         }
631
632         if (!simplerect->draw) {
633                 return;
634         }
635
636         begin = MAX(simplerect->bbox_ulx,buf->rect.x0);
637         end = MIN((simplerect->bbox_lrx-1),buf->rect.x1);
638
639         sy = simplerect->bbox_uly;
640         ey = simplerect->bbox_lry-1;
641
642         if (simplerect->fill) {
643                 
644 #ifdef HARLEQUIN_DEBUGGING
645                 gint randr, randg, randb;
646                 randr = random() % 255;
647                 randg = random() % 255;
648                 randb = random() % 255;
649                 PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
650 #else           
651                 PAINT_BOX(buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a, begin, sy, end, ey);
652 #endif
653         }
654
655         for (i = 0; i < simplerect->outline_pixels; ++i) {
656
657                 if (simplerect->outline_what & 0x1) {
658                         if (begin == simplerect->bbox_ulx) {
659                                 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin + i, sy, ey);
660                         }
661                 }
662
663                 if (simplerect->outline_what & 0x2) {
664                         if (end == (simplerect->bbox_lrx - 1)) {
665                                 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, end - i, sy, ey + 1);
666                         }
667                 }
668
669                 if (simplerect->outline_what & 0x4) {
670                         PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end, sy+i);
671                 }
672         
673                 if (simplerect->outline_what & 0x8) {
674                         PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end + 1, ey-i);
675                 }
676         }
677 }
678 #endif /* SIMPLERECT_FAST_RENDERER */
679
680 static void
681 gnome_canvas_simplerect_draw (GnomeCanvasItem *item,
682                             GdkDrawable *drawable,
683                             int x, int y,
684                             int width, int height)
685 {
686         fprintf (stderr, "please don't use the CanvasSimpleRect item in a non-aa Canvas\n");
687         abort ();
688 }
689
690 static double
691 gnome_canvas_simplerect_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
692 {
693         GnomeCanvasSimpleRect *simplerect;
694         double x1, y1, x2, y2;
695         double dx, dy;
696
697         simplerect = GNOME_CANVAS_SIMPLERECT (item);
698
699         *actual_item = item;
700
701         /* Find the bounds for the rectangle plus its outline width */
702
703         gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
704
705         /* Is point inside rectangle */
706         
707         if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
708                 return 0.0;
709         }
710
711         /* Point is outside rectangle */
712
713         if (x < x1)
714                 dx = x1 - x;
715         else if (x > x2)
716                 dx = x - x2;
717         else
718                 dx = 0.0;
719
720         if (y < y1)
721                 dy = y1 - y;
722         else if (y > y2)
723                 dy = y - y2;
724         else
725                 dy = 0.0;
726
727         return sqrt (dx * dx + dy * dy);
728 }