From 1704b94650907e1d42c75b2e59fb6628cedf765a Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Thu, 6 Jan 2011 04:28:56 +0100
Subject: Introduce structure LdCanvasRect.
It's basically the same as cairo_rectangle_t,
just in our own namespace.
---
src/ld-canvas.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/src/ld-canvas.c b/src/ld-canvas.c
index e9d7123..5435a5c 100644
--- a/src/ld-canvas.c
+++ b/src/ld-canvas.c
@@ -80,6 +80,8 @@ struct _LdCanvasColor
gdouble a;
};
+typedef cairo_rectangle_t LdCanvasRect;
+
/*
* LdCanvasPrivate:
* @diagram: A diagram object assigned to this canvas as a model.
@@ -133,7 +135,7 @@ struct _DrawData
{
LdCanvas *self;
cairo_t *cr;
- cairo_rectangle_t exposed_rect;
+ LdCanvasRect exposed_rect;
gdouble scale;
};
@@ -176,6 +178,12 @@ static void ld_canvas_color_set (LdCanvasColor *color,
gdouble r, gdouble g, gdouble b, gdouble a);
static void ld_canvas_color_apply (LdCanvasColor *color, cairo_t *cr);
+static gboolean ld_canvas_rect_contains (LdCanvasRect *rect,
+ gdouble x, gdouble y);
+static gboolean ld_canvas_rect_intersects (LdCanvasRect *first,
+ LdCanvasRect *second);
+static void ld_canvas_rect_extend (LdCanvasRect *rect, gdouble border);
+
static void move_object_to_widget_coords (LdCanvas *self,
LdDiagramObject *object, gdouble x, gdouble y);
static gboolean is_object_in_selection (LdCanvas *self,
@@ -775,6 +783,37 @@ ld_canvas_color_apply (LdCanvasColor *color, cairo_t *cr)
cairo_set_source_rgba (cr, color->r, color->g, color->b, color->a);
}
+static gboolean
+ld_canvas_rect_contains (LdCanvasRect *rect, gdouble x, gdouble y)
+{
+ g_return_val_if_fail (rect != NULL, FALSE);
+ return (x >= rect->x && x <= rect->x + rect->width
+ && y >= rect->y && y <= rect->y + rect->height);
+}
+
+static gboolean
+ld_canvas_rect_intersects (LdCanvasRect *first, LdCanvasRect *second)
+{
+ g_return_val_if_fail (first != NULL, FALSE);
+ g_return_val_if_fail (second != NULL, FALSE);
+
+ return !(first->x > second->x + second->width
+ || first->y > second->y + second->height
+ || first->x + first->width < second->x
+ || first->y + first->height < second->y);
+}
+
+static void
+ld_canvas_rect_extend (LdCanvasRect *rect, gdouble border)
+{
+ g_return_if_fail (rect != NULL);
+
+ rect->x -= border;
+ rect->y -= border;
+ rect->width += 2 * border;
+ rect->height += 2 * border;
+}
+
static void
move_object_to_widget_coords (LdCanvas *self, LdDiagramObject *object,
gdouble x, gdouble y)
--
cgit v1.2.3-70-g09d2