4 #include <libgnomecanvas/libgnomecanvas.h>
6 #include "canvas-simplerect.h"
9 #define _(Text) dgettext (PACKAGE,Text)
64 static GType simplerect_type;
66 if (!simplerect_type) {
67 static const GTypeInfo object_info = {
68 sizeof (GnomeCanvasSimpleRectClass),
70 (GBaseFinalizeFunc) NULL,
72 (GClassFinalizeFunc) NULL,
74 sizeof (GnomeCanvasSimpleRect),
80 simplerect_type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM,
"GnomeCanvasSimpleRect",
84 return simplerect_type;
90 GObjectClass *gobject_class;
91 GtkObjectClass *object_class;
92 GnomeCanvasItemClass *item_class;
94 gobject_class = (GObjectClass *)
class;
95 object_class = (GtkObjectClass *)
class;
96 item_class = (GnomeCanvasItemClass *)
class;
103 g_object_class_install_property (gobject_class,
105 g_param_spec_double (
"x1",
107 _(
"x coordinate of upper left corner of rect"),
113 g_object_class_install_property (gobject_class,
115 g_param_spec_double (
"y1",
117 _(
"y coordinate of upper left corner of rect "),
124 g_object_class_install_property (gobject_class,
126 g_param_spec_double (
"x2",
128 _(
"x coordinate of lower right corner of rect"),
134 g_object_class_install_property (gobject_class,
136 g_param_spec_double (
"y2",
138 _(
"y coordinate of lower right corner of rect "),
145 g_object_class_install_property (gobject_class,
147 g_param_spec_uint (
"outline_pixels",
149 _(
"width in pixels of outline"),
156 g_object_class_install_property (gobject_class,
158 g_param_spec_uint (
"outline_what",
160 _(
"which boundaries to outline (mask)"),
168 g_object_class_install_property (gobject_class,
170 g_param_spec_boolean (
"fill",
176 g_object_class_install_property (gobject_class,
178 g_param_spec_boolean (
"draw",
185 g_object_class_install_property (gobject_class,
187 g_param_spec_uint (
"outline_color_rgba",
188 _(
"outline color rgba"),
189 _(
"color of outline"),
196 g_object_class_install_property (gobject_class,
198 g_param_spec_uint (
"fill_color_rgba",
199 _(
"fill color rgba"),
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;
235 g_return_if_fail (
object != NULL);
236 g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (
object));
247 GnomeCanvasSimpleRect *simplerect = GNOME_CANVAS_SIMPLERECT (item);
249 *x1 = simplerect->x1;
250 *y1 = simplerect->y1;
251 *x2 = simplerect->x2 + 1;
252 *y2 = simplerect->y2 + 1;
259 GnomeCanvasSimpleRect* simplerect;
260 double x1, x2, y1, y2;
261 double old_x1, old_x2, old_y1, old_y2;
262 ArtDRect unionrect, old,
new;
270 gnome_canvas_item_i2w (item, &x1, &y1);
271 gnome_canvas_item_i2w (item, &x2, &y2);
280 simplerect = GNOME_CANVAS_SIMPLERECT (item);
282 gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simplerect->bbox_ulx, &simplerect->bbox_uly);
283 gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simplerect->bbox_lrx, &simplerect->bbox_lry);
287 if (item->x1 == old_x1 && item->x2 == old_x2) {
291 if (item->y1 == old_y1) {
294 double start_y =
MIN (item->y2, old_y2);
295 double end_y =
MAX (item->y2, old_y2);
297 gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
300 }
else if (item->y2 == old_y2) {
304 double start_y =
MIN (item->y1, old_y1);
305 double end_y =
MAX (item->y1, old_y1);
307 gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
312 }
else if (item->y1 == old_y1 && item->y2 == old_y2) {
316 if (item->x1 == old_x1) {
319 double start_x =
MIN (item->x2, old_x2);
320 double end_x =
MAX (item->x2, old_x2);
322 gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2 + 0.5);
325 }
else if (item->x2 == old_x2) {
329 double start_x =
MIN (item->x1, old_x1);
330 double end_x =
MAX (item->x1, old_x1);
332 gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2 + 0.5);
348 art_drect_union (&unionrect, &old, &
new);
349 gnome_canvas_request_redraw (item->canvas,
369 GnomeCanvasSimpleRect *simplerect;
371 int bounds_changed = FALSE;
372 g_return_if_fail (
object != NULL);
373 g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (
object));
375 simplerect = GNOME_CANVAS_SIMPLERECT (
object);
379 if (simplerect->x1 != g_value_get_double (value)) {
380 simplerect->x1 = g_value_get_double (value);
381 bounds_changed = TRUE;
386 if (simplerect->y1 != g_value_get_double (value)) {
387 simplerect->y1 = g_value_get_double (value);
388 bounds_changed = TRUE;
393 if (simplerect->x2 != g_value_get_double (value)) {
394 simplerect->x2 = g_value_get_double (value);
395 bounds_changed = TRUE;
400 if (simplerect->y2 != g_value_get_double (value)) {
401 simplerect->y2 = g_value_get_double (value);
402 bounds_changed = TRUE;
407 if (simplerect->draw != g_value_get_boolean (value)) {
408 simplerect->draw = g_value_get_boolean (value);
415 if (simplerect->fill != g_value_get_boolean (value)) {
416 simplerect->fill = g_value_get_boolean (value);
422 if (simplerect->fill_color != g_value_get_uint(value)) {
423 simplerect->fill_color = g_value_get_uint(value);
429 if (simplerect->outline_color != g_value_get_uint(value)) {
430 simplerect->outline_color = g_value_get_uint(value);
436 if (simplerect->outline_pixels != g_value_get_uint(value)) {
437 simplerect->outline_pixels = g_value_get_uint(value);
443 if (simplerect->outline_what != g_value_get_uint(value)) {
444 simplerect->outline_what = g_value_get_uint(value);
453 if (!simplerect->full_draw_on_update) {
468 simplerect->full_draw_on_update = update;
471 if (update || bounds_changed) {
472 gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(
object));
482 GnomeCanvasSimpleRect *rect = GNOME_CANVAS_SIMPLERECT (
object);
484 g_return_if_fail (
object != NULL);
485 g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (
object));
489 g_value_set_double (value, rect->x1);
492 g_value_set_double (value, rect->x2);
495 g_value_set_double (value, rect->y1);
498 g_value_set_double (value, rect->y2);
501 g_value_set_uint (value, rect->outline_what);
504 g_value_set_boolean (value, rect->fill);
507 g_value_set_uint (value, rect->outline_pixels);
510 g_value_set_uint (value, rect->fill_color);
513 g_value_set_uint (value, rect->outline_color);
516 g_value_set_boolean (value, rect->draw);
520 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
529 GnomeCanvasSimpleRect *simplerect;
531 simplerect = GNOME_CANVAS_SIMPLERECT (item);
534 (*
parent_class->update) (item, affine, clip_path, flags);
538 if (simplerect->full_draw_on_update) {
539 gnome_canvas_request_redraw (item->canvas,
540 simplerect->bbox_ulx,
541 simplerect->bbox_uly,
542 simplerect->bbox_lrx+0.5,
543 simplerect->bbox_lry+0.5);
544 simplerect->full_draw_on_update = FALSE;
547 UINT_TO_RGBA (simplerect->fill_color, &simplerect->fill_r, &simplerect->fill_g, &simplerect->fill_b, &simplerect->fill_a);
548 UINT_TO_RGBA (simplerect->outline_color, &simplerect->outline_r, &simplerect->outline_g, &simplerect->outline_b, &simplerect->outline_a);
554 #undef HARLEQUIN_DEBUGGING
556 #undef SIMPLERECT_FAST_RENDERER
557 #ifdef SIMPLERECT_FAST_RENDERER
563 GnomeCanvasSimpleRect *simplerect;
567 ArtIRect intersection;
570 simplerect = GNOME_CANVAS_SIMPLERECT (item);
578 #ifdef HARLEQUIN_DEBUGGING
579 gint randr, randg, randb;
580 randr = random() % 255;
581 randg = random() % 255;
582 randb = random() % 255;
583 PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
585 gnome_canvas_buf_ensure_buf (buf);
589 if (!simplerect->draw) {
593 self.x0 = simplerect->bbox_ulx;
594 self.y0 = simplerect->bbox_uly;
595 self.x1 = simplerect->bbox_lrx;
596 self.y1 = simplerect->bbox_lry;
598 art_irect_intersect (&intersection, &
self, &buf->rect);
600 begin =
MAX(simplerect->bbox_ulx, buf->rect.x0);
601 end =
MIN((simplerect->bbox_lrx-1), buf->rect.x1);
603 sy = simplerect->bbox_uly;
604 ey = simplerect->bbox_lry-1;
606 if (simplerect->fill) {
611 #ifdef HARLEQUIN_DEBUGGING
612 gint randr, randg, randb;
613 randr = random() % 255;
614 randg = random() % 255;
615 randb = random() % 255;
616 PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
618 PAINT_BOX (buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a,
619 intersection.x0, intersection.y0,
620 intersection.x1, intersection.y1);
625 if (simplerect->outline_a > 0) {
626 for (i = 0; i < simplerect->outline_pixels; ++i) {
628 if (simplerect->outline_what & 0x1) {
629 if (begin == simplerect->bbox_ulx) {
630 PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin + i, sy, ey);
634 if (simplerect->outline_what & 0x2) {
635 if (end == (simplerect->bbox_lrx - 1)) {
636 PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, end - i, sy, ey + 1);
640 if (simplerect->outline_what & 0x4) {
641 PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end, sy+i);
644 if (simplerect->outline_what & 0x8) {
645 PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end + 1, ey-i);
657 GnomeCanvasSimpleRect *simplerect;
662 simplerect = GNOME_CANVAS_SIMPLERECT (item);
670 #ifdef HARLEQUIN_DEBUGGING
671 gint randr, randg, randb;
672 randr = random() % 255;
673 randg = random() % 255;
674 randb = random() % 255;
675 PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
677 gnome_canvas_buf_ensure_buf (buf);
681 if (!simplerect->draw) {
685 begin =
MAX(simplerect->bbox_ulx,buf->rect.x0);
686 end =
MIN((simplerect->bbox_lrx-1),buf->rect.x1);
688 sy = simplerect->bbox_uly;
689 ey = simplerect->bbox_lry-1;
691 if (simplerect->fill) {
693 #ifdef HARLEQUIN_DEBUGGING
694 gint randr, randg, randb;
695 randr = random() % 255;
696 randg = random() % 255;
697 randb = random() % 255;
698 PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
700 PAINT_BOX(buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a, begin, sy, end, ey);
704 if (simplerect->outline_a) {
705 for (i = 0; i < (int) simplerect->outline_pixels; ++i) {
707 if (simplerect->outline_what & 0x1) {
708 if (begin == simplerect->bbox_ulx) {
709 PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin + i, sy, ey);
713 if (simplerect->outline_what & 0x2) {
714 if (end == (simplerect->bbox_lrx - 1)) {
715 PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, end - i, sy, ey + 1);
719 if (simplerect->outline_what & 0x4) {
720 PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end, sy+i);
723 if (simplerect->outline_what & 0x8) {
724 PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end + 1, ey-i);
733 GdkDrawable *drawable,
735 int width,
int height)
737 GnomeCanvasSimpleRect *simplerect;
744 simplerect = GNOME_CANVAS_SIMPLERECT (item);
746 cr = gdk_cairo_create (drawable);
748 if (x > simplerect->bbox_ulx) {
751 ulx = simplerect->bbox_ulx;
754 if (y > simplerect->bbox_uly) {
757 uly = simplerect->bbox_uly;
760 if (x + width > simplerect->bbox_lrx) {
761 lrx = simplerect->bbox_lrx;
766 if (y + height > simplerect->bbox_lry) {
767 lry = simplerect->bbox_lry;
777 cairo_rectangle (cr, ulx, uly, lrx - ulx, lry - uly);
779 if (simplerect->fill) {
780 cairo_set_source_rgba (cr,
781 simplerect->fill_r/255.0,
782 simplerect->fill_g/255.0,
783 simplerect->fill_b/255.0,
784 simplerect->fill_a/255.0);
788 if (simplerect->outline_what && simplerect->outline_pixels) {
790 #define x_in_range(a) (x <= (a) && (a) < x + width)
791 #define y_in_range(a) (y <= (a) && (a) < y + height)
793 cairo_set_line_width (cr, simplerect->outline_pixels);
795 cairo_set_source_rgb (cr,
796 simplerect->outline_r/255.0,
797 simplerect->outline_g/255.0,
798 simplerect->outline_b/255.0);
800 if (simplerect->outline_what & 0x1) {
803 cairo_move_to (cr, ulx+0.5, uly+0.5);
804 cairo_line_to (cr, ulx+0.5, lry+0.5);
809 if (simplerect->outline_what & 0x2) {
812 cairo_move_to (cr, lrx+0.5, uly+0.5);
813 cairo_line_to (cr, lrx+0.5, lry+0.5);
818 if (simplerect->outline_what & 0x4) {
821 cairo_move_to (cr, ulx+0.5, uly+0.5);
822 cairo_line_to (cr, lrx+0.5, uly+0.5);
827 if (simplerect->outline_what & 0x8) {
830 cairo_move_to (cr, ulx+0.5, lry+0.5);
831 cairo_line_to (cr, lrx+0.5, lry+0.5);
846 double x1, y1, x2, y2;
857 if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
877 return sqrt (dx * dx + dy * dy);
static void gnome_canvas_simplerect_class_init(GnomeCanvasSimpleRectClass *class)
#define UINT_TO_RGBA(u, r, g, b, a)
static void gnome_canvas_simplerect_draw(GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w, int h)
#define PAINT_HORIZA(inbuf, colr, colg, colb, cola, ptx0, ptx1, pty)
static void gnome_canvas_simplerect_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
static void gnome_canvas_simplerect_reset_bounds(GnomeCanvasItem *item)
static GnomeCanvasItemClass * parent_class
static void gnome_canvas_simplerect_destroy(GtkObject *object)
#define PAINT_VERTA(inbuf, colr, colg, colb, cola, ptx, pty0, pty1)
static void gnome_canvas_simplerect_update(GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
static void gnome_canvas_simplerect_init(GnomeCanvasSimpleRect *simplerect)
GType gnome_canvas_simplerect_get_type(void)
static double gnome_canvas_simplerect_point(GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
static void gnome_canvas_simplerect_render(GnomeCanvasItem *item, GnomeCanvasBuf *buf)
#define PAINT_BOX(inbuf, colr, colg, colb, cola, ptx0, pty0, ptx1, pty1)
static void gnome_canvas_simplerect_bounds(GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
static void gnome_canvas_simplerect_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)