css: Introduce a corner order enum

Same order as CSS again.

The nice thing about this is that now edge i in a rounded box follows
corner i and is followed by corner (i + 1) % 4.
This commit is contained in:
Benjamin Otte 2012-01-07 22:40:17 +01:00
parent 998055c835
commit 34a62d779b
3 changed files with 124 additions and 122 deletions

View File

@ -71,6 +71,13 @@ typedef enum /*< skip >*/ {
GTK_CSS_LEFT GTK_CSS_LEFT
} GtkCssSide; } GtkCssSide;
typedef enum /*< skip >*/ {
GTK_CSS_TOP_LEFT,
GTK_CSS_TOP_RIGHT,
GTK_CSS_BOTTOM_RIGHT,
GTK_CSS_BOTTOM_LEFT
} GtkCssCorner;
typedef struct _GtkCssBorderCornerRadius GtkCssBorderCornerRadius; typedef struct _GtkCssBorderCornerRadius GtkCssBorderCornerRadius;
typedef struct _GtkCssBorderImageRepeat GtkCssBorderImageRepeat; typedef struct _GtkCssBorderImageRepeat GtkCssBorderImageRepeat;

View File

@ -56,23 +56,23 @@ gtk_rounded_box_clamp_border_radius (GtkRoundedBox *box)
gdouble factor = 1.0; gdouble factor = 1.0;
/* note: division by zero leads to +INF, which is > factor, so will be ignored */ /* note: division by zero leads to +INF, which is > factor, so will be ignored */
factor = MIN (factor, box->box.width / (box->top_left.horizontal + factor = MIN (factor, box->box.width / (box->corner[GTK_CSS_TOP_LEFT].horizontal +
box->top_right.horizontal)); box->corner[GTK_CSS_TOP_RIGHT].horizontal));
factor = MIN (factor, box->box.height / (box->top_right.vertical + factor = MIN (factor, box->box.height / (box->corner[GTK_CSS_TOP_RIGHT].vertical +
box->bottom_right.vertical)); box->corner[GTK_CSS_BOTTOM_RIGHT].vertical));
factor = MIN (factor, box->box.width / (box->bottom_right.horizontal + factor = MIN (factor, box->box.width / (box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal +
box->bottom_left.horizontal)); box->corner[GTK_CSS_BOTTOM_LEFT].horizontal));
factor = MIN (factor, box->box.height / (box->top_left.vertical + factor = MIN (factor, box->box.height / (box->corner[GTK_CSS_TOP_LEFT].vertical +
box->bottom_left.vertical)); box->corner[GTK_CSS_BOTTOM_LEFT].vertical));
box->top_left.horizontal *= factor; box->corner[GTK_CSS_TOP_LEFT].horizontal *= factor;
box->top_left.vertical *= factor; box->corner[GTK_CSS_TOP_LEFT].vertical *= factor;
box->top_right.horizontal *= factor; box->corner[GTK_CSS_TOP_RIGHT].horizontal *= factor;
box->top_right.vertical *= factor; box->corner[GTK_CSS_TOP_RIGHT].vertical *= factor;
box->bottom_right.horizontal *= factor; box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal *= factor;
box->bottom_right.vertical *= factor; box->corner[GTK_CSS_BOTTOM_RIGHT].vertical *= factor;
box->bottom_left.horizontal *= factor; box->corner[GTK_CSS_BOTTOM_LEFT].horizontal *= factor;
box->bottom_left.vertical *= factor; box->corner[GTK_CSS_BOTTOM_LEFT].vertical *= factor;
} }
void void
@ -81,33 +81,31 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
GtkStateFlags state, GtkStateFlags state,
GtkJunctionSides junction) GtkJunctionSides junction)
{ {
GtkCssBorderCornerRadius *top_left_radius, *top_right_radius; GtkCssBorderCornerRadius *corner[4];
GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius; guint i;
gtk_theming_engine_get (engine, state, gtk_theming_engine_get (engine, state,
/* Can't use border-radius as it's an int for /* Can't use border-radius as it's an int for
* backwards compat */ * backwards compat */
"border-top-left-radius", &top_left_radius, "border-top-left-radius", &corner[GTK_CSS_TOP_LEFT],
"border-top-right-radius", &top_right_radius, "border-top-right-radius", &corner[GTK_CSS_TOP_RIGHT],
"border-bottom-right-radius", &bottom_right_radius, "border-bottom-right-radius", &corner[GTK_CSS_BOTTOM_RIGHT],
"border-bottom-left-radius", &bottom_left_radius, "border-bottom-left-radius", &corner[GTK_CSS_BOTTOM_LEFT],
NULL); NULL);
if (top_left_radius && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0) if (corner[GTK_CSS_TOP_LEFT] && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0)
box->top_left = *top_left_radius; box->corner[GTK_CSS_TOP_LEFT] = *corner[GTK_CSS_TOP_LEFT];
if (top_right_radius && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0) if (corner[GTK_CSS_TOP_RIGHT] && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0)
box->top_right = *top_right_radius; box->corner[GTK_CSS_TOP_RIGHT] = *corner[GTK_CSS_TOP_RIGHT];
if (bottom_right_radius && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0) if (corner[GTK_CSS_BOTTOM_RIGHT] && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0)
box->bottom_right = *bottom_right_radius; box->corner[GTK_CSS_BOTTOM_RIGHT] = *corner[GTK_CSS_BOTTOM_RIGHT];
if (bottom_left_radius && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0) if (corner[GTK_CSS_BOTTOM_LEFT] && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0)
box->bottom_left = *bottom_left_radius; box->corner[GTK_CSS_BOTTOM_LEFT] = *corner[GTK_CSS_BOTTOM_LEFT];
gtk_rounded_box_clamp_border_radius (box); gtk_rounded_box_clamp_border_radius (box);
g_free (top_left_radius); for (i = 0; i < 4; i++)
g_free (top_right_radius); g_free (corner[i]);
g_free (bottom_right_radius);
g_free (bottom_left_radius);
} }
static void static void
@ -153,10 +151,10 @@ _gtk_rounded_box_grow (GtkRoundedBox *box,
box->box.height += top + bottom; box->box.height += top + bottom;
} }
gtk_css_border_radius_grow (&box->top_left, left, top); gtk_css_border_radius_grow (&box->corner[GTK_CSS_TOP_LEFT], left, top);
gtk_css_border_radius_grow (&box->top_right, right, bottom); gtk_css_border_radius_grow (&box->corner[GTK_CSS_TOP_RIGHT], right, bottom);
gtk_css_border_radius_grow (&box->bottom_right, right, top); gtk_css_border_radius_grow (&box->corner[GTK_CSS_BOTTOM_RIGHT], right, top);
gtk_css_border_radius_grow (&box->bottom_left, left, bottom); gtk_css_border_radius_grow (&box->corner[GTK_CSS_BOTTOM_LEFT], left, bottom);
} }
void void
@ -223,28 +221,28 @@ _gtk_rounded_box_path (const GtkRoundedBox *box,
cairo_new_sub_path (cr); cairo_new_sub_path (cr);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->top_left.horizontal, box->box.x + box->corner[GTK_CSS_TOP_LEFT].horizontal,
box->box.y + box->top_left.vertical, box->box.y + box->corner[GTK_CSS_TOP_LEFT].vertical,
box->top_left.horizontal, box->corner[GTK_CSS_TOP_LEFT].horizontal,
box->top_left.vertical, box->corner[GTK_CSS_TOP_LEFT].vertical,
G_PI, 3 * G_PI / 2); G_PI, 3 * G_PI / 2);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->box.width - box->top_right.horizontal, box->box.x + box->box.width - box->corner[GTK_CSS_TOP_RIGHT].horizontal,
box->box.y + box->top_right.vertical, box->box.y + box->corner[GTK_CSS_TOP_RIGHT].vertical,
box->top_right.horizontal, box->corner[GTK_CSS_TOP_RIGHT].horizontal,
box->top_right.vertical, box->corner[GTK_CSS_TOP_RIGHT].vertical,
- G_PI / 2, 0); - G_PI / 2, 0);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->box.width - box->bottom_right.horizontal, box->box.x + box->box.width - box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
box->box.y + box->box.height - box->bottom_right.vertical, box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
box->bottom_right.horizontal, box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
box->bottom_right.vertical, box->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
0, G_PI / 2); 0, G_PI / 2);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->bottom_left.horizontal, box->box.x + box->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
box->box.y + box->box.height - box->bottom_left.vertical, box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_LEFT].vertical,
box->bottom_left.horizontal, box->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
box->bottom_left.vertical, box->corner[GTK_CSS_BOTTOM_LEFT].vertical,
G_PI / 2, G_PI); G_PI / 2, G_PI);
} }
@ -256,29 +254,29 @@ _gtk_rounded_box_path_top (const GtkRoundedBox *outer,
cairo_new_sub_path (cr); cairo_new_sub_path (cr);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->top_left.horizontal, outer->box.x + outer->corner[GTK_CSS_TOP_LEFT].horizontal,
outer->box.y + outer->top_left.vertical, outer->box.y + outer->corner[GTK_CSS_TOP_LEFT].vertical,
outer->top_left.horizontal, outer->corner[GTK_CSS_TOP_LEFT].horizontal,
outer->top_left.vertical, outer->corner[GTK_CSS_TOP_LEFT].vertical,
5 * G_PI / 4, 3 * G_PI / 2); 5 * G_PI / 4, 3 * G_PI / 2);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->box.width - outer->top_right.horizontal, outer->box.x + outer->box.width - outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
outer->box.y + outer->top_right.vertical, outer->box.y + outer->corner[GTK_CSS_TOP_RIGHT].vertical,
outer->top_right.horizontal, outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
outer->top_right.vertical, outer->corner[GTK_CSS_TOP_RIGHT].vertical,
- G_PI / 2, -G_PI / 4); - G_PI / 2, -G_PI / 4);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->top_right.horizontal, inner->box.x + inner->box.width - inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
inner->box.y + inner->top_right.vertical, inner->box.y + inner->corner[GTK_CSS_TOP_RIGHT].vertical,
inner->top_right.horizontal, inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
inner->top_right.vertical, inner->corner[GTK_CSS_TOP_RIGHT].vertical,
-G_PI / 4, - G_PI / 2); -G_PI / 4, - G_PI / 2);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->top_left.horizontal, inner->box.x + inner->corner[GTK_CSS_TOP_LEFT].horizontal,
inner->box.y + inner->top_left.vertical, inner->box.y + inner->corner[GTK_CSS_TOP_LEFT].vertical,
inner->top_left.horizontal, inner->corner[GTK_CSS_TOP_LEFT].horizontal,
inner->top_left.vertical, inner->corner[GTK_CSS_TOP_LEFT].vertical,
3 * G_PI / 2, 5 * G_PI / 4); 3 * G_PI / 2, 5 * G_PI / 4);
cairo_close_path (cr); cairo_close_path (cr);
@ -292,29 +290,29 @@ _gtk_rounded_box_path_right (const GtkRoundedBox *outer,
cairo_new_sub_path (cr); cairo_new_sub_path (cr);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->box.width - outer->top_right.horizontal, outer->box.x + outer->box.width - outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
outer->box.y + outer->top_right.vertical, outer->box.y + outer->corner[GTK_CSS_TOP_RIGHT].vertical,
outer->top_right.horizontal, outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
outer->top_right.vertical, outer->corner[GTK_CSS_TOP_RIGHT].vertical,
- G_PI / 4, 0); - G_PI / 4, 0);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->box.width - outer->bottom_right.horizontal, outer->box.x + outer->box.width - outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
outer->box.y + outer->box.height - outer->bottom_right.vertical, outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
outer->bottom_right.horizontal, outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
outer->bottom_right.vertical, outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
0, G_PI / 4); 0, G_PI / 4);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->bottom_right.horizontal, inner->box.x + inner->box.width - inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
inner->box.y + inner->box.height - inner->bottom_right.vertical, inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
inner->bottom_right.horizontal, inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
inner->bottom_right.vertical, inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
G_PI / 4, 0); G_PI / 4, 0);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->top_right.horizontal, inner->box.x + inner->box.width - inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
inner->box.y + inner->top_right.vertical, inner->box.y + inner->corner[GTK_CSS_TOP_RIGHT].vertical,
inner->top_right.horizontal, inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
inner->top_right.vertical, inner->corner[GTK_CSS_TOP_RIGHT].vertical,
0, - G_PI / 4); 0, - G_PI / 4);
cairo_close_path (cr); cairo_close_path (cr);
@ -328,29 +326,29 @@ _gtk_rounded_box_path_bottom (const GtkRoundedBox *outer,
cairo_new_sub_path (cr); cairo_new_sub_path (cr);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->box.width - outer->bottom_right.horizontal, outer->box.x + outer->box.width - outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
outer->box.y + outer->box.height - outer->bottom_right.vertical, outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
outer->bottom_right.horizontal, outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
outer->bottom_right.vertical, outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
G_PI / 4, G_PI / 2); G_PI / 4, G_PI / 2);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->bottom_left.horizontal, outer->box.x + outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
outer->box.y + outer->box.height - outer->bottom_left.vertical, outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
outer->bottom_left.horizontal, outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
outer->bottom_left.vertical, outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
G_PI / 2, 3 * G_PI / 4); G_PI / 2, 3 * G_PI / 4);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->bottom_left.horizontal, inner->box.x + inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
inner->box.y + inner->box.height - inner->bottom_left.vertical, inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
inner->bottom_left.horizontal, inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
inner->bottom_left.vertical, inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
3 * G_PI / 4, G_PI / 2); 3 * G_PI / 4, G_PI / 2);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->bottom_right.horizontal, inner->box.x + inner->box.width - inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
inner->box.y + inner->box.height - inner->bottom_right.vertical, inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
inner->bottom_right.horizontal, inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
inner->bottom_right.vertical, inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
G_PI / 2, G_PI / 4); G_PI / 2, G_PI / 4);
cairo_close_path (cr); cairo_close_path (cr);
@ -364,29 +362,29 @@ _gtk_rounded_box_path_left (const GtkRoundedBox *outer,
cairo_new_sub_path (cr); cairo_new_sub_path (cr);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->bottom_left.horizontal, outer->box.x + outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
outer->box.y + outer->box.height - outer->bottom_left.vertical, outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
outer->bottom_left.horizontal, outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
outer->bottom_left.vertical, outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
3 * G_PI / 4, G_PI); 3 * G_PI / 4, G_PI);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->top_left.horizontal, outer->box.x + outer->corner[GTK_CSS_TOP_LEFT].horizontal,
outer->box.y + outer->top_left.vertical, outer->box.y + outer->corner[GTK_CSS_TOP_LEFT].vertical,
outer->top_left.horizontal, outer->corner[GTK_CSS_TOP_LEFT].horizontal,
outer->top_left.vertical, outer->corner[GTK_CSS_TOP_LEFT].vertical,
G_PI, 5 * G_PI / 4); G_PI, 5 * G_PI / 4);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->top_left.horizontal, inner->box.x + inner->corner[GTK_CSS_TOP_LEFT].horizontal,
inner->box.y + inner->top_left.vertical, inner->box.y + inner->corner[GTK_CSS_TOP_LEFT].vertical,
inner->top_left.horizontal, inner->corner[GTK_CSS_TOP_LEFT].horizontal,
inner->top_left.vertical, inner->corner[GTK_CSS_TOP_LEFT].vertical,
5 * G_PI / 4, G_PI); 5 * G_PI / 4, G_PI);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->bottom_left.horizontal, inner->box.x + inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
inner->box.y + inner->box.height - inner->bottom_left.vertical, inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
inner->bottom_left.horizontal, inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
inner->bottom_left.vertical, inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
G_PI, 3 * G_PI / 4); G_PI, 3 * G_PI / 4);
cairo_close_path (cr); cairo_close_path (cr);

View File

@ -34,10 +34,7 @@ typedef struct _GtkRoundedBox GtkRoundedBox;
struct _GtkRoundedBox { struct _GtkRoundedBox {
/*< private >*/ /*< private >*/
cairo_rectangle_t box; cairo_rectangle_t box;
GtkCssBorderCornerRadius top_left; GtkCssBorderCornerRadius corner[4];
GtkCssBorderCornerRadius top_right;
GtkCssBorderCornerRadius bottom_right;
GtkCssBorderCornerRadius bottom_left;
}; };
void _gtk_rounded_box_init_rect (GtkRoundedBox *box, void _gtk_rounded_box_init_rect (GtkRoundedBox *box,