fix for small thinko
[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         gobject_class->set_property = gnome_canvas_simplerect_set_property;
99         gobject_class->get_property = gnome_canvas_simplerect_get_property;
100         
101         g_object_class_install_property (gobject_class,
102                                          PROP_X1,
103                                          g_param_spec_double ("x1",
104                                                               _("x1"),
105                                                               _("x coordinate of upper left corner of rect"),
106                                                               -G_MAXDOUBLE,
107                                                               G_MAXDOUBLE,
108                                                               0.0,
109                                                               G_PARAM_READWRITE));  
110         
111         g_object_class_install_property (gobject_class,
112                                          PROP_Y1,
113                                          g_param_spec_double ("y1",
114                                                               _("y1"),
115                                                               _("y coordinate of upper left corner of rect "),
116                                                               -G_MAXDOUBLE,
117                                                               G_MAXDOUBLE,
118                                                               0.0,
119                                                               G_PARAM_READWRITE));  
120         
121
122         g_object_class_install_property (gobject_class,
123                                          PROP_X2,
124                                          g_param_spec_double ("x2",
125                                                               _("x2"),
126                                                               _("x coordinate of lower right corner of rect"),
127                                                               -G_MAXDOUBLE,
128                                                               G_MAXDOUBLE,
129                                                               0.0,
130                                                               G_PARAM_READWRITE));  
131         
132         g_object_class_install_property (gobject_class,
133                                          PROP_Y2,
134                                          g_param_spec_double ("y2",
135                                                               _("y2"),
136                                                               _("y coordinate of lower right corner of rect "),
137                                                               -G_MAXDOUBLE,
138                                                               G_MAXDOUBLE,
139                                                               0.0,
140                                                               G_PARAM_READWRITE));  
141         
142
143         g_object_class_install_property (gobject_class,
144                                          PROP_OUTLINE_PIXELS,
145                                          g_param_spec_uint ("outline_pixels",
146                                                               _("outline pixels"),
147                                                               _("width in pixels of outline"),
148                                                               0,
149                                                               G_MAXUINT,
150                                                               0,
151                                                               G_PARAM_READWRITE));  
152         
153
154         g_object_class_install_property (gobject_class,
155                                          PROP_OUTLINE_WHAT,
156                                          g_param_spec_uint ("outline_what",
157                                                               _("outline what"),
158                                                               _("which boundaries to outline (mask)"),
159                                                               0,
160                                                               G_MAXUINT,
161                                                               0,
162                                                               G_PARAM_READWRITE));  
163         
164
165
166         g_object_class_install_property (gobject_class,
167                                          PROP_FILL,
168                                          g_param_spec_boolean ("fill",
169                                                                _("fill"),
170                                                                _("fill rectangle"),
171                                                                TRUE,
172                                                                G_PARAM_READWRITE));  
173         
174         g_object_class_install_property (gobject_class,
175                                          PROP_DRAW,
176                                          g_param_spec_boolean ("draw",
177                                                                _("draw"),
178                                                                _("draw rectangle"),
179                                                                TRUE,
180                                                                G_PARAM_READWRITE));  
181         
182
183         g_object_class_install_property (gobject_class,
184                                          PROP_OUTLINE_COLOR_RGBA,
185                                          g_param_spec_uint ("outline_color_rgba",
186                                                             _("outline color rgba"),
187                                                             _("color of outline"),
188                                                             0,
189                                                             G_MAXUINT,
190                                                             0,
191                                                             G_PARAM_READWRITE));  
192         
193
194         g_object_class_install_property (gobject_class,
195                                          PROP_FILL_COLOR_RGBA,
196                                          g_param_spec_uint ("fill_color_rgba",
197                                                             _("fill color rgba"),
198                                                             _("color of fill"),
199                                                             0,
200                                                             G_MAXUINT,
201                                                             0,
202                                                             G_PARAM_READWRITE));  
203
204         object_class->destroy = gnome_canvas_simplerect_destroy;
205
206         item_class->update = gnome_canvas_simplerect_update;
207         item_class->draw = gnome_canvas_simplerect_draw;
208         item_class->bounds = gnome_canvas_simplerect_bounds;
209         item_class->point = gnome_canvas_simplerect_point;
210         item_class->render = gnome_canvas_simplerect_render;
211
212 }
213
214 static void
215 gnome_canvas_simplerect_init (GnomeCanvasSimpleRect *simplerect)
216 {
217         simplerect->x1 = 0.0;
218         simplerect->y1 = 0.0;
219         simplerect->x2 = 0.0;
220         simplerect->y2 = 0.0;
221         simplerect->fill = TRUE;
222         simplerect->draw = TRUE;
223         simplerect->full_draw_on_update = TRUE;
224         simplerect->fill_color = 0;
225         simplerect->outline_color = 0;
226         simplerect->outline_pixels = 1;
227         simplerect->outline_what = 0xf;
228
229         // GTK2FIX
230         // GNOME_CANVAS_ITEM(simplerect)->object.flags |= GNOME_CANVAS_ITEM_NO_AUTO_REDRAW;
231 }
232
233 static void
234 gnome_canvas_simplerect_destroy (GtkObject *object)
235 {
236         GnomeCanvasSimpleRect *rect;
237         
238         g_return_if_fail (object != NULL);
239         g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
240
241         rect = GNOME_CANVAS_SIMPLERECT (object);
242
243         /* remember, destroy can be run multiple times! */
244
245         if (GTK_OBJECT_CLASS (parent_class)->destroy)
246               (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
247 }
248
249 static void
250 gnome_canvas_simplerect_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
251 {
252         GnomeCanvasSimpleRect *simplerect = GNOME_CANVAS_SIMPLERECT (item);
253
254         *x1 = simplerect->x1;
255         *y1 = simplerect->y1;
256         *x2 = simplerect->x2 + 1;
257         *y2 = simplerect->y2 + 1;
258
259 }
260
261 static void 
262 gnome_canvas_simplerect_reset_bounds (GnomeCanvasItem *item)
263 {
264         GnomeCanvasSimpleRect* simplerect;
265         double x1, x2, y1, y2;
266         double old_x1, old_x2, old_y1, old_y2;
267         double a, b;
268         
269         old_x1 = item->x1;
270         old_y1 = item->y1;
271         old_x2 = item->x2;
272         old_y2 = item->y2;
273
274         gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
275         gnome_canvas_item_i2w (item, &x1, &y1);
276         gnome_canvas_item_i2w (item, &x2, &y2);
277
278         item->x1 = x1;
279         item->y1 = y1;
280         item->x2 = x2;
281         item->y2 = y2;
282
283         /* now compute bounding box in canvas units */
284
285         simplerect = GNOME_CANVAS_SIMPLERECT (item);
286
287         gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simplerect->bbox_ulx, &simplerect->bbox_uly);
288         gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simplerect->bbox_lrx, &simplerect->bbox_lry);
289
290         /* now queue redraws for changed areas */
291
292         if (item->x1 != old_x1) {
293                 
294                 /* left edge changed. redraw the area that altered */
295                 
296                 a = MIN(item->x1, old_x1); 
297                 b = MAX(item->x1, old_x1);
298                 gnome_canvas_request_redraw (item->canvas, a - 1, item->y1, b + 1, item->y2);
299         }
300         
301         if (item->x2 != old_x2) {
302                 
303                 /* right edge changed. redraw the area that altered */
304                 
305                 a = MIN(item->x2, old_x2);
306                 b = MAX(item->x2, old_x2);
307                 gnome_canvas_request_redraw (item->canvas, a - 1, item->y1, b + 1, item->y2);
308         }
309         
310         if (item->y1 != old_y1) {
311                 
312                 /* top edge changed. redraw the area that altered */
313                 
314                 a = MIN(item->y1, old_y1);
315                 b = MAX(item->y1, old_y1);
316                 gnome_canvas_request_redraw (item->canvas, item->x1, a - 1, item->x2, b + 1);
317         }
318         
319         if (item->y2 != old_y2) {
320                 
321                 /* lower edge changed. redraw the area that altered */
322                 
323                 a = MIN(item->y2, old_y2);
324                 b = MAX(item->y2, old_y2);
325                 gnome_canvas_request_redraw (item->canvas, item->x1, a - 1, item->x2, b + 1);
326         }
327 }
328
329 /* 
330  * CANVAS CALLBACKS 
331  */
332
333 static void
334 gnome_canvas_simplerect_set_property (GObject      *object,
335                                       guint         prop_id,
336                                       const GValue *value,
337                                       GParamSpec   *pspec)
338
339 {
340         GnomeCanvasSimpleRect *simplerect;
341         int update = FALSE;
342         int bounds_changed = FALSE;
343         g_return_if_fail (object != NULL);
344         g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
345
346         simplerect = GNOME_CANVAS_SIMPLERECT (object);
347
348         switch (prop_id) {
349         case PROP_X1:
350                 if (simplerect->x1 != g_value_get_double (value)) {
351                         simplerect->x1 = g_value_get_double (value);
352                         bounds_changed = TRUE;
353                 }
354                 break;
355
356         case PROP_Y1:
357                 if (simplerect->y1 != g_value_get_double (value)) {
358                         simplerect->y1 = g_value_get_double (value);
359                         bounds_changed = TRUE;
360                 }
361                 break;
362
363         case PROP_X2:
364                 if (simplerect->x2 != g_value_get_double (value)) {
365                         simplerect->x2 = g_value_get_double (value);
366                         bounds_changed = TRUE;
367                 }
368                 break;
369
370         case PROP_Y2:
371                 if (simplerect->y2 != g_value_get_double (value)) {
372                         simplerect->y2 = g_value_get_double (value);
373                         bounds_changed = TRUE;
374                 }
375                 break;
376
377         case PROP_DRAW:
378                 if (simplerect->draw != g_value_get_boolean (value)) {
379                         simplerect->draw = g_value_get_boolean (value);
380                         update = TRUE;
381                 }
382                 break;
383
384
385         case PROP_FILL:
386                 if (simplerect->fill != g_value_get_boolean (value)) {
387                         simplerect->fill = g_value_get_boolean (value);
388                         update = TRUE;
389                 }
390                 break;
391
392         case PROP_FILL_COLOR_RGBA:
393                 if (simplerect->fill_color != g_value_get_uint(value)) {
394                         simplerect->fill_color = g_value_get_uint(value);
395                         update = TRUE;
396                 }
397                 break;
398
399         case PROP_OUTLINE_COLOR_RGBA:
400                 if (simplerect->outline_color != g_value_get_uint(value)) {
401                         simplerect->outline_color = g_value_get_uint(value);
402                         update = TRUE;
403                 }
404                 break;
405
406         case PROP_OUTLINE_PIXELS:
407                 if (simplerect->outline_pixels != g_value_get_uint(value)) {
408                         simplerect->outline_pixels = g_value_get_uint(value);
409                         update = TRUE;
410                 }
411                 break;
412
413         case PROP_OUTLINE_WHAT:
414                 if (simplerect->outline_what != g_value_get_uint(value)) {
415                         simplerect->outline_what = g_value_get_uint(value);
416                         update = TRUE;
417                 }
418                 break;
419
420         default:
421                 break;
422         }
423
424         simplerect->full_draw_on_update = update;
425
426         if (update || bounds_changed) {
427                 gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(object));
428         }
429 }
430
431 static void
432 gnome_canvas_simplerect_get_property (GObject      *object,
433                                       guint         prop_id,
434                                       GValue       *value,
435                                       GParamSpec   *pspec)
436 {
437         GnomeCanvasSimpleRect *rect = GNOME_CANVAS_SIMPLERECT (object);
438         
439         g_return_if_fail (object != NULL);
440         g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
441
442         switch (prop_id) {
443         case PROP_X1:
444                 g_value_set_double (value, rect->x1);
445                 break;
446         case PROP_X2:
447                 g_value_set_double (value, rect->x2);
448                 break;
449         case PROP_Y1:
450                 g_value_set_double (value, rect->y1);
451                 break;
452         case PROP_Y2:
453                 g_value_set_double (value, rect->y2);
454                 break;
455         case PROP_OUTLINE_WHAT:
456                 g_value_set_uint (value, rect->outline_what);
457                 break;
458         case PROP_FILL:
459                 g_value_set_boolean (value, rect->fill);
460                 break;
461         case PROP_OUTLINE_PIXELS:
462                 g_value_set_uint (value, rect->outline_pixels);
463                 break;
464         case PROP_FILL_COLOR_RGBA:
465                 g_value_set_uint (value, rect->fill_color);
466                 break;
467         case PROP_OUTLINE_COLOR_RGBA:
468                 g_value_set_uint (value, rect->outline_color);
469                 break;
470         case PROP_DRAW:
471                 g_value_set_boolean (value, rect->draw);
472                 break;
473                 
474         default:
475                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
476                 break;
477         }
478 }
479
480
481 static void
482 gnome_canvas_simplerect_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
483 {
484         GnomeCanvasSimpleRect *simplerect;
485         unsigned char foo;
486
487         g_return_if_fail (clip_path == NULL);
488
489         simplerect = GNOME_CANVAS_SIMPLERECT (item);
490
491         if (parent_class->update)
492                 (* parent_class->update) (item, affine, clip_path, flags);
493
494         gnome_canvas_simplerect_reset_bounds (item);
495
496         if (simplerect->full_draw_on_update) {
497                 gnome_canvas_request_redraw (item->canvas, 
498                                            simplerect->bbox_ulx,
499                                            simplerect->bbox_uly,
500                                            simplerect->bbox_lrx+1,
501                                            simplerect->bbox_lry+1);
502                 simplerect->full_draw_on_update = FALSE;
503         }
504
505         UINT_TO_RGBA (simplerect->fill_color, &simplerect->fill_r, &simplerect->fill_g, &simplerect->fill_b, &simplerect->fill_a);
506         UINT_TO_RGBA (simplerect->outline_color, &simplerect->outline_r, &simplerect->outline_g, &simplerect->outline_b, &foo);
507 }
508
509 #define 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                 // this can be useful for debugging/understanding how the canvas redraws
532                 // stuff.
533
534                 // gint randr, randg, randb;
535                 // randr = random() % 255;
536                 // randg = random() % 255;
537                 // randb = random() % 255;
538                 // PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
539
540                 gnome_canvas_buf_ensure_buf (buf);
541                 buf->is_bg = FALSE;
542         }
543
544         if (!simplerect->draw) {
545                 return;
546         }
547         
548         self.x0 = simplerect->bbox_ulx;
549         self.y0 = simplerect->bbox_uly;
550         self.x1 = simplerect->bbox_lrx;
551         self.y1 = simplerect->bbox_lry;
552
553         art_irect_intersect (&intersection, &self, &buf->rect);
554
555         begin = MAX(simplerect->bbox_ulx, buf->rect.x0);
556         end = MIN((simplerect->bbox_lrx-1), buf->rect.x1);
557
558         sy = simplerect->bbox_uly;
559         ey = simplerect->bbox_lry-1;
560
561         if (simplerect->fill) {
562                 
563                 // this can be useful for debugging/understanding how the canvas redraws
564                 // stuff.
565                 
566                 // gint randr, randg, randb;
567                 // randr = random() % 255;
568                 // randg = random() % 255;
569                 // randb = random() % 255;
570                 // PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
571                 
572                 FAST_PAINT_BOX (buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a, 
573                                 intersection.x0, intersection.y0,
574                                 intersection.x1, intersection.y1);
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                 // this can be useful for debugging/understanding how the canvas redraws
622                 // stuff.
623
624                 // gint randr, randg, randb;
625                 // randr = random() % 255;
626                 // randg = random() % 255;
627                 // randb = random() % 255;
628                 // PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
629
630                 gnome_canvas_buf_ensure_buf (buf);
631                 buf->is_bg = FALSE;
632         }
633
634         if (!simplerect->draw) {
635                 return;
636         }
637
638         begin = MAX(simplerect->bbox_ulx,buf->rect.x0);
639         end = MIN((simplerect->bbox_lrx-1),buf->rect.x1);
640
641         sy = simplerect->bbox_uly;
642         ey = simplerect->bbox_lry-1;
643
644         if (simplerect->fill) {
645                 
646                 // this can be useful for debugging/understanding how the canvas redraws
647                 // stuff.
648                 
649                 // gint randr, randg, randb;
650                 // randr = random() % 255;
651                 // randg = random() % 255;
652                 // randb = random() % 255;
653                 // PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
654                 
655                 PAINT_BOX(buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a, begin, sy, end, ey);
656         }
657
658         for (i = 0; i < simplerect->outline_pixels; ++i) {
659
660                 if (simplerect->outline_what & 0x1) {
661                         if (begin == simplerect->bbox_ulx) {
662                                 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin + i, sy, ey);
663                         }
664                 }
665
666                 if (simplerect->outline_what & 0x2) {
667                         if (end == (simplerect->bbox_lrx - 1)) {
668                                 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, end - i, sy, ey + 1);
669                         }
670                 }
671
672                 if (simplerect->outline_what & 0x4) {
673                         PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end, sy+i);
674                 }
675         
676                 if (simplerect->outline_what & 0x8) {
677                         PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end + 1, ey-i);
678                 }
679         }
680 }
681 #endif /* SIMPLERECT_FAST_RENDERER */
682
683 static void
684 gnome_canvas_simplerect_draw (GnomeCanvasItem *item,
685                             GdkDrawable *drawable,
686                             int x, int y,
687                             int width, int height)
688 {
689         fprintf (stderr, "please don't use the CanvasSimpleRect item in a non-aa Canvas\n");
690         abort ();
691 }
692
693 static double
694 gnome_canvas_simplerect_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
695 {
696         GnomeCanvasSimpleRect *simplerect;
697         double x1, y1, x2, y2;
698         double dx, dy;
699
700         simplerect = GNOME_CANVAS_SIMPLERECT (item);
701
702         *actual_item = item;
703
704         /* Find the bounds for the rectangle plus its outline width */
705
706         gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
707
708         /* Is point inside rectangle */
709         
710         if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
711                 return 0.0;
712         }
713
714         /* Point is outside rectangle */
715
716         if (x < x1)
717                 dx = x1 - x;
718         else if (x > x2)
719                 dx = x - x2;
720         else
721                 dx = 0.0;
722
723         if (y < y1)
724                 dy = y1 - y;
725         else if (y > y2)
726                 dy = y - y2;
727         else
728                 dy = 0.0;
729
730         return sqrt (dx * dx + dy * dy);
731 }