aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2011-01-06 04:28:56 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2011-01-06 13:07:04 +0100
commit1704b94650907e1d42c75b2e59fb6628cedf765a (patch)
treeec07bbb8f15ad0b1e205275558e9be6ba8672e07 /src
parent53d1de680d6ddf4e0f13383953ac470ae60d65b9 (diff)
downloadlogdiag-1704b94650907e1d42c75b2e59fb6628cedf765a.tar.gz
logdiag-1704b94650907e1d42c75b2e59fb6628cedf765a.tar.xz
logdiag-1704b94650907e1d42c75b2e59fb6628cedf765a.zip
Introduce structure LdCanvasRect.
It's basically the same as cairo_rectangle_t, just in our own namespace.
Diffstat (limited to 'src')
-rw-r--r--src/ld-canvas.c41
1 files changed, 40 insertions, 1 deletions
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)