[gtk+] roundedbox: Fix border radius grow algorithm



commit e0b1943c97a0becc239d22283835a3cbead0d5bc
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jun 13 05:49:12 2011 +0200

    roundedbox: Fix border radius grow algorithm
    
    When one radius gets to 0, the other should be set to 0, too. Otherwise
    the paths constructed from it will not be correct.

 gtk/gtkroundedbox.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c
index 8433282..3414e48 100644
--- a/gtk/gtkroundedbox.c
+++ b/gtk/gtkroundedbox.c
@@ -81,6 +81,20 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox    *box,
   g_free (bottom_left_radius);
 }
 
+static void
+gtk_css_border_radius_grow (GtkCssBorderCornerRadius *corner,
+                            double                    horizontal,
+                            double                    vertical)
+{
+  corner->horizontal += horizontal;
+  corner->vertical += vertical;
+
+  if (corner->horizontal <= 0 || corner->vertical <= 0)
+    {
+      corner->horizontal = 0;
+      corner->vertical = 0;
+    }
+}
 void
 _gtk_rounded_box_grow (GtkRoundedBox *box,
                        double         top,
@@ -110,22 +124,10 @@ _gtk_rounded_box_grow (GtkRoundedBox *box,
       box->box.height += top + bottom;
     }
 
-  if (box->border_radius.top_left.horizontal)
-    box->border_radius.top_left.horizontal = MAX (0, box->border_radius.top_left.horizontal + left);
-  if (box->border_radius.top_left.vertical)
-    box->border_radius.top_left.vertical = MAX (0, box->border_radius.top_left.vertical + top);
-  if (box->border_radius.top_right.horizontal)
-    box->border_radius.top_right.horizontal = MAX (0, box->border_radius.top_right.horizontal + right);
-  if (box->border_radius.top_right.vertical)
-    box->border_radius.top_right.vertical = MAX (0, box->border_radius.top_right.vertical + top);
-  if (box->border_radius.bottom_right.horizontal)
-    box->border_radius.bottom_right.horizontal = MAX (0, box->border_radius.bottom_right.horizontal + right);
-  if (box->border_radius.bottom_right.vertical)
-    box->border_radius.bottom_right.vertical = MAX (0, box->border_radius.bottom_right.vertical + bottom);
-  if (box->border_radius.bottom_left.horizontal)
-    box->border_radius.bottom_left.horizontal = MAX (0, box->border_radius.bottom_left.horizontal + left);
-  if (box->border_radius.bottom_left.vertical)
-    box->border_radius.bottom_left.vertical = MAX (0, box->border_radius.bottom_left.vertical + bottom);
+  gtk_css_border_radius_grow (&box->border_radius.top_left, left, top);
+  gtk_css_border_radius_grow (&box->border_radius.top_right, right, bottom);
+  gtk_css_border_radius_grow (&box->border_radius.bottom_right, right, top);
+  gtk_css_border_radius_grow (&box->border_radius.bottom_left, left, bottom);
 }
 
 void



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