[gtk+] Add clipping apis to GtkRoundedBox



commit 73e6a05e386b58fd6e38b0f14a7b4fb83c436d34
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 2 08:26:36 2014 -0500

    Add clipping apis to GtkRoundedBox
    
    This adds two functions for checking whether an axis-aligned
    rectangle is completely outside or inside of a rounded box.
    These are not trying to be exact, but fast.

 gtk/gtkroundedbox.c        |   47 ++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkroundedboxprivate.h |   10 +++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c
index c89a1fd..2b5ac21 100644
--- a/gtk/gtkroundedbox.c
+++ b/gtk/gtkroundedbox.c
@@ -536,3 +536,50 @@ _gtk_rounded_box_clip_path (const GtkRoundedBox *box,
                    box->box.width, box->box.height);
 }
 
+gboolean
+_gtk_rounded_box_intersects_rectangle (const GtkRoundedBox *box,
+                                       gdouble              x1,
+                                       gdouble              y1,
+                                       gdouble              x2,
+                                       gdouble              y2)
+{
+  if (x2 < box->box.x ||
+      y2 < box->box.y ||
+      x1 >= box->box.x + box->box.width ||
+      y1 >= box->box.y + box->box.height)
+    return FALSE;
+
+  return TRUE;
+}
+
+gboolean
+_gtk_rounded_box_contains_rectangle (const GtkRoundedBox *box,
+                                     gdouble              x1,
+                                     gdouble              y1,
+                                     gdouble              x2,
+                                     gdouble              y2)
+{
+  if (x1 < box->box.x ||
+      y1 < box->box.y ||
+      x2 >= box->box.x + box->box.width ||
+      y2 >= box->box.y + box->box.width)
+    return FALSE;
+
+  if (x1 < box->box.x + box->corner[GTK_CSS_TOP_LEFT].horizontal &&
+      y1 < box->box.y + box->corner[GTK_CSS_TOP_LEFT].vertical)
+    return FALSE;
+
+  if (x2 > box->box.x + box->box.width - box->corner[GTK_CSS_TOP_RIGHT].horizontal &&
+      y1 < box->box.y + box->corner[GTK_CSS_TOP_RIGHT].vertical)
+    return FALSE;
+
+  if (x2 > box->box.x + box->box.width - box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal &&
+      y2 > box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_RIGHT].vertical)
+    return FALSE;
+
+  if (x1 < box->box.x + box->corner[GTK_CSS_BOTTOM_LEFT].horizontal &&
+      y2 > box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_LEFT].vertical)
+    return FALSE;
+
+  return TRUE;
+}
diff --git a/gtk/gtkroundedboxprivate.h b/gtk/gtkroundedboxprivate.h
index 483216a..3f98e20 100644
--- a/gtk/gtkroundedboxprivate.h
+++ b/gtk/gtkroundedboxprivate.h
@@ -91,6 +91,16 @@ void            _gtk_rounded_box_path_left                      (const GtkRounde
                                                                  cairo_t             *cr);
 void            _gtk_rounded_box_clip_path                      (const GtkRoundedBox *box,
                                                                  cairo_t             *cr);
+gboolean        _gtk_rounded_box_intersects_rectangle           (const GtkRoundedBox *box,
+                                                                 gdouble              x1,
+                                                                 gdouble              y1,
+                                                                 gdouble              x2,
+                                                                 gdouble              y2);
+gboolean        _gtk_rounded_box_contains_rectangle             (const GtkRoundedBox *box,
+                                                                 gdouble              x1,
+                                                                 gdouble              y1,
+                                                                 gdouble              x2,
+                                                                 gdouble              y2);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]