2011-06-11 01:57:57 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-06-11 01:57:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkroundedboxprivate.h"
|
2012-04-03 16:39:01 +00:00
|
|
|
|
|
|
|
#include "gtkcsscornervalueprivate.h"
|
2016-12-19 18:19:15 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2012-04-03 16:39:01 +00:00
|
|
|
#include "gtkcsstypesprivate.h"
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2011-06-11 01:57:57 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _gtk_rounded_box_init_rect:
|
|
|
|
* @box: box to initialize
|
|
|
|
* @x: x coordinate of box
|
|
|
|
* @y: y coordinate of box
|
|
|
|
* @width: width of box
|
|
|
|
* @height: height of box
|
|
|
|
*
|
|
|
|
* Initializes the given @box to represent the given rectangle.
|
|
|
|
* The
|
|
|
|
**/
|
|
|
|
void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_init_rect (GskRoundedRect *box,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double width,
|
|
|
|
double height)
|
2011-06-11 01:57:57 +00:00
|
|
|
{
|
2016-12-13 19:48:58 +00:00
|
|
|
memset (box, 0, sizeof (GskRoundedRect));
|
2012-01-02 01:39:20 +00:00
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x = x;
|
|
|
|
box->bounds.origin.y = y;
|
|
|
|
box->bounds.size.width = width;
|
|
|
|
box->bounds.size.height = height;
|
2011-06-11 01:57:57 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 21:37:26 +00:00
|
|
|
/* clamp border radius, following CSS specs */
|
|
|
|
static void
|
2016-12-13 19:48:58 +00:00
|
|
|
gtk_rounded_box_clamp_border_radius (GskRoundedRect *box)
|
2011-07-20 21:37:26 +00:00
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double factor = 1.0;
|
|
|
|
double corners;
|
2011-07-20 21:37:26 +00:00
|
|
|
|
2016-12-13 19:15:01 +00:00
|
|
|
corners = box->corner[GSK_CORNER_TOP_LEFT].width + box->corner[GSK_CORNER_TOP_RIGHT].width;
|
2016-01-08 18:17:58 +00:00
|
|
|
if (corners != 0)
|
2016-12-13 19:36:00 +00:00
|
|
|
factor = MIN (factor, box->bounds.size.width / corners);
|
2016-01-08 18:17:58 +00:00
|
|
|
|
2016-12-13 19:15:01 +00:00
|
|
|
corners = box->corner[GSK_CORNER_TOP_RIGHT].height + box->corner[GSK_CORNER_BOTTOM_RIGHT].height;
|
2016-01-08 18:17:58 +00:00
|
|
|
if (corners != 0)
|
2016-12-13 19:36:00 +00:00
|
|
|
factor = MIN (factor, box->bounds.size.height / corners);
|
2016-01-08 18:17:58 +00:00
|
|
|
|
2016-12-13 19:15:01 +00:00
|
|
|
corners = box->corner[GSK_CORNER_BOTTOM_RIGHT].width + box->corner[GSK_CORNER_BOTTOM_LEFT].width;
|
2016-01-08 18:17:58 +00:00
|
|
|
if (corners != 0)
|
2016-12-13 19:36:00 +00:00
|
|
|
factor = MIN (factor, box->bounds.size.width / corners);
|
2016-01-08 18:17:58 +00:00
|
|
|
|
2016-12-13 19:15:01 +00:00
|
|
|
corners = box->corner[GSK_CORNER_TOP_LEFT].height + box->corner[GSK_CORNER_BOTTOM_LEFT].height;
|
2016-01-08 18:17:58 +00:00
|
|
|
if (corners != 0)
|
2016-12-13 19:36:00 +00:00
|
|
|
factor = MIN (factor, box->bounds.size.height / corners);
|
2012-01-07 21:40:17 +00:00
|
|
|
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].width *= factor;
|
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].height *= factor;
|
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].width *= factor;
|
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].height *= factor;
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].width *= factor;
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].height *= factor;
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].width *= factor;
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].height *= factor;
|
2011-07-20 21:37:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-03 16:39:01 +00:00
|
|
|
static void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_apply_border_radius (GskRoundedRect *box,
|
2017-10-01 07:48:31 +00:00
|
|
|
const GtkCssValue * const corner[4])
|
2011-06-11 01:57:57 +00:00
|
|
|
{
|
2017-10-01 07:48:31 +00:00
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_TOP_LEFT],
|
|
|
|
box->bounds.size.width);
|
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_TOP_LEFT],
|
|
|
|
box->bounds.size.height);
|
|
|
|
|
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_TOP_RIGHT],
|
|
|
|
box->bounds.size.width);
|
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_TOP_RIGHT],
|
|
|
|
box->bounds.size.height);
|
|
|
|
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_BOTTOM_RIGHT],
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.size.width);
|
2017-10-01 07:48:31 +00:00
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_BOTTOM_RIGHT],
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.size.height);
|
2017-10-01 07:48:31 +00:00
|
|
|
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].width = _gtk_css_corner_value_get_x (corner[GSK_CORNER_BOTTOM_LEFT],
|
|
|
|
box->bounds.size.width);
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].height = _gtk_css_corner_value_get_y (corner[GSK_CORNER_BOTTOM_LEFT],
|
|
|
|
box->bounds.size.height);
|
2011-06-11 01:57:57 +00:00
|
|
|
|
2011-07-20 21:37:26 +00:00
|
|
|
gtk_rounded_box_clamp_border_radius (box);
|
2012-02-08 21:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-19 18:19:15 +00:00
|
|
|
gtk_rounded_boxes_init_for_style (GskRoundedRect *border_box,
|
|
|
|
GskRoundedRect *padding_box,
|
|
|
|
GskRoundedRect *content_box,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double width,
|
|
|
|
double height)
|
2012-02-08 21:27:39 +00:00
|
|
|
{
|
2017-10-01 07:48:31 +00:00
|
|
|
const GtkCssValue *corner[4];
|
2016-12-19 18:19:15 +00:00
|
|
|
GskRoundedRect box;
|
|
|
|
|
|
|
|
gsk_rounded_rect_init_from_rect (&box, &GRAPHENE_RECT_INIT (x, y, width, height), 0);
|
2012-02-08 21:27:39 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
corner[GSK_CORNER_TOP_LEFT] = style->border->border_top_left_radius;
|
|
|
|
corner[GSK_CORNER_TOP_RIGHT] = style->border->border_top_right_radius;
|
|
|
|
corner[GSK_CORNER_BOTTOM_LEFT] = style->border->border_bottom_left_radius;
|
|
|
|
corner[GSK_CORNER_BOTTOM_RIGHT] = style->border->border_bottom_right_radius;
|
2011-07-20 21:37:26 +00:00
|
|
|
|
2016-12-19 18:19:15 +00:00
|
|
|
_gtk_rounded_box_apply_border_radius (&box, corner);
|
|
|
|
|
|
|
|
if (border_box)
|
|
|
|
gsk_rounded_rect_init_copy (border_box, &box);
|
|
|
|
|
|
|
|
if (padding_box || content_box)
|
|
|
|
{
|
|
|
|
gsk_rounded_rect_shrink (&box,
|
2020-01-28 07:38:25 +00:00
|
|
|
_gtk_css_number_value_get (style->border->border_top_width, 100),
|
|
|
|
_gtk_css_number_value_get (style->border->border_right_width, 100),
|
|
|
|
_gtk_css_number_value_get (style->border->border_bottom_width, 100),
|
|
|
|
_gtk_css_number_value_get (style->border->border_left_width, 100));
|
2016-12-19 18:19:15 +00:00
|
|
|
if (padding_box)
|
|
|
|
gsk_rounded_rect_init_copy (padding_box, &box);
|
|
|
|
|
|
|
|
if (content_box)
|
|
|
|
{
|
|
|
|
gsk_rounded_rect_shrink (&box,
|
2020-01-28 07:38:25 +00:00
|
|
|
_gtk_css_number_value_get (style->size->padding_top, 100),
|
|
|
|
_gtk_css_number_value_get (style->size->padding_right, 100),
|
|
|
|
_gtk_css_number_value_get (style->size->padding_bottom, 100),
|
|
|
|
_gtk_css_number_value_get (style->size->padding_left, 100));
|
2016-12-19 18:19:15 +00:00
|
|
|
gsk_rounded_rect_init_copy (content_box, &box);
|
|
|
|
}
|
|
|
|
}
|
2011-06-11 01:57:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:40:00 +00:00
|
|
|
typedef struct {
|
|
|
|
double angle1;
|
|
|
|
double angle2;
|
|
|
|
gboolean negative;
|
|
|
|
} Arc;
|
|
|
|
|
2016-05-01 02:39:26 +00:00
|
|
|
static inline guint
|
2020-07-24 13:54:49 +00:00
|
|
|
mem_hash (gconstpointer v, int len)
|
2016-05-01 02:39:26 +00:00
|
|
|
{
|
|
|
|
const signed char *p;
|
|
|
|
const signed char *end;
|
|
|
|
guint32 h = 5381;
|
|
|
|
|
|
|
|
p = v;
|
|
|
|
end = p + len;
|
|
|
|
for (; p < end; p++)
|
|
|
|
h = (h << 5) + h + *p;
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:40:00 +00:00
|
|
|
static guint
|
|
|
|
arc_path_hash (Arc *arc)
|
|
|
|
{
|
2016-05-01 02:39:26 +00:00
|
|
|
return mem_hash ((gconstpointer)arc, sizeof (Arc));
|
2015-09-29 13:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
arc_path_equal (Arc *arc1,
|
|
|
|
Arc *arc2)
|
|
|
|
{
|
|
|
|
return arc1->angle1 == arc2->angle1 &&
|
|
|
|
arc1->angle2 == arc2->angle2 &&
|
|
|
|
arc1->negative == arc2->negative;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need the path to start with a line-to */
|
|
|
|
static cairo_path_t *
|
|
|
|
fixup_path (cairo_path_t *path)
|
|
|
|
{
|
|
|
|
cairo_path_data_t *data;
|
|
|
|
|
|
|
|
data = &path->data[0];
|
|
|
|
if (data->header.type == CAIRO_PATH_MOVE_TO)
|
|
|
|
data->header.type = CAIRO_PATH_LINE_TO;
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
append_arc (cairo_t *cr, double angle1, double angle2, gboolean negative)
|
|
|
|
{
|
|
|
|
static GHashTable *arc_path_cache;
|
|
|
|
Arc key;
|
|
|
|
cairo_path_t *arc;
|
|
|
|
|
2016-05-03 14:58:02 +00:00
|
|
|
memset (&key, 0, sizeof (Arc));
|
2015-09-29 13:40:00 +00:00
|
|
|
key.angle1 = angle1;
|
|
|
|
key.angle2 = angle2;
|
|
|
|
key.negative = negative;
|
|
|
|
|
|
|
|
if (arc_path_cache == NULL)
|
|
|
|
arc_path_cache = g_hash_table_new_full ((GHashFunc)arc_path_hash,
|
|
|
|
(GEqualFunc)arc_path_equal,
|
|
|
|
g_free, (GDestroyNotify)cairo_path_destroy);
|
|
|
|
|
|
|
|
arc = g_hash_table_lookup (arc_path_cache, &key);
|
|
|
|
if (arc == NULL)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *tmp;
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
|
|
|
|
tmp = cairo_create (surface);
|
|
|
|
|
|
|
|
if (negative)
|
|
|
|
cairo_arc_negative (tmp, 0.0, 0.0, 1.0, angle1, angle2);
|
|
|
|
else
|
|
|
|
cairo_arc (tmp, 0.0, 0.0, 1.0, angle1, angle2);
|
|
|
|
|
|
|
|
arc = fixup_path (cairo_copy_path (tmp));
|
|
|
|
g_hash_table_insert (arc_path_cache, g_memdup (&key, sizeof (key)), arc);
|
|
|
|
|
|
|
|
cairo_destroy (tmp);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_append_path (cr, arc);
|
|
|
|
}
|
|
|
|
|
2011-06-11 01:57:57 +00:00
|
|
|
static void
|
|
|
|
_cairo_ellipsis (cairo_t *cr,
|
|
|
|
double xc, double yc,
|
|
|
|
double xradius, double yradius,
|
|
|
|
double angle1, double angle2)
|
|
|
|
{
|
2014-10-22 21:41:50 +00:00
|
|
|
cairo_matrix_t save;
|
|
|
|
|
2011-06-11 01:57:57 +00:00
|
|
|
if (xradius <= 0.0 || yradius <= 0.0)
|
|
|
|
{
|
|
|
|
cairo_line_to (cr, xc, yc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:41:50 +00:00
|
|
|
cairo_get_matrix (cr, &save);
|
2011-06-11 01:57:57 +00:00
|
|
|
cairo_translate (cr, xc, yc);
|
|
|
|
cairo_scale (cr, xradius, yradius);
|
2015-09-29 13:40:00 +00:00
|
|
|
append_arc (cr, angle1, angle2, FALSE);
|
2014-10-22 21:41:50 +00:00
|
|
|
cairo_set_matrix (cr, &save);
|
2011-06-11 01:57:57 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 03:04:44 +00:00
|
|
|
static void
|
|
|
|
_cairo_ellipsis_negative (cairo_t *cr,
|
|
|
|
double xc, double yc,
|
|
|
|
double xradius, double yradius,
|
|
|
|
double angle1, double angle2)
|
|
|
|
{
|
2014-10-22 21:41:50 +00:00
|
|
|
cairo_matrix_t save;
|
|
|
|
|
2011-06-13 03:04:44 +00:00
|
|
|
if (xradius <= 0.0 || yradius <= 0.0)
|
|
|
|
{
|
|
|
|
cairo_line_to (cr, xc, yc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:41:50 +00:00
|
|
|
cairo_get_matrix (cr, &save);
|
2011-06-13 03:04:44 +00:00
|
|
|
cairo_translate (cr, xc, yc);
|
|
|
|
cairo_scale (cr, xradius, yradius);
|
2015-09-29 13:40:00 +00:00
|
|
|
append_arc (cr, angle1, angle2, TRUE);
|
2014-10-22 21:41:50 +00:00
|
|
|
cairo_set_matrix (cr, &save);
|
2011-06-13 03:04:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 00:17:48 +00:00
|
|
|
double
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_guess_length (const GskRoundedRect *box,
|
|
|
|
GtkCssSide side)
|
2012-01-08 00:17:48 +00:00
|
|
|
{
|
|
|
|
double length;
|
2012-12-01 13:36:13 +00:00
|
|
|
GtkCssSide before, after;
|
2012-01-08 00:17:48 +00:00
|
|
|
|
|
|
|
before = side;
|
|
|
|
after = (side + 1) % 4;
|
|
|
|
|
|
|
|
if (side & 1)
|
2016-12-13 19:36:00 +00:00
|
|
|
length = box->bounds.size.height
|
2016-12-13 19:15:01 +00:00
|
|
|
- box->corner[before].height
|
|
|
|
- box->corner[after].height;
|
2012-01-08 00:17:48 +00:00
|
|
|
else
|
2016-12-13 19:36:00 +00:00
|
|
|
length = box->bounds.size.width
|
2016-12-13 19:15:01 +00:00
|
|
|
- box->corner[before].width
|
|
|
|
- box->corner[after].width;
|
2012-01-08 00:17:48 +00:00
|
|
|
|
2016-12-13 19:15:01 +00:00
|
|
|
length += G_PI * 0.125 * (box->corner[before].width
|
|
|
|
+ box->corner[before].height
|
|
|
|
+ box->corner[after].width
|
|
|
|
+ box->corner[after].height);
|
2012-01-08 00:17:48 +00:00
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_path_side (const GskRoundedRect *box,
|
|
|
|
cairo_t *cr,
|
|
|
|
GtkCssSide side)
|
2012-01-08 00:17:48 +00:00
|
|
|
{
|
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case GTK_CSS_TOP:
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
box->bounds.origin.y + box->corner[GSK_CORNER_TOP_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
5 * G_PI_4, 3 * G_PI_2);
|
2012-01-08 00:17:48 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->bounds.size.width - box->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
box->bounds.origin.y + box->corner[GSK_CORNER_TOP_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
- G_PI_2, -G_PI_4);
|
2012-01-08 00:17:48 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_RIGHT:
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->bounds.size.width - box->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
box->bounds.origin.y + box->corner[GSK_CORNER_TOP_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
box->corner[GSK_CORNER_TOP_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
- G_PI_4, 0);
|
2012-01-08 00:17:48 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->bounds.size.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
box->bounds.origin.y + box->bounds.size.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
0, G_PI_4);
|
2012-01-08 00:17:48 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_BOTTOM:
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->bounds.size.width - box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
box->bounds.origin.y + box->bounds.size.height - box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
G_PI_4, G_PI_2);
|
2012-01-08 00:17:48 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
box->bounds.origin.y + box->bounds.size.height - box->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
G_PI_2, 3 * G_PI_4);
|
2012-01-08 00:17:48 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_LEFT:
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
box->bounds.origin.y + box->bounds.size.height - box->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
box->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
3 * G_PI_4, G_PI);
|
2012-01-08 00:17:48 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x + box->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
box->bounds.origin.y + box->corner[GSK_CORNER_TOP_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
box->corner[GSK_CORNER_TOP_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
G_PI, 5 * G_PI_4);
|
2012-01-08 00:17:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-13 03:04:44 +00:00
|
|
|
void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_path_top (const GskRoundedRect *outer,
|
|
|
|
const GskRoundedRect *inner,
|
|
|
|
cairo_t *cr)
|
2011-06-13 03:04:44 +00:00
|
|
|
{
|
2015-01-22 14:47:36 +00:00
|
|
|
double start_angle, middle_angle, end_angle;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.y == inner->bounds.origin.y)
|
2015-01-22 14:47:36 +00:00
|
|
|
return;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.x == inner->bounds.origin.x)
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle = G_PI;
|
|
|
|
else
|
|
|
|
start_angle = 5 * G_PI_4;
|
|
|
|
middle_angle = 3 * G_PI_2;
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.x + outer->bounds.size.width == inner->bounds.origin.x + inner->bounds.size.width)
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle = 0;
|
|
|
|
else
|
|
|
|
end_angle = 7 * G_PI_4;
|
|
|
|
|
2011-06-13 03:04:44 +00:00
|
|
|
cairo_new_sub_path (cr);
|
|
|
|
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
outer->bounds.origin.y + outer->corner[GSK_CORNER_TOP_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
outer->corner[GSK_CORNER_TOP_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->bounds.size.width - outer->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
outer->bounds.origin.y + outer->corner[GSK_CORNER_TOP_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
outer->corner[GSK_CORNER_TOP_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, end_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->bounds.size.width - inner->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
inner->bounds.origin.y + inner->corner[GSK_CORNER_TOP_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
inner->corner[GSK_CORNER_TOP_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
inner->bounds.origin.y + inner->corner[GSK_CORNER_TOP_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
inner->corner[GSK_CORNER_TOP_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, start_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
cairo_close_path (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_path_right (const GskRoundedRect *outer,
|
|
|
|
const GskRoundedRect *inner,
|
|
|
|
cairo_t *cr)
|
2011-06-13 03:04:44 +00:00
|
|
|
{
|
2015-01-22 14:47:36 +00:00
|
|
|
double start_angle, middle_angle, end_angle;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.x + outer->bounds.size.width == inner->bounds.origin.x + inner->bounds.size.width)
|
2015-01-22 14:47:36 +00:00
|
|
|
return;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.y == inner->bounds.origin.y)
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle = 3 * G_PI_2;
|
|
|
|
else
|
|
|
|
start_angle = 7 * G_PI_4;
|
|
|
|
middle_angle = 0;
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.y + outer->bounds.size.height == inner->bounds.origin.y + inner->bounds.size.height)
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle = G_PI_2;
|
|
|
|
else
|
|
|
|
end_angle = G_PI_4;
|
|
|
|
|
2011-06-13 03:04:44 +00:00
|
|
|
cairo_new_sub_path (cr);
|
|
|
|
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->bounds.size.width - outer->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
outer->bounds.origin.y + outer->corner[GSK_CORNER_TOP_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
outer->corner[GSK_CORNER_TOP_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->bounds.size.width - outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
outer->bounds.origin.y + outer->bounds.size.height - outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, end_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->bounds.size.width - inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
inner->bounds.origin.y + inner->bounds.size.height - inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->bounds.size.width - inner->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
inner->bounds.origin.y + inner->corner[GSK_CORNER_TOP_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_TOP_RIGHT].width,
|
|
|
|
inner->corner[GSK_CORNER_TOP_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, start_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
cairo_close_path (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_path_bottom (const GskRoundedRect *outer,
|
|
|
|
const GskRoundedRect *inner,
|
|
|
|
cairo_t *cr)
|
2011-06-13 03:04:44 +00:00
|
|
|
{
|
2015-01-22 14:47:36 +00:00
|
|
|
double start_angle, middle_angle, end_angle;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.y + outer->bounds.size.height == inner->bounds.origin.y + inner->bounds.size.height)
|
2015-01-22 14:47:36 +00:00
|
|
|
return;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.x + outer->bounds.size.width == inner->bounds.origin.x + inner->bounds.size.width)
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle = 0;
|
|
|
|
else
|
|
|
|
start_angle = G_PI_4;
|
|
|
|
middle_angle = G_PI_2;
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.x == inner->bounds.origin.x)
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle = G_PI;
|
|
|
|
else
|
|
|
|
end_angle = 3 * G_PI_4;
|
|
|
|
|
2011-06-13 03:04:44 +00:00
|
|
|
cairo_new_sub_path (cr);
|
|
|
|
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->bounds.size.width - outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
outer->bounds.origin.y + outer->bounds.size.height - outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
outer->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
outer->bounds.origin.y + outer->bounds.size.height - outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, end_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
inner->bounds.origin.y + inner->bounds.size.height - inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->bounds.size.width - inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
inner->bounds.origin.y + inner->bounds.size.height - inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
|
|
|
inner->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, start_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
cairo_close_path (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_path_left (const GskRoundedRect *outer,
|
|
|
|
const GskRoundedRect *inner,
|
|
|
|
cairo_t *cr)
|
2011-06-13 03:04:44 +00:00
|
|
|
{
|
2015-01-22 14:47:36 +00:00
|
|
|
double start_angle, middle_angle, end_angle;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.x == inner->bounds.origin.x)
|
2015-01-22 14:47:36 +00:00
|
|
|
return;
|
|
|
|
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.y + outer->bounds.size.height == inner->bounds.origin.y + inner->bounds.size.height)
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle = G_PI_2;
|
|
|
|
else
|
|
|
|
start_angle = 3 * G_PI_4;
|
|
|
|
middle_angle = G_PI;
|
2016-12-13 19:36:00 +00:00
|
|
|
if (outer->bounds.origin.y == inner->bounds.origin.y)
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle = 3 * G_PI_2;
|
|
|
|
else
|
|
|
|
end_angle = 5 * G_PI_4;
|
|
|
|
|
2011-06-13 03:04:44 +00:00
|
|
|
cairo_new_sub_path (cr);
|
|
|
|
|
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
outer->bounds.origin.y + outer->bounds.size.height - outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
outer->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
start_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
outer->bounds.origin.x + outer->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
outer->bounds.origin.y + outer->corner[GSK_CORNER_TOP_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
outer->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
outer->corner[GSK_CORNER_TOP_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, end_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
inner->bounds.origin.y + inner->corner[GSK_CORNER_TOP_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_TOP_LEFT].width,
|
|
|
|
inner->corner[GSK_CORNER_TOP_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
end_angle, middle_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
_cairo_ellipsis_negative (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
inner->bounds.origin.x + inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
inner->bounds.origin.y + inner->bounds.size.height - inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2016-12-13 19:15:01 +00:00
|
|
|
inner->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
|
|
|
inner->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
2015-01-22 14:47:36 +00:00
|
|
|
middle_angle, start_angle);
|
2011-06-13 03:04:44 +00:00
|
|
|
|
|
|
|
cairo_close_path (cr);
|
|
|
|
}
|
|
|
|
|
2011-06-11 01:57:57 +00:00
|
|
|
void
|
2016-12-13 19:48:58 +00:00
|
|
|
_gtk_rounded_box_clip_path (const GskRoundedRect *box,
|
|
|
|
cairo_t *cr)
|
2011-06-11 01:57:57 +00:00
|
|
|
{
|
|
|
|
cairo_rectangle (cr,
|
2016-12-13 19:36:00 +00:00
|
|
|
box->bounds.origin.x, box->bounds.origin.y,
|
|
|
|
box->bounds.size.width, box->bounds.size.height);
|
2011-06-11 01:57:57 +00:00
|
|
|
}
|
|
|
|
|