forked from AuroraMiddleware/gtk
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:
parent
998055c835
commit
34a62d779b
@ -71,6 +71,13 @@ typedef enum /*< skip >*/ {
|
||||
GTK_CSS_LEFT
|
||||
} 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 _GtkCssBorderImageRepeat GtkCssBorderImageRepeat;
|
||||
|
||||
|
@ -56,23 +56,23 @@ 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->top_left.horizontal +
|
||||
box->top_right.horizontal));
|
||||
factor = MIN (factor, box->box.height / (box->top_right.vertical +
|
||||
box->bottom_right.vertical));
|
||||
factor = MIN (factor, box->box.width / (box->bottom_right.horizontal +
|
||||
box->bottom_left.horizontal));
|
||||
factor = MIN (factor, box->box.height / (box->top_left.vertical +
|
||||
box->bottom_left.vertical));
|
||||
factor = MIN (factor, box->box.width / (box->corner[GTK_CSS_TOP_LEFT].horizontal +
|
||||
box->corner[GTK_CSS_TOP_RIGHT].horizontal));
|
||||
factor = MIN (factor, box->box.height / (box->corner[GTK_CSS_TOP_RIGHT].vertical +
|
||||
box->corner[GTK_CSS_BOTTOM_RIGHT].vertical));
|
||||
factor = MIN (factor, box->box.width / (box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal +
|
||||
box->corner[GTK_CSS_BOTTOM_LEFT].horizontal));
|
||||
factor = MIN (factor, box->box.height / (box->corner[GTK_CSS_TOP_LEFT].vertical +
|
||||
box->corner[GTK_CSS_BOTTOM_LEFT].vertical));
|
||||
|
||||
box->top_left.horizontal *= factor;
|
||||
box->top_left.vertical *= factor;
|
||||
box->top_right.horizontal *= factor;
|
||||
box->top_right.vertical *= factor;
|
||||
box->bottom_right.horizontal *= factor;
|
||||
box->bottom_right.vertical *= factor;
|
||||
box->bottom_left.horizontal *= factor;
|
||||
box->bottom_left.vertical *= factor;
|
||||
box->corner[GTK_CSS_TOP_LEFT].horizontal *= factor;
|
||||
box->corner[GTK_CSS_TOP_LEFT].vertical *= factor;
|
||||
box->corner[GTK_CSS_TOP_RIGHT].horizontal *= factor;
|
||||
box->corner[GTK_CSS_TOP_RIGHT].vertical *= factor;
|
||||
box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal *= factor;
|
||||
box->corner[GTK_CSS_BOTTOM_RIGHT].vertical *= factor;
|
||||
box->corner[GTK_CSS_BOTTOM_LEFT].horizontal *= factor;
|
||||
box->corner[GTK_CSS_BOTTOM_LEFT].vertical *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
@ -81,33 +81,31 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
|
||||
GtkStateFlags state,
|
||||
GtkJunctionSides junction)
|
||||
{
|
||||
GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
|
||||
GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
|
||||
GtkCssBorderCornerRadius *corner[4];
|
||||
guint i;
|
||||
|
||||
gtk_theming_engine_get (engine, state,
|
||||
/* Can't use border-radius as it's an int for
|
||||
* backwards compat */
|
||||
"border-top-left-radius", &top_left_radius,
|
||||
"border-top-right-radius", &top_right_radius,
|
||||
"border-bottom-right-radius", &bottom_right_radius,
|
||||
"border-bottom-left-radius", &bottom_left_radius,
|
||||
"border-top-left-radius", &corner[GTK_CSS_TOP_LEFT],
|
||||
"border-top-right-radius", &corner[GTK_CSS_TOP_RIGHT],
|
||||
"border-bottom-right-radius", &corner[GTK_CSS_BOTTOM_RIGHT],
|
||||
"border-bottom-left-radius", &corner[GTK_CSS_BOTTOM_LEFT],
|
||||
NULL);
|
||||
|
||||
if (top_left_radius && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0)
|
||||
box->top_left = *top_left_radius;
|
||||
if (top_right_radius && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0)
|
||||
box->top_right = *top_right_radius;
|
||||
if (bottom_right_radius && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0)
|
||||
box->bottom_right = *bottom_right_radius;
|
||||
if (bottom_left_radius && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0)
|
||||
box->bottom_left = *bottom_left_radius;
|
||||
if (corner[GTK_CSS_TOP_LEFT] && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0)
|
||||
box->corner[GTK_CSS_TOP_LEFT] = *corner[GTK_CSS_TOP_LEFT];
|
||||
if (corner[GTK_CSS_TOP_RIGHT] && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0)
|
||||
box->corner[GTK_CSS_TOP_RIGHT] = *corner[GTK_CSS_TOP_RIGHT];
|
||||
if (corner[GTK_CSS_BOTTOM_RIGHT] && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0)
|
||||
box->corner[GTK_CSS_BOTTOM_RIGHT] = *corner[GTK_CSS_BOTTOM_RIGHT];
|
||||
if (corner[GTK_CSS_BOTTOM_LEFT] && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0)
|
||||
box->corner[GTK_CSS_BOTTOM_LEFT] = *corner[GTK_CSS_BOTTOM_LEFT];
|
||||
|
||||
gtk_rounded_box_clamp_border_radius (box);
|
||||
|
||||
g_free (top_left_radius);
|
||||
g_free (top_right_radius);
|
||||
g_free (bottom_right_radius);
|
||||
g_free (bottom_left_radius);
|
||||
for (i = 0; i < 4; i++)
|
||||
g_free (corner[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -153,10 +151,10 @@ _gtk_rounded_box_grow (GtkRoundedBox *box,
|
||||
box->box.height += top + bottom;
|
||||
}
|
||||
|
||||
gtk_css_border_radius_grow (&box->top_left, left, top);
|
||||
gtk_css_border_radius_grow (&box->top_right, right, bottom);
|
||||
gtk_css_border_radius_grow (&box->bottom_right, right, top);
|
||||
gtk_css_border_radius_grow (&box->bottom_left, left, bottom);
|
||||
gtk_css_border_radius_grow (&box->corner[GTK_CSS_TOP_LEFT], left, top);
|
||||
gtk_css_border_radius_grow (&box->corner[GTK_CSS_TOP_RIGHT], right, bottom);
|
||||
gtk_css_border_radius_grow (&box->corner[GTK_CSS_BOTTOM_RIGHT], right, top);
|
||||
gtk_css_border_radius_grow (&box->corner[GTK_CSS_BOTTOM_LEFT], left, bottom);
|
||||
}
|
||||
|
||||
void
|
||||
@ -223,28 +221,28 @@ _gtk_rounded_box_path (const GtkRoundedBox *box,
|
||||
cairo_new_sub_path (cr);
|
||||
|
||||
_cairo_ellipsis (cr,
|
||||
box->box.x + box->top_left.horizontal,
|
||||
box->box.y + box->top_left.vertical,
|
||||
box->top_left.horizontal,
|
||||
box->top_left.vertical,
|
||||
box->box.x + box->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
box->box.y + box->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
box->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
box->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
G_PI, 3 * G_PI / 2);
|
||||
_cairo_ellipsis (cr,
|
||||
box->box.x + box->box.width - box->top_right.horizontal,
|
||||
box->box.y + box->top_right.vertical,
|
||||
box->top_right.horizontal,
|
||||
box->top_right.vertical,
|
||||
box->box.x + box->box.width - box->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
box->box.y + box->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
box->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
box->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
- G_PI / 2, 0);
|
||||
_cairo_ellipsis (cr,
|
||||
box->box.x + box->box.width - box->bottom_right.horizontal,
|
||||
box->box.y + box->box.height - box->bottom_right.vertical,
|
||||
box->bottom_right.horizontal,
|
||||
box->bottom_right.vertical,
|
||||
box->box.x + box->box.width - box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
box->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
0, G_PI / 2);
|
||||
_cairo_ellipsis (cr,
|
||||
box->box.x + box->bottom_left.horizontal,
|
||||
box->box.y + box->box.height - box->bottom_left.vertical,
|
||||
box->bottom_left.horizontal,
|
||||
box->bottom_left.vertical,
|
||||
box->box.x + box->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
box->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
box->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
G_PI / 2, G_PI);
|
||||
}
|
||||
|
||||
@ -256,29 +254,29 @@ _gtk_rounded_box_path_top (const GtkRoundedBox *outer,
|
||||
cairo_new_sub_path (cr);
|
||||
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->top_left.horizontal,
|
||||
outer->box.y + outer->top_left.vertical,
|
||||
outer->top_left.horizontal,
|
||||
outer->top_left.vertical,
|
||||
outer->box.x + outer->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
outer->box.y + outer->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
outer->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
outer->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
5 * G_PI / 4, 3 * G_PI / 2);
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->box.width - outer->top_right.horizontal,
|
||||
outer->box.y + outer->top_right.vertical,
|
||||
outer->top_right.horizontal,
|
||||
outer->top_right.vertical,
|
||||
outer->box.x + outer->box.width - outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
outer->box.y + outer->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
outer->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
- G_PI / 2, -G_PI / 4);
|
||||
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->box.width - inner->top_right.horizontal,
|
||||
inner->box.y + inner->top_right.vertical,
|
||||
inner->top_right.horizontal,
|
||||
inner->top_right.vertical,
|
||||
inner->box.x + inner->box.width - inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
inner->box.y + inner->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
inner->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
-G_PI / 4, - G_PI / 2);
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->top_left.horizontal,
|
||||
inner->box.y + inner->top_left.vertical,
|
||||
inner->top_left.horizontal,
|
||||
inner->top_left.vertical,
|
||||
inner->box.x + inner->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
inner->box.y + inner->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
inner->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
inner->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
3 * G_PI / 2, 5 * G_PI / 4);
|
||||
|
||||
cairo_close_path (cr);
|
||||
@ -292,29 +290,29 @@ _gtk_rounded_box_path_right (const GtkRoundedBox *outer,
|
||||
cairo_new_sub_path (cr);
|
||||
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->box.width - outer->top_right.horizontal,
|
||||
outer->box.y + outer->top_right.vertical,
|
||||
outer->top_right.horizontal,
|
||||
outer->top_right.vertical,
|
||||
outer->box.x + outer->box.width - outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
outer->box.y + outer->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
outer->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
outer->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
- G_PI / 4, 0);
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->box.width - outer->bottom_right.horizontal,
|
||||
outer->box.y + outer->box.height - outer->bottom_right.vertical,
|
||||
outer->bottom_right.horizontal,
|
||||
outer->bottom_right.vertical,
|
||||
outer->box.x + outer->box.width - outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
0, G_PI / 4);
|
||||
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->box.width - inner->bottom_right.horizontal,
|
||||
inner->box.y + inner->box.height - inner->bottom_right.vertical,
|
||||
inner->bottom_right.horizontal,
|
||||
inner->bottom_right.vertical,
|
||||
inner->box.x + inner->box.width - inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
G_PI / 4, 0);
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->box.width - inner->top_right.horizontal,
|
||||
inner->box.y + inner->top_right.vertical,
|
||||
inner->top_right.horizontal,
|
||||
inner->top_right.vertical,
|
||||
inner->box.x + inner->box.width - inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
inner->box.y + inner->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
inner->corner[GTK_CSS_TOP_RIGHT].horizontal,
|
||||
inner->corner[GTK_CSS_TOP_RIGHT].vertical,
|
||||
0, - G_PI / 4);
|
||||
|
||||
cairo_close_path (cr);
|
||||
@ -328,29 +326,29 @@ _gtk_rounded_box_path_bottom (const GtkRoundedBox *outer,
|
||||
cairo_new_sub_path (cr);
|
||||
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->box.width - outer->bottom_right.horizontal,
|
||||
outer->box.y + outer->box.height - outer->bottom_right.vertical,
|
||||
outer->bottom_right.horizontal,
|
||||
outer->bottom_right.vertical,
|
||||
outer->box.x + outer->box.width - outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
outer->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
outer->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
G_PI / 4, G_PI / 2);
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->bottom_left.horizontal,
|
||||
outer->box.y + outer->box.height - outer->bottom_left.vertical,
|
||||
outer->bottom_left.horizontal,
|
||||
outer->bottom_left.vertical,
|
||||
outer->box.x + outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
G_PI / 2, 3 * G_PI / 4);
|
||||
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->bottom_left.horizontal,
|
||||
inner->box.y + inner->box.height - inner->bottom_left.vertical,
|
||||
inner->bottom_left.horizontal,
|
||||
inner->bottom_left.vertical,
|
||||
inner->box.x + inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
3 * G_PI / 4, G_PI / 2);
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->box.width - inner->bottom_right.horizontal,
|
||||
inner->box.y + inner->box.height - inner->bottom_right.vertical,
|
||||
inner->bottom_right.horizontal,
|
||||
inner->bottom_right.vertical,
|
||||
inner->box.x + inner->box.width - inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
inner->corner[GTK_CSS_BOTTOM_RIGHT].horizontal,
|
||||
inner->corner[GTK_CSS_BOTTOM_RIGHT].vertical,
|
||||
G_PI / 2, G_PI / 4);
|
||||
|
||||
cairo_close_path (cr);
|
||||
@ -364,29 +362,29 @@ _gtk_rounded_box_path_left (const GtkRoundedBox *outer,
|
||||
cairo_new_sub_path (cr);
|
||||
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->bottom_left.horizontal,
|
||||
outer->box.y + outer->box.height - outer->bottom_left.vertical,
|
||||
outer->bottom_left.horizontal,
|
||||
outer->bottom_left.vertical,
|
||||
outer->box.x + outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
outer->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
3 * G_PI / 4, G_PI);
|
||||
_cairo_ellipsis (cr,
|
||||
outer->box.x + outer->top_left.horizontal,
|
||||
outer->box.y + outer->top_left.vertical,
|
||||
outer->top_left.horizontal,
|
||||
outer->top_left.vertical,
|
||||
outer->box.x + outer->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
outer->box.y + outer->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
outer->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
outer->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
G_PI, 5 * G_PI / 4);
|
||||
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->top_left.horizontal,
|
||||
inner->box.y + inner->top_left.vertical,
|
||||
inner->top_left.horizontal,
|
||||
inner->top_left.vertical,
|
||||
inner->box.x + inner->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
inner->box.y + inner->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
inner->corner[GTK_CSS_TOP_LEFT].horizontal,
|
||||
inner->corner[GTK_CSS_TOP_LEFT].vertical,
|
||||
5 * G_PI / 4, G_PI);
|
||||
_cairo_ellipsis_negative (cr,
|
||||
inner->box.x + inner->bottom_left.horizontal,
|
||||
inner->box.y + inner->box.height - inner->bottom_left.vertical,
|
||||
inner->bottom_left.horizontal,
|
||||
inner->bottom_left.vertical,
|
||||
inner->box.x + inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal,
|
||||
inner->corner[GTK_CSS_BOTTOM_LEFT].vertical,
|
||||
G_PI, 3 * G_PI / 4);
|
||||
|
||||
cairo_close_path (cr);
|
||||
|
@ -34,10 +34,7 @@ typedef struct _GtkRoundedBox GtkRoundedBox;
|
||||
struct _GtkRoundedBox {
|
||||
/*< private >*/
|
||||
cairo_rectangle_t box;
|
||||
GtkCssBorderCornerRadius top_left;
|
||||
GtkCssBorderCornerRadius top_right;
|
||||
GtkCssBorderCornerRadius bottom_right;
|
||||
GtkCssBorderCornerRadius bottom_left;
|
||||
GtkCssBorderCornerRadius corner[4];
|
||||
};
|
||||
|
||||
void _gtk_rounded_box_init_rect (GtkRoundedBox *box,
|
||||
|
Loading…
Reference in New Issue
Block a user