patch from lucus for long names in trackbus inspector
[ardour2.git] / gtk2_ardour / canvas-simplerect.c
blob91649b64bbca6f2f7ed7ecc2c3ad660b7ecb8584
1 #include <stdio.h>
2 #include <math.h>
3 #include <cairo.h>
4 #include <libgnomecanvas/libgnomecanvas.h>
6 #include "canvas-simplerect.h"
7 #include "rgb_macros.h"
8 #include "gettext.h"
9 #define _(Text) dgettext (PACKAGE,Text)
11 enum {
12 PROP_0,
13 PROP_X1,
14 PROP_Y1,
15 PROP_X2,
16 PROP_Y2,
17 PROP_OUTLINE_PIXELS,
18 PROP_OUTLINE_WHAT,
19 PROP_FILL,
20 PROP_FILL_COLOR_RGBA,
21 PROP_OUTLINE_COLOR_RGBA,
22 PROP_DRAW
26 static void gnome_canvas_simplerect_class_init (GnomeCanvasSimpleRectClass *class);
28 static void gnome_canvas_simplerect_init (GnomeCanvasSimpleRect *simplerect);
30 static void gnome_canvas_simplerect_destroy (GtkObject *object);
32 static void gnome_canvas_simplerect_set_property (GObject *object,
33 guint prop_id,
34 const GValue *value,
35 GParamSpec *pspec);
37 static void gnome_canvas_simplerect_get_property (GObject *object,
38 guint prop_id,
39 GValue *value,
40 GParamSpec *pspec);
42 static void gnome_canvas_simplerect_update (GnomeCanvasItem *item,
43 double *affine,
44 ArtSVP *clip_path,
45 int flags);
47 static void gnome_canvas_simplerect_bounds (GnomeCanvasItem *item,
48 double *x1,
49 double *y1,
50 double *x2,
51 double *y2);
53 static double gnome_canvas_simplerect_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item);
55 static void gnome_canvas_simplerect_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
57 static void gnome_canvas_simplerect_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w, int h);
59 static GnomeCanvasItemClass *parent_class;
62 GType
63 gnome_canvas_simplerect_get_type (void)
65 static GType simplerect_type;
67 if (!simplerect_type) {
68 static const GTypeInfo object_info = {
69 sizeof (GnomeCanvasSimpleRectClass),
70 (GBaseInitFunc) NULL,
71 (GBaseFinalizeFunc) NULL,
72 (GClassInitFunc) gnome_canvas_simplerect_class_init,
73 (GClassFinalizeFunc) NULL,
74 NULL, /* class_data */
75 sizeof (GnomeCanvasSimpleRect),
76 0, /* n_preallocs */
77 (GInstanceInitFunc) gnome_canvas_simplerect_init,
78 NULL /* value_table */
81 simplerect_type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM, "GnomeCanvasSimpleRect",
82 &object_info, 0);
85 return simplerect_type;
88 static void
89 gnome_canvas_simplerect_class_init (GnomeCanvasSimpleRectClass *class)
91 GObjectClass *gobject_class;
92 GtkObjectClass *object_class;
93 GnomeCanvasItemClass *item_class;
95 gobject_class = (GObjectClass *) class;
96 object_class = (GtkObjectClass *) class;
97 item_class = (GnomeCanvasItemClass *) class;
99 parent_class = g_type_class_peek_parent (class);
101 gobject_class->set_property = gnome_canvas_simplerect_set_property;
102 gobject_class->get_property = gnome_canvas_simplerect_get_property;
104 g_object_class_install_property (gobject_class,
105 PROP_X1,
106 g_param_spec_double ("x1",
107 _("x1"),
108 _("x coordinate of upper left corner of rect"),
109 -G_MAXDOUBLE,
110 G_MAXDOUBLE,
111 0.0,
112 G_PARAM_READWRITE));
114 g_object_class_install_property (gobject_class,
115 PROP_Y1,
116 g_param_spec_double ("y1",
117 _("y1"),
118 _("y coordinate of upper left corner of rect "),
119 -G_MAXDOUBLE,
120 G_MAXDOUBLE,
121 0.0,
122 G_PARAM_READWRITE));
125 g_object_class_install_property (gobject_class,
126 PROP_X2,
127 g_param_spec_double ("x2",
128 _("x2"),
129 _("x coordinate of lower right corner of rect"),
130 -G_MAXDOUBLE,
131 G_MAXDOUBLE,
132 0.0,
133 G_PARAM_READWRITE));
135 g_object_class_install_property (gobject_class,
136 PROP_Y2,
137 g_param_spec_double ("y2",
138 _("y2"),
139 _("y coordinate of lower right corner of rect "),
140 -G_MAXDOUBLE,
141 G_MAXDOUBLE,
142 0.0,
143 G_PARAM_READWRITE));
146 g_object_class_install_property (gobject_class,
147 PROP_OUTLINE_PIXELS,
148 g_param_spec_uint ("outline_pixels",
149 _("outline pixels"),
150 _("width in pixels of outline"),
152 G_MAXUINT,
154 G_PARAM_READWRITE));
157 g_object_class_install_property (gobject_class,
158 PROP_OUTLINE_WHAT,
159 g_param_spec_uint ("outline_what",
160 _("outline what"),
161 _("which boundaries to outline (mask)"),
163 G_MAXUINT,
165 G_PARAM_READWRITE));
169 g_object_class_install_property (gobject_class,
170 PROP_FILL,
171 g_param_spec_boolean ("fill",
172 _("fill"),
173 _("fill rectangle"),
174 TRUE,
175 G_PARAM_READWRITE));
177 g_object_class_install_property (gobject_class,
178 PROP_DRAW,
179 g_param_spec_boolean ("draw",
180 _("draw"),
181 _("draw rectangle"),
182 TRUE,
183 G_PARAM_READWRITE));
186 g_object_class_install_property (gobject_class,
187 PROP_OUTLINE_COLOR_RGBA,
188 g_param_spec_uint ("outline_color_rgba",
189 _("outline color rgba"),
190 _("color of outline"),
192 G_MAXUINT,
194 G_PARAM_READWRITE));
197 g_object_class_install_property (gobject_class,
198 PROP_FILL_COLOR_RGBA,
199 g_param_spec_uint ("fill_color_rgba",
200 _("fill color rgba"),
201 _("color of fill"),
203 G_MAXUINT,
205 G_PARAM_READWRITE));
207 object_class->destroy = gnome_canvas_simplerect_destroy;
209 item_class->update = gnome_canvas_simplerect_update;
210 item_class->draw = gnome_canvas_simplerect_draw;
211 item_class->bounds = gnome_canvas_simplerect_bounds;
212 item_class->point = gnome_canvas_simplerect_point;
213 item_class->render = gnome_canvas_simplerect_render;
217 static void
218 gnome_canvas_simplerect_init (GnomeCanvasSimpleRect *simplerect)
220 simplerect->x1 = 0.0;
221 simplerect->y1 = 0.0;
222 simplerect->x2 = 0.0;
223 simplerect->y2 = 0.0;
224 simplerect->fill = TRUE;
225 simplerect->draw = TRUE;
226 simplerect->full_draw_on_update = TRUE;
227 simplerect->fill_color = 0;
228 simplerect->outline_color = 0;
229 simplerect->outline_pixels = 1;
230 simplerect->outline_what = 0xf;
233 static void
234 gnome_canvas_simplerect_destroy (GtkObject *object)
236 GnomeCanvasSimpleRect *rect;
238 g_return_if_fail (object != NULL);
239 g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
241 rect = GNOME_CANVAS_SIMPLERECT (object);
243 /* remember, destroy can be run multiple times! */
245 if (GTK_OBJECT_CLASS (parent_class)->destroy)
246 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
249 static void
250 gnome_canvas_simplerect_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
252 GnomeCanvasSimpleRect *simplerect = GNOME_CANVAS_SIMPLERECT (item);
254 *x1 = simplerect->x1;
255 *y1 = simplerect->y1;
256 *x2 = simplerect->x2 + 1;
257 *y2 = simplerect->y2 + 1;
262 static void
263 gnome_canvas_simplerect_reset_bounds (GnomeCanvasItem *item)
265 GnomeCanvasSimpleRect* simplerect;
266 double x1, x2, y1, y2;
267 double old_x1, old_x2, old_y1, old_y2;
268 ArtDRect unionrect, old, new;
270 old_x1 = item->x1;
271 old_y1 = item->y1;
272 old_x2 = item->x2;
273 old_y2 = item->y2;
275 gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
276 gnome_canvas_item_i2w (item, &x1, &y1);
277 gnome_canvas_item_i2w (item, &x2, &y2);
279 item->x1 = x1;
280 item->y1 = y1;
281 item->x2 = x2;
282 item->y2 = y2;
284 /* now compute bounding box in canvas units */
286 simplerect = GNOME_CANVAS_SIMPLERECT (item);
288 gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simplerect->bbox_ulx, &simplerect->bbox_uly);
289 gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simplerect->bbox_lrx, &simplerect->bbox_lry);
291 /* now queue redraws for changed areas */
293 if (item->x1 == old_x1 && item->x2 == old_x2) {
295 /* no change in x-axis position */
297 if (item->y1 == old_y1) {
298 /* top didn't change, so just draw bottom */
300 double start_y = MIN (item->y2, old_y2);
301 double end_y = MAX (item->y2, old_y2);
303 gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
304 return;
306 } else if (item->y2 == old_y2) {
308 /* bottom didn't change, just draw top */
310 double start_y = MIN (item->y1, old_y1);
311 double end_y = MAX (item->y1, old_y1);
313 gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
314 return;
318 } else if (item->y1 == old_y1 && item->y2 == old_y2) {
320 /* no change in y-axis position */
322 if (item->x1 == old_x1) {
323 /* start didn't change, so just draw at the end */
325 double start_x = MIN (item->x2, old_x2);
326 double end_x = MAX (item->x2, old_x2);
328 gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2);
329 return;
331 } else if (item->x2 == old_x2) {
333 /* end didn't change, so just draw at the start */
335 double start_x = MIN (item->x1, old_x1);
336 double end_x = MAX (item->x1, old_x1);
338 gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2 + 0.5);
339 return;
344 new.x0 = x1;
345 new.y0 = y1;
346 new.x1 = x2;
347 new.y1 = y2;
349 old.x0 = old_x1;
350 old.y0 = old_y1;
351 old.x1 = old_x2;
352 old.y1 = old_y2;
354 art_drect_union (&unionrect, &old, &new);
355 gnome_canvas_request_redraw (item->canvas,
356 unionrect.x0 - 0.5,
357 unionrect.y0 - 0.5,
358 unionrect.x1 + 1.5,
359 unionrect.y1 + 1.5);
363 * CANVAS CALLBACKS
366 static void
367 gnome_canvas_simplerect_set_property (GObject *object,
368 guint prop_id,
369 const GValue *value,
370 GParamSpec *pspec)
373 GnomeCanvasSimpleRect *simplerect;
374 int update = FALSE;
375 int bounds_changed = FALSE;
376 g_return_if_fail (object != NULL);
377 g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
379 simplerect = GNOME_CANVAS_SIMPLERECT (object);
381 switch (prop_id) {
382 case PROP_X1:
383 if (simplerect->x1 != g_value_get_double (value)) {
384 simplerect->x1 = g_value_get_double (value);
385 bounds_changed = TRUE;
387 break;
389 case PROP_Y1:
390 if (simplerect->y1 != g_value_get_double (value)) {
391 simplerect->y1 = g_value_get_double (value);
392 bounds_changed = TRUE;
394 break;
396 case PROP_X2:
397 if (simplerect->x2 != g_value_get_double (value)) {
398 simplerect->x2 = g_value_get_double (value);
399 bounds_changed = TRUE;
401 break;
403 case PROP_Y2:
404 if (simplerect->y2 != g_value_get_double (value)) {
405 simplerect->y2 = g_value_get_double (value);
406 bounds_changed = TRUE;
408 break;
410 case PROP_DRAW:
411 if (simplerect->draw != g_value_get_boolean (value)) {
412 simplerect->draw = g_value_get_boolean (value);
413 update = TRUE;
415 break;
418 case PROP_FILL:
419 if (simplerect->fill != g_value_get_boolean (value)) {
420 simplerect->fill = g_value_get_boolean (value);
421 update = TRUE;
423 break;
425 case PROP_FILL_COLOR_RGBA:
426 if (simplerect->fill_color != g_value_get_uint(value)) {
427 simplerect->fill_color = g_value_get_uint(value);
428 update = TRUE;
430 break;
432 case PROP_OUTLINE_COLOR_RGBA:
433 if (simplerect->outline_color != g_value_get_uint(value)) {
434 simplerect->outline_color = g_value_get_uint(value);
435 update = TRUE;
437 break;
439 case PROP_OUTLINE_PIXELS:
440 if (simplerect->outline_pixels != g_value_get_uint(value)) {
441 simplerect->outline_pixels = g_value_get_uint(value);
442 update = TRUE;
444 break;
446 case PROP_OUTLINE_WHAT:
447 if (simplerect->outline_what != g_value_get_uint(value)) {
448 simplerect->outline_what = g_value_get_uint(value);
449 update = TRUE;
451 break;
453 default:
454 break;
457 simplerect->full_draw_on_update = update;
459 if (update || bounds_changed) {
460 gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(object));
464 static void
465 gnome_canvas_simplerect_get_property (GObject *object,
466 guint prop_id,
467 GValue *value,
468 GParamSpec *pspec)
470 GnomeCanvasSimpleRect *rect = GNOME_CANVAS_SIMPLERECT (object);
472 g_return_if_fail (object != NULL);
473 g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
475 switch (prop_id) {
476 case PROP_X1:
477 g_value_set_double (value, rect->x1);
478 break;
479 case PROP_X2:
480 g_value_set_double (value, rect->x2);
481 break;
482 case PROP_Y1:
483 g_value_set_double (value, rect->y1);
484 break;
485 case PROP_Y2:
486 g_value_set_double (value, rect->y2);
487 break;
488 case PROP_OUTLINE_WHAT:
489 g_value_set_uint (value, rect->outline_what);
490 break;
491 case PROP_FILL:
492 g_value_set_boolean (value, rect->fill);
493 break;
494 case PROP_OUTLINE_PIXELS:
495 g_value_set_uint (value, rect->outline_pixels);
496 break;
497 case PROP_FILL_COLOR_RGBA:
498 g_value_set_uint (value, rect->fill_color);
499 break;
500 case PROP_OUTLINE_COLOR_RGBA:
501 g_value_set_uint (value, rect->outline_color);
502 break;
503 case PROP_DRAW:
504 g_value_set_boolean (value, rect->draw);
505 break;
507 default:
508 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
509 break;
514 static void
515 gnome_canvas_simplerect_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
517 GnomeCanvasSimpleRect *simplerect;
518 unsigned char foo;
520 simplerect = GNOME_CANVAS_SIMPLERECT (item);
522 if (parent_class->update)
523 (* parent_class->update) (item, affine, clip_path, flags);
525 gnome_canvas_simplerect_reset_bounds (item);
527 if (simplerect->full_draw_on_update) {
528 gnome_canvas_request_redraw (item->canvas,
529 simplerect->bbox_ulx,
530 simplerect->bbox_uly,
531 simplerect->bbox_lrx+0.5,
532 simplerect->bbox_lry+0.5);
533 simplerect->full_draw_on_update = FALSE;
536 UINT_TO_RGBA (simplerect->fill_color, &simplerect->fill_r, &simplerect->fill_g, &simplerect->fill_b, &simplerect->fill_a);
537 UINT_TO_RGBA (simplerect->outline_color, &simplerect->outline_r, &simplerect->outline_g, &simplerect->outline_b, &foo);
540 // this can be useful for debugging/understanding how the canvas redraws
541 // stuff.
543 #undef HARLEQUIN_DEBUGGING
545 #undef SIMPLERECT_FAST_RENDERER
546 #ifdef SIMPLERECT_FAST_RENDERER
548 static void
549 gnome_canvas_simplerect_render (GnomeCanvasItem *item,
550 GnomeCanvasBuf *buf)
552 GnomeCanvasSimpleRect *simplerect;
553 int end, begin;
554 int ey, sy;
555 unsigned int i;
556 ArtIRect intersection;
557 ArtIRect self;
559 simplerect = GNOME_CANVAS_SIMPLERECT (item);
561 if (parent_class->render) {
562 (*parent_class->render) (item, buf);
565 if (buf->is_bg) {
567 #ifdef HARLEQUIN_DEBUGGING
568 gint randr, randg, randb;
569 randr = random() % 255;
570 randg = random() % 255;
571 randb = random() % 255;
572 PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
573 #endif
574 gnome_canvas_buf_ensure_buf (buf);
575 buf->is_bg = FALSE;
578 if (!simplerect->draw) {
579 return;
582 self.x0 = simplerect->bbox_ulx;
583 self.y0 = simplerect->bbox_uly;
584 self.x1 = simplerect->bbox_lrx;
585 self.y1 = simplerect->bbox_lry;
587 art_irect_intersect (&intersection, &self, &buf->rect);
589 begin = MAX(simplerect->bbox_ulx, buf->rect.x0);
590 end = MIN((simplerect->bbox_lrx-1), buf->rect.x1);
592 sy = simplerect->bbox_uly;
593 ey = simplerect->bbox_lry-1;
595 if (simplerect->fill) {
597 // this can be useful for debugging/understanding how the canvas redraws
598 // stuff.
600 #ifdef HARLEQUIN_DEBUGGING
601 gint randr, randg, randb;
602 randr = random() % 255;
603 randg = random() % 255;
604 randb = random() % 255;
605 PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
606 #else
607 PAINT_BOX (buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a,
608 intersection.x0, intersection.y0,
609 intersection.x1, intersection.y1);
610 #endif
614 for (i = 0; i < simplerect->outline_pixels; ++i) {
616 if (simplerect->outline_what & 0x1) {
617 if (begin == simplerect->bbox_ulx) {
618 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin + i, sy, ey);
622 if (simplerect->outline_what & 0x2) {
623 if (end == (simplerect->bbox_lrx - 1)) {
624 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, end - i, sy, ey + 1);
628 if (simplerect->outline_what & 0x4) {
629 PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end, sy+i);
632 if (simplerect->outline_what & 0x8) {
633 PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end + 1, ey-i);
638 #else /* SIMPLERECT_FAST_RENDERER */
640 static void
641 gnome_canvas_simplerect_render (GnomeCanvasItem *item,
642 GnomeCanvasBuf *buf)
644 GnomeCanvasSimpleRect *simplerect;
645 int end, begin;
646 int ey, sy;
647 unsigned int i;
649 simplerect = GNOME_CANVAS_SIMPLERECT (item);
651 if (parent_class->render) {
652 (*parent_class->render) (item, buf);
655 if (buf->is_bg) {
657 #ifdef HARLEQUIN_DEBUGGING
658 gint randr, randg, randb;
659 randr = random() % 255;
660 randg = random() % 255;
661 randb = random() % 255;
662 PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
663 #endif
664 gnome_canvas_buf_ensure_buf (buf);
665 buf->is_bg = FALSE;
668 if (!simplerect->draw) {
669 return;
672 begin = MAX(simplerect->bbox_ulx,buf->rect.x0);
673 end = MIN((simplerect->bbox_lrx-1),buf->rect.x1);
675 sy = simplerect->bbox_uly;
676 ey = simplerect->bbox_lry-1;
678 if (simplerect->fill) {
680 #ifdef HARLEQUIN_DEBUGGING
681 gint randr, randg, randb;
682 randr = random() % 255;
683 randg = random() % 255;
684 randb = random() % 255;
685 PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
686 #else
687 PAINT_BOX(buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a, begin, sy, end, ey);
688 #endif
691 for (i = 0; i < simplerect->outline_pixels; ++i) {
693 if (simplerect->outline_what & 0x1) {
694 if (begin == simplerect->bbox_ulx) {
695 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin + i, sy, ey);
699 if (simplerect->outline_what & 0x2) {
700 if (end == (simplerect->bbox_lrx - 1)) {
701 PAINT_VERT(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, end - i, sy, ey + 1);
705 if (simplerect->outline_what & 0x4) {
706 PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end, sy+i);
709 if (simplerect->outline_what & 0x8) {
710 PAINT_HORIZ(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, begin, end + 1, ey-i);
714 #endif /* SIMPLERECT_FAST_RENDERER */
716 static void
717 gnome_canvas_simplerect_draw (GnomeCanvasItem *item,
718 GdkDrawable *drawable,
719 int x, int y,
720 int width, int height)
722 GnomeCanvasSimpleRect *simplerect;
723 cairo_t* cr;
724 double ulx;
725 double uly;
726 double lrx;
727 double lry;
729 simplerect = GNOME_CANVAS_SIMPLERECT (item);
731 cr = gdk_cairo_create (drawable);
733 if (x > simplerect->bbox_ulx) {
734 ulx = x;
735 } else {
736 ulx = simplerect->bbox_ulx;
739 if (y > simplerect->bbox_uly) {
740 uly = y;
741 } else {
742 uly = simplerect->bbox_uly;
745 if (x + width > simplerect->bbox_lrx) {
746 lrx = simplerect->bbox_lrx;
747 } else {
748 lrx = x + width;
751 if (y + height > simplerect->bbox_lry) {
752 lry = simplerect->bbox_lry;
753 } else {
754 lry = y + height;
757 ulx -= x;
758 uly -= y;
759 lrx -= x;
760 lry -= y;
762 cairo_rectangle (cr, ulx, uly, lrx - ulx, lry - uly);
764 if (simplerect->fill) {
765 cairo_set_source_rgba (cr,
766 simplerect->fill_r/255.0,
767 simplerect->fill_g/255.0,
768 simplerect->fill_b/255.0,
769 simplerect->fill_a/255.0);
770 cairo_fill (cr);
773 if (simplerect->outline_what && simplerect->outline_pixels) {
775 #define x_in_range(a) (x <= (a) && (a) < x + width)
776 #define y_in_range(a) (y <= (a) && (a) < y + height)
778 cairo_set_line_width (cr, simplerect->outline_pixels);
780 cairo_set_source_rgb (cr,
781 simplerect->outline_r/255.0,
782 simplerect->outline_g/255.0,
783 simplerect->outline_b/255.0);
785 if (simplerect->outline_what & 0x1) {
786 /* left edge, if visible */
787 if (x_in_range (simplerect->bbox_ulx)) {
788 cairo_move_to (cr, ulx+0.5, uly+0.5);
789 cairo_line_to (cr, ulx+0.5, lry+0.5);
790 cairo_stroke (cr);
794 if (simplerect->outline_what & 0x2) {
795 /* right edge, if visible */
796 if (x_in_range (simplerect->bbox_lrx)) {
797 cairo_move_to (cr, lrx+0.5, uly+0.5);
798 cairo_line_to (cr, lrx+0.5, lry+0.5);
799 cairo_stroke (cr);
803 if (simplerect->outline_what & 0x4) {
804 /* top edge */
805 if (y_in_range (simplerect->bbox_uly)) {
806 cairo_move_to (cr, ulx+0.5, uly+0.5);
807 cairo_line_to (cr, lrx+0.5, uly+0.5);
808 cairo_stroke (cr);
812 if (simplerect->outline_what & 0x8) {
813 /* bottom edge */
814 if (y_in_range (simplerect->bbox_lry)) {
815 cairo_move_to (cr, ulx+0.5, lry+0.5);
816 cairo_line_to (cr, lrx+0.5, lry+0.5);
817 cairo_stroke (cr);
822 cairo_destroy (cr);
825 static double
826 gnome_canvas_simplerect_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
828 GnomeCanvasSimpleRect *simplerect;
829 double x1, y1, x2, y2;
830 double dx, dy;
832 simplerect = GNOME_CANVAS_SIMPLERECT (item);
834 *actual_item = item;
836 /* Find the bounds for the rectangle plus its outline width */
838 gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
840 /* Is point inside rectangle */
842 if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
843 return 0.0;
846 /* Point is outside rectangle */
848 if (x < x1)
849 dx = x1 - x;
850 else if (x > x2)
851 dx = x - x2;
852 else
853 dx = 0.0;
855 if (y < y1)
856 dy = y1 - y;
857 else if (y > y2)
858 dy = y - y2;
859 else
860 dy = 0.0;
862 return sqrt (dx * dx + dy * dy);