roundedbox: Use a graphene_size_t for the corners

Obviously, I'm trying to port GtkRoundedBox to GskRoundedRect.

This is the second step on that path.
This commit is contained in:
Benjamin Otte 2016-12-13 20:15:01 +01:00
parent 6d012fb4ea
commit c04bece131
3 changed files with 172 additions and 178 deletions

View File

@ -665,15 +665,15 @@ draw_shadow (const GtkCssValue *shadow,
typedef struct { typedef struct {
double radius; double radius;
GtkRoundedBoxCorner corner; graphene_size_t corner;
} CornerMask; } CornerMask;
static guint static guint
corner_mask_hash (CornerMask *mask) corner_mask_hash (CornerMask *mask)
{ {
return ((guint)mask->radius << 24) ^ return ((guint)mask->radius << 24) ^
((guint)(mask->corner.horizontal*4)) << 12 ^ ((guint)(mask->corner.width*4)) << 12 ^
((guint)(mask->corner.vertical*4)) << 0; ((guint)(mask->corner.height*4)) << 0;
} }
static gboolean static gboolean
@ -682,8 +682,8 @@ corner_mask_equal (CornerMask *mask1,
{ {
return return
mask1->radius == mask2->radius && mask1->radius == mask2->radius &&
mask1->corner.horizontal == mask2->corner.horizontal && mask1->corner.width == mask2->corner.width &&
mask1->corner.vertical == mask2->corner.vertical; mask1->corner.height == mask2->corner.height;
} }
static void static void
@ -714,21 +714,21 @@ draw_shadow_corner (const GtkCssValue *shadow,
if (corner == GSK_CORNER_TOP_LEFT || corner == GSK_CORNER_BOTTOM_LEFT) if (corner == GSK_CORNER_TOP_LEFT || corner == GSK_CORNER_BOTTOM_LEFT)
{ {
x1 = floor (box->box.x - clip_radius); x1 = floor (box->box.x - clip_radius);
x2 = ceil (box->box.x + box->corner[corner].horizontal + clip_radius); x2 = ceil (box->box.x + box->corner[corner].width + clip_radius);
x = x1; x = x1;
sx = 1; sx = 1;
max_other = MAX(box->corner[GSK_CORNER_TOP_RIGHT].horizontal, box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal); max_other = MAX(box->corner[GSK_CORNER_TOP_RIGHT].width, box->corner[GSK_CORNER_BOTTOM_RIGHT].width);
x3 = floor (box->box.x + box->box.width - max_other - clip_radius); x3 = floor (box->box.x + box->box.width - max_other - clip_radius);
if (x2 > x3) if (x2 > x3)
overlapped = TRUE; overlapped = TRUE;
} }
else else
{ {
x1 = floor (box->box.x + box->box.width - box->corner[corner].horizontal - clip_radius); x1 = floor (box->box.x + box->box.width - box->corner[corner].width - clip_radius);
x2 = ceil (box->box.x + box->box.width + clip_radius); x2 = ceil (box->box.x + box->box.width + clip_radius);
x = x2; x = x2;
sx = -1; sx = -1;
max_other = MAX(box->corner[GSK_CORNER_TOP_LEFT].horizontal, box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal); max_other = MAX(box->corner[GSK_CORNER_TOP_LEFT].width, box->corner[GSK_CORNER_BOTTOM_LEFT].width);
x3 = ceil (box->box.x + max_other + clip_radius); x3 = ceil (box->box.x + max_other + clip_radius);
if (x3 > x1) if (x3 > x1)
overlapped = TRUE; overlapped = TRUE;
@ -737,21 +737,21 @@ draw_shadow_corner (const GtkCssValue *shadow,
if (corner == GSK_CORNER_TOP_LEFT || corner == GSK_CORNER_TOP_RIGHT) if (corner == GSK_CORNER_TOP_LEFT || corner == GSK_CORNER_TOP_RIGHT)
{ {
y1 = floor (box->box.y - clip_radius); y1 = floor (box->box.y - clip_radius);
y2 = ceil (box->box.y + box->corner[corner].vertical + clip_radius); y2 = ceil (box->box.y + box->corner[corner].height + clip_radius);
y = y1; y = y1;
sy = 1; sy = 1;
max_other = MAX(box->corner[GSK_CORNER_BOTTOM_LEFT].vertical, box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical); max_other = MAX(box->corner[GSK_CORNER_BOTTOM_LEFT].height, box->corner[GSK_CORNER_BOTTOM_RIGHT].height);
y3 = floor (box->box.y + box->box.height - max_other - clip_radius); y3 = floor (box->box.y + box->box.height - max_other - clip_radius);
if (y2 > y3) if (y2 > y3)
overlapped = TRUE; overlapped = TRUE;
} }
else else
{ {
y1 = floor (box->box.y + box->box.height - box->corner[corner].vertical - clip_radius); y1 = floor (box->box.y + box->box.height - box->corner[corner].height - clip_radius);
y2 = ceil (box->box.y + box->box.height + clip_radius); y2 = ceil (box->box.y + box->box.height + clip_radius);
y = y2; y = y2;
sy = -1; sy = -1;
max_other = MAX(box->corner[GSK_CORNER_TOP_LEFT].vertical, box->corner[GSK_CORNER_TOP_RIGHT].vertical); max_other = MAX(box->corner[GSK_CORNER_TOP_LEFT].height, box->corner[GSK_CORNER_TOP_RIGHT].height);
y3 = ceil (box->box.y + max_other + clip_radius); y3 = ceil (box->box.y + max_other + clip_radius);
if (y3 > y1) if (y3 > y1)
overlapped = TRUE; overlapped = TRUE;

View File

@ -58,30 +58,30 @@ gtk_rounded_box_clamp_border_radius (GtkRoundedBox *box)
gdouble factor = 1.0; gdouble factor = 1.0;
gdouble corners; gdouble corners;
corners = box->corner[GSK_CORNER_TOP_LEFT].horizontal + box->corner[GSK_CORNER_TOP_RIGHT].horizontal; corners = box->corner[GSK_CORNER_TOP_LEFT].width + box->corner[GSK_CORNER_TOP_RIGHT].width;
if (corners != 0) if (corners != 0)
factor = MIN (factor, box->box.width / corners); factor = MIN (factor, box->box.width / corners);
corners = box->corner[GSK_CORNER_TOP_RIGHT].vertical + box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical; corners = box->corner[GSK_CORNER_TOP_RIGHT].height + box->corner[GSK_CORNER_BOTTOM_RIGHT].height;
if (corners != 0) if (corners != 0)
factor = MIN (factor, box->box.height / corners); factor = MIN (factor, box->box.height / corners);
corners = box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal + box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal; corners = box->corner[GSK_CORNER_BOTTOM_RIGHT].width + box->corner[GSK_CORNER_BOTTOM_LEFT].width;
if (corners != 0) if (corners != 0)
factor = MIN (factor, box->box.width / corners); factor = MIN (factor, box->box.width / corners);
corners = box->corner[GSK_CORNER_TOP_LEFT].vertical + box->corner[GSK_CORNER_BOTTOM_LEFT].vertical; corners = box->corner[GSK_CORNER_TOP_LEFT].height + box->corner[GSK_CORNER_BOTTOM_LEFT].height;
if (corners != 0) if (corners != 0)
factor = MIN (factor, box->box.height / corners); factor = MIN (factor, box->box.height / corners);
box->corner[GSK_CORNER_TOP_LEFT].horizontal *= factor; box->corner[GSK_CORNER_TOP_LEFT].width *= factor;
box->corner[GSK_CORNER_TOP_LEFT].vertical *= factor; box->corner[GSK_CORNER_TOP_LEFT].height *= factor;
box->corner[GSK_CORNER_TOP_RIGHT].horizontal *= factor; box->corner[GSK_CORNER_TOP_RIGHT].width *= factor;
box->corner[GSK_CORNER_TOP_RIGHT].vertical *= factor; box->corner[GSK_CORNER_TOP_RIGHT].height *= factor;
box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal *= factor; box->corner[GSK_CORNER_BOTTOM_RIGHT].width *= factor;
box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical *= factor; box->corner[GSK_CORNER_BOTTOM_RIGHT].height *= factor;
box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal *= factor; box->corner[GSK_CORNER_BOTTOM_LEFT].width *= factor;
box->corner[GSK_CORNER_BOTTOM_LEFT].vertical *= factor; box->corner[GSK_CORNER_BOTTOM_LEFT].height *= factor;
} }
static void static void
@ -91,30 +91,30 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
{ {
if (corner[GSK_CORNER_TOP_LEFT] && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0) if (corner[GSK_CORNER_TOP_LEFT] && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0)
{ {
box->corner[GSK_CORNER_TOP_LEFT].horizontal = _gtk_css_corner_value_get_x (corner[GSK_CORNER_TOP_LEFT], box->corner[GSK_CORNER_TOP_LEFT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_TOP_LEFT],
box->box.width); box->box.width);
box->corner[GSK_CORNER_TOP_LEFT].vertical = _gtk_css_corner_value_get_y (corner[GSK_CORNER_TOP_LEFT], box->corner[GSK_CORNER_TOP_LEFT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_TOP_LEFT],
box->box.height); box->box.height);
} }
if (corner[GSK_CORNER_TOP_RIGHT] && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0) if (corner[GSK_CORNER_TOP_RIGHT] && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0)
{ {
box->corner[GSK_CORNER_TOP_RIGHT].horizontal = _gtk_css_corner_value_get_x (corner[GSK_CORNER_TOP_RIGHT], box->corner[GSK_CORNER_TOP_RIGHT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_TOP_RIGHT],
box->box.width); box->box.width);
box->corner[GSK_CORNER_TOP_RIGHT].vertical = _gtk_css_corner_value_get_y (corner[GSK_CORNER_TOP_RIGHT], box->corner[GSK_CORNER_TOP_RIGHT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_TOP_RIGHT],
box->box.height); box->box.height);
} }
if (corner[GSK_CORNER_BOTTOM_RIGHT] && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0) if (corner[GSK_CORNER_BOTTOM_RIGHT] && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0)
{ {
box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal = _gtk_css_corner_value_get_x (corner[GSK_CORNER_BOTTOM_RIGHT], box->corner[GSK_CORNER_BOTTOM_RIGHT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_BOTTOM_RIGHT],
box->box.width); box->box.width);
box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical = _gtk_css_corner_value_get_y (corner[GSK_CORNER_BOTTOM_RIGHT], box->corner[GSK_CORNER_BOTTOM_RIGHT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_BOTTOM_RIGHT],
box->box.height); box->box.height);
} }
if (corner[GSK_CORNER_BOTTOM_LEFT] && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0) if (corner[GSK_CORNER_BOTTOM_LEFT] && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0)
{ {
box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal = _gtk_css_corner_value_get_x (corner[GSK_CORNER_BOTTOM_LEFT], box->corner[GSK_CORNER_BOTTOM_LEFT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_BOTTOM_LEFT],
box->box.width); box->box.width);
box->corner[GSK_CORNER_BOTTOM_LEFT].vertical = _gtk_css_corner_value_get_y (corner[GSK_CORNER_BOTTOM_LEFT], box->corner[GSK_CORNER_BOTTOM_LEFT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_BOTTOM_LEFT],
box->box.height); box->box.height);
} }
@ -152,19 +152,19 @@ _gtk_rounded_box_apply_outline_radius_for_style (GtkRoundedBox *box,
} }
static void static void
gtk_css_border_radius_grow (GtkRoundedBoxCorner *corner, gtk_css_border_radius_grow (graphene_size_t *corner,
double horizontal, double width,
double vertical) double height)
{ {
if (corner->horizontal) if (corner->width)
corner->horizontal += horizontal; corner->width += width;
if (corner->vertical) if (corner->height)
corner->vertical += vertical; corner->height += height;
if (corner->horizontal <= 0 || corner->vertical <= 0) if (corner->width <= 0 || corner->height <= 0)
{ {
corner->horizontal = 0; corner->width = 0;
corner->vertical = 0; corner->height = 0;
} }
} }
@ -361,28 +361,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->corner[GSK_CORNER_TOP_LEFT].horizontal, box->box.x + box->corner[GSK_CORNER_TOP_LEFT].width,
box->box.y + box->corner[GSK_CORNER_TOP_LEFT].vertical, box->box.y + box->corner[GSK_CORNER_TOP_LEFT].height,
box->corner[GSK_CORNER_TOP_LEFT].horizontal, box->corner[GSK_CORNER_TOP_LEFT].width,
box->corner[GSK_CORNER_TOP_LEFT].vertical, box->corner[GSK_CORNER_TOP_LEFT].height,
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->corner[GSK_CORNER_TOP_RIGHT].horizontal, box->box.x + box->box.width - box->corner[GSK_CORNER_TOP_RIGHT].width,
box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].vertical, box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].height,
box->corner[GSK_CORNER_TOP_RIGHT].horizontal, box->corner[GSK_CORNER_TOP_RIGHT].width,
box->corner[GSK_CORNER_TOP_RIGHT].vertical, box->corner[GSK_CORNER_TOP_RIGHT].height,
- G_PI_2, 0); - G_PI_2, 0);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
0, G_PI_2); 0, G_PI_2);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].width,
box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].vertical, box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].height,
box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, box->corner[GSK_CORNER_BOTTOM_LEFT].width,
box->corner[GSK_CORNER_BOTTOM_LEFT].vertical, box->corner[GSK_CORNER_BOTTOM_LEFT].height,
G_PI_2, G_PI); G_PI_2, G_PI);
cairo_close_path (cr); cairo_close_path (cr);
@ -400,17 +400,17 @@ _gtk_rounded_box_guess_length (const GtkRoundedBox *box,
if (side & 1) if (side & 1)
length = box->box.height length = box->box.height
- box->corner[before].vertical - box->corner[before].height
- box->corner[after].vertical; - box->corner[after].height;
else else
length = box->box.width length = box->box.width
- box->corner[before].horizontal - box->corner[before].width
- box->corner[after].horizontal; - box->corner[after].width;
length += G_PI * 0.125 * (box->corner[before].horizontal length += G_PI * 0.125 * (box->corner[before].width
+ box->corner[before].vertical + box->corner[before].height
+ box->corner[after].horizontal + box->corner[after].width
+ box->corner[after].vertical); + box->corner[after].height);
return length; return length;
} }
@ -424,58 +424,58 @@ _gtk_rounded_box_path_side (const GtkRoundedBox *box,
{ {
case GTK_CSS_TOP: case GTK_CSS_TOP:
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->corner[GSK_CORNER_TOP_LEFT].horizontal, box->box.x + box->corner[GSK_CORNER_TOP_LEFT].width,
box->box.y + box->corner[GSK_CORNER_TOP_LEFT].vertical, box->box.y + box->corner[GSK_CORNER_TOP_LEFT].height,
box->corner[GSK_CORNER_TOP_LEFT].horizontal, box->corner[GSK_CORNER_TOP_LEFT].width,
box->corner[GSK_CORNER_TOP_LEFT].vertical, box->corner[GSK_CORNER_TOP_LEFT].height,
5 * G_PI_4, 3 * G_PI_2); 5 * G_PI_4, 3 * G_PI_2);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->box.width - box->corner[GSK_CORNER_TOP_RIGHT].horizontal, box->box.x + box->box.width - box->corner[GSK_CORNER_TOP_RIGHT].width,
box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].vertical, box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].height,
box->corner[GSK_CORNER_TOP_RIGHT].horizontal, box->corner[GSK_CORNER_TOP_RIGHT].width,
box->corner[GSK_CORNER_TOP_RIGHT].vertical, box->corner[GSK_CORNER_TOP_RIGHT].height,
- G_PI_2, -G_PI_4); - G_PI_2, -G_PI_4);
break; break;
case GTK_CSS_RIGHT: case GTK_CSS_RIGHT:
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->box.width - box->corner[GSK_CORNER_TOP_RIGHT].horizontal, box->box.x + box->box.width - box->corner[GSK_CORNER_TOP_RIGHT].width,
box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].vertical, box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].height,
box->corner[GSK_CORNER_TOP_RIGHT].horizontal, box->corner[GSK_CORNER_TOP_RIGHT].width,
box->corner[GSK_CORNER_TOP_RIGHT].vertical, box->corner[GSK_CORNER_TOP_RIGHT].height,
- G_PI_4, 0); - G_PI_4, 0);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
0, G_PI_4); 0, G_PI_4);
break; break;
case GTK_CSS_BOTTOM: case GTK_CSS_BOTTOM:
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
G_PI_4, G_PI_2); G_PI_4, G_PI_2);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].width,
box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].vertical, box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].height,
box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, box->corner[GSK_CORNER_BOTTOM_LEFT].width,
box->corner[GSK_CORNER_BOTTOM_LEFT].vertical, box->corner[GSK_CORNER_BOTTOM_LEFT].height,
G_PI_2, 3 * G_PI_4); G_PI_2, 3 * G_PI_4);
break; break;
case GTK_CSS_LEFT: case GTK_CSS_LEFT:
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].width,
box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].vertical, box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].height,
box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, box->corner[GSK_CORNER_BOTTOM_LEFT].width,
box->corner[GSK_CORNER_BOTTOM_LEFT].vertical, box->corner[GSK_CORNER_BOTTOM_LEFT].height,
3 * G_PI_4, G_PI); 3 * G_PI_4, G_PI);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
box->box.x + box->corner[GSK_CORNER_TOP_LEFT].horizontal, box->box.x + box->corner[GSK_CORNER_TOP_LEFT].width,
box->box.y + box->corner[GSK_CORNER_TOP_LEFT].vertical, box->box.y + box->corner[GSK_CORNER_TOP_LEFT].height,
box->corner[GSK_CORNER_TOP_LEFT].horizontal, box->corner[GSK_CORNER_TOP_LEFT].width,
box->corner[GSK_CORNER_TOP_LEFT].vertical, box->corner[GSK_CORNER_TOP_LEFT].height,
G_PI, 5 * G_PI_4); G_PI, 5 * G_PI_4);
break; break;
default: default:
@ -507,29 +507,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->corner[GSK_CORNER_TOP_LEFT].horizontal, outer->box.x + outer->corner[GSK_CORNER_TOP_LEFT].width,
outer->box.y + outer->corner[GSK_CORNER_TOP_LEFT].vertical, outer->box.y + outer->corner[GSK_CORNER_TOP_LEFT].height,
outer->corner[GSK_CORNER_TOP_LEFT].horizontal, outer->corner[GSK_CORNER_TOP_LEFT].width,
outer->corner[GSK_CORNER_TOP_LEFT].vertical, outer->corner[GSK_CORNER_TOP_LEFT].height,
start_angle, middle_angle); start_angle, middle_angle);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->box.width - outer->corner[GSK_CORNER_TOP_RIGHT].horizontal, outer->box.x + outer->box.width - outer->corner[GSK_CORNER_TOP_RIGHT].width,
outer->box.y + outer->corner[GSK_CORNER_TOP_RIGHT].vertical, outer->box.y + outer->corner[GSK_CORNER_TOP_RIGHT].height,
outer->corner[GSK_CORNER_TOP_RIGHT].horizontal, outer->corner[GSK_CORNER_TOP_RIGHT].width,
outer->corner[GSK_CORNER_TOP_RIGHT].vertical, outer->corner[GSK_CORNER_TOP_RIGHT].height,
middle_angle, end_angle); middle_angle, end_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->corner[GSK_CORNER_TOP_RIGHT].horizontal, inner->box.x + inner->box.width - inner->corner[GSK_CORNER_TOP_RIGHT].width,
inner->box.y + inner->corner[GSK_CORNER_TOP_RIGHT].vertical, inner->box.y + inner->corner[GSK_CORNER_TOP_RIGHT].height,
inner->corner[GSK_CORNER_TOP_RIGHT].horizontal, inner->corner[GSK_CORNER_TOP_RIGHT].width,
inner->corner[GSK_CORNER_TOP_RIGHT].vertical, inner->corner[GSK_CORNER_TOP_RIGHT].height,
end_angle, middle_angle); end_angle, middle_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->corner[GSK_CORNER_TOP_LEFT].horizontal, inner->box.x + inner->corner[GSK_CORNER_TOP_LEFT].width,
inner->box.y + inner->corner[GSK_CORNER_TOP_LEFT].vertical, inner->box.y + inner->corner[GSK_CORNER_TOP_LEFT].height,
inner->corner[GSK_CORNER_TOP_LEFT].horizontal, inner->corner[GSK_CORNER_TOP_LEFT].width,
inner->corner[GSK_CORNER_TOP_LEFT].vertical, inner->corner[GSK_CORNER_TOP_LEFT].height,
middle_angle, start_angle); middle_angle, start_angle);
cairo_close_path (cr); cairo_close_path (cr);
@ -558,29 +558,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->corner[GSK_CORNER_TOP_RIGHT].horizontal, outer->box.x + outer->box.width - outer->corner[GSK_CORNER_TOP_RIGHT].width,
outer->box.y + outer->corner[GSK_CORNER_TOP_RIGHT].vertical, outer->box.y + outer->corner[GSK_CORNER_TOP_RIGHT].height,
outer->corner[GSK_CORNER_TOP_RIGHT].horizontal, outer->corner[GSK_CORNER_TOP_RIGHT].width,
outer->corner[GSK_CORNER_TOP_RIGHT].vertical, outer->corner[GSK_CORNER_TOP_RIGHT].height,
start_angle, middle_angle); start_angle, middle_angle);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->box.width - outer->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, outer->box.x + outer->box.width - outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
outer->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
outer->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
middle_angle, end_angle); middle_angle, end_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, inner->box.x + inner->box.width - inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
inner->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
inner->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
end_angle, middle_angle); end_angle, middle_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->corner[GSK_CORNER_TOP_RIGHT].horizontal, inner->box.x + inner->box.width - inner->corner[GSK_CORNER_TOP_RIGHT].width,
inner->box.y + inner->corner[GSK_CORNER_TOP_RIGHT].vertical, inner->box.y + inner->corner[GSK_CORNER_TOP_RIGHT].height,
inner->corner[GSK_CORNER_TOP_RIGHT].horizontal, inner->corner[GSK_CORNER_TOP_RIGHT].width,
inner->corner[GSK_CORNER_TOP_RIGHT].vertical, inner->corner[GSK_CORNER_TOP_RIGHT].height,
middle_angle, start_angle); middle_angle, start_angle);
cairo_close_path (cr); cairo_close_path (cr);
@ -609,29 +609,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->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, outer->box.x + outer->box.width - outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
outer->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
outer->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
start_angle, middle_angle); start_angle, middle_angle);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, outer->box.x + outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_LEFT].vertical, outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
outer->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
outer->corner[GSK_CORNER_BOTTOM_LEFT].vertical, outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
middle_angle, end_angle); middle_angle, end_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, inner->box.x + inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_LEFT].vertical, inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
inner->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
inner->corner[GSK_CORNER_BOTTOM_LEFT].vertical, inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
end_angle, middle_angle); end_angle, middle_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->box.width - inner->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, inner->box.x + inner->box.width - inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
inner->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal, inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
inner->corner[GSK_CORNER_BOTTOM_RIGHT].vertical, inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
middle_angle, start_angle); middle_angle, start_angle);
cairo_close_path (cr); cairo_close_path (cr);
@ -660,29 +660,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->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, outer->box.x + outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_LEFT].vertical, outer->box.y + outer->box.height - outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
outer->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
outer->corner[GSK_CORNER_BOTTOM_LEFT].vertical, outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
start_angle, middle_angle); start_angle, middle_angle);
_cairo_ellipsis (cr, _cairo_ellipsis (cr,
outer->box.x + outer->corner[GSK_CORNER_TOP_LEFT].horizontal, outer->box.x + outer->corner[GSK_CORNER_TOP_LEFT].width,
outer->box.y + outer->corner[GSK_CORNER_TOP_LEFT].vertical, outer->box.y + outer->corner[GSK_CORNER_TOP_LEFT].height,
outer->corner[GSK_CORNER_TOP_LEFT].horizontal, outer->corner[GSK_CORNER_TOP_LEFT].width,
outer->corner[GSK_CORNER_TOP_LEFT].vertical, outer->corner[GSK_CORNER_TOP_LEFT].height,
middle_angle, end_angle); middle_angle, end_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->corner[GSK_CORNER_TOP_LEFT].horizontal, inner->box.x + inner->corner[GSK_CORNER_TOP_LEFT].width,
inner->box.y + inner->corner[GSK_CORNER_TOP_LEFT].vertical, inner->box.y + inner->corner[GSK_CORNER_TOP_LEFT].height,
inner->corner[GSK_CORNER_TOP_LEFT].horizontal, inner->corner[GSK_CORNER_TOP_LEFT].width,
inner->corner[GSK_CORNER_TOP_LEFT].vertical, inner->corner[GSK_CORNER_TOP_LEFT].height,
end_angle, middle_angle); end_angle, middle_angle);
_cairo_ellipsis_negative (cr, _cairo_ellipsis_negative (cr,
inner->box.x + inner->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, inner->box.x + inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_LEFT].vertical, inner->box.y + inner->box.height - inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
inner->corner[GSK_CORNER_BOTTOM_LEFT].horizontal, inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
inner->corner[GSK_CORNER_BOTTOM_LEFT].vertical, inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
middle_angle, start_angle); middle_angle, start_angle);
cairo_close_path (cr); cairo_close_path (cr);
@ -726,20 +726,20 @@ _gtk_rounded_box_contains_rectangle (const GtkRoundedBox *box,
y2 > box->box.y + box->box.height) y2 > box->box.y + box->box.height)
return FALSE; return FALSE;
if (x1 < box->box.x + box->corner[GSK_CORNER_TOP_LEFT].horizontal && if (x1 < box->box.x + box->corner[GSK_CORNER_TOP_LEFT].width &&
y1 < box->box.y + box->corner[GSK_CORNER_TOP_LEFT].vertical) y1 < box->box.y + box->corner[GSK_CORNER_TOP_LEFT].height)
return FALSE; return FALSE;
if (x2 > box->box.x + box->box.width - box->corner[GSK_CORNER_TOP_RIGHT].horizontal && if (x2 > box->box.x + box->box.width - box->corner[GSK_CORNER_TOP_RIGHT].width &&
y1 < box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].vertical) y1 < box->box.y + box->corner[GSK_CORNER_TOP_RIGHT].height)
return FALSE; return FALSE;
if (x2 > box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].horizontal && if (x2 > box->box.x + box->box.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].width &&
y2 > box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].vertical) y2 > box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].height)
return FALSE; return FALSE;
if (x1 < box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].horizontal && if (x1 < box->box.x + box->corner[GSK_CORNER_BOTTOM_LEFT].width &&
y2 > box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].vertical) y2 > box->box.y + box->box.height - box->corner[GSK_CORNER_BOTTOM_LEFT].height)
return FALSE; return FALSE;
return TRUE; return TRUE;

View File

@ -29,17 +29,11 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _GtkRoundedBox GtkRoundedBox; typedef struct _GtkRoundedBox GtkRoundedBox;
typedef struct _GtkRoundedBoxCorner GtkRoundedBoxCorner;
struct _GtkRoundedBoxCorner {
double horizontal;
double vertical;
};
struct _GtkRoundedBox { struct _GtkRoundedBox {
/*< private >*/ /*< private >*/
cairo_rectangle_t box; cairo_rectangle_t box;
GtkRoundedBoxCorner corner[4]; graphene_size_t corner[4];
}; };
void _gtk_rounded_box_init_rect (GtkRoundedBox *box, void _gtk_rounded_box_init_rect (GtkRoundedBox *box,