diff options
author | Andrea Cimitan <andrea.cimitan@canonical.com> | 2011-07-20 23:37:26 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2011-07-21 02:43:54 +0200 |
commit | b3f03d092fd71ba6f31a0dda20f1b00fa0d99eb3 (patch) | |
tree | 32d7fa981b0152d279b776bf622e6b540ae6796b /gtk | |
parent | a02b82056a37df9e235ba09afb78cc8bb299c797 (diff) | |
download | gtk+-b3f03d092fd71ba6f31a0dda20f1b00fa0d99eb3.tar.gz |
roundedbox: Clamp border radius to box size
Note that clamping in rounded_box_grow() is not necessary as that
function cannot lead to overlap unless the rounded box was overlapping
previously.
https://bugzilla.gnome.org/show_bug.cgi?id=655009
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkroundedbox.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c index 5b1eefcfe1..c6512c1108 100644 --- a/gtk/gtkroundedbox.c +++ b/gtk/gtkroundedbox.c @@ -48,6 +48,32 @@ _gtk_rounded_box_init_rect (GtkRoundedBox *box, memset (&box->border_radius, 0, sizeof (GtkCssBorderRadius)); } +/* clamp border radius, following CSS specs */ +static void +gtk_rounded_box_clamp_border_radius (GtkRoundedBox *box) +{ + gdouble factor = 1.0; + + /* note: division by zero leads to +INF, which is > factor, so will be ignored */ + factor = MIN (factor, box->box.width / (box->border_radius.top_left.horizontal + + box->border_radius.top_right.horizontal)); + factor = MIN (factor, box->box.height / (box->border_radius.top_right.vertical + + box->border_radius.bottom_right.vertical)); + factor = MIN (factor, box->box.width / (box->border_radius.bottom_right.horizontal + + box->border_radius.bottom_left.horizontal)); + factor = MIN (factor, box->box.height / (box->border_radius.top_left.vertical + + box->border_radius.bottom_left.vertical)); + + box->border_radius.top_left.horizontal *= factor; + box->border_radius.top_left.vertical *= factor; + box->border_radius.top_right.horizontal *= factor; + box->border_radius.top_right.vertical *= factor; + box->border_radius.bottom_right.horizontal *= factor; + box->border_radius.bottom_right.vertical *= factor; + box->border_radius.bottom_left.horizontal *= factor; + box->border_radius.bottom_left.vertical *= factor; +} + void _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box, GtkThemingEngine *engine, @@ -75,6 +101,8 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box, if (bottom_left_radius && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0) box->border_radius.bottom_left = *bottom_left_radius; + gtk_rounded_box_clamp_border_radius (box); + g_free (top_left_radius); g_free (top_right_radius); g_free (bottom_right_radius); |