summaryrefslogtreecommitdiff
path: root/gdk/gdkcairo.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-09-09 01:45:54 +0200
committerBenjamin Otte <otte@redhat.com>2010-09-26 15:11:34 +0200
commitd4f08efd57207b24837a5c2d8833139acb9005ad (patch)
tree94c9b0e32234ee3549a9c89e802cb97137f8b126 /gdk/gdkcairo.c
parent39b376681c8b99cf7031c0c4afb275f10cfaa167 (diff)
downloadgtk+-d4f08efd57207b24837a5c2d8833139acb9005ad.tar.gz
API: add gdk_cairo_get_clip_rectangle() convenience API
Diffstat (limited to 'gdk/gdkcairo.c')
-rw-r--r--gdk/gdkcairo.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c
index 7a7fc839cf..3ef1ce2b34 100644
--- a/gdk/gdkcairo.c
+++ b/gdk/gdkcairo.c
@@ -90,6 +90,45 @@ gdk_cairo_reset_clip (cairo_t *cr,
}
/**
+ * gdk_cairo_get_clip_rectangle:
+ * @cr: a cairo context
+ * @rect: (out) (allow-none): return location for the clip, or %NULL
+ *
+ * This is a convenience function around cairo_clip_extents(). It rounds
+ * the clip extents to integer coordinates and returns a boolean
+ * indicating if a clip area exists.
+ *
+ * Returns: %TRUE if a clip rectangle exists, %FALSE if all of @cr is
+ * clipped and all drawing can be skipped.
+ **/
+gboolean
+gdk_cairo_get_clip_rectangle (cairo_t *cr,
+ GdkRectangle *rect)
+{
+ double x1, y1, x2, y2;
+ gboolean clip_exists;
+
+ cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
+
+ clip_exists = x1 < x2 && y1 < y2;
+
+ if (rect)
+ {
+ x1 = floor (x1);
+ y1 = floor (y1);
+ x2 = ceil (x2);
+ y2 = ceil (y2);
+
+ rect->x = CLAMP (x1, G_MININT, G_MAXINT);
+ rect->y = CLAMP (y1, G_MININT, G_MAXINT);
+ rect->width = CLAMP (x2 - x1, G_MININT, G_MAXINT);
+ rect->height = CLAMP (y2 - y1, G_MININT, G_MAXINT);
+ }
+
+ return clip_exists;
+}
+
+/**
* gdk_cairo_set_source_color:
* @cr: a #cairo_t
* @color: a #GdkColor