2011-05-26 19:53:28 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
* Copyright (C) 2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Authors: Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
* Cosimo Cecchi <cosimoc@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-05-26 19:53:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2015-01-17 17:00:03 +00:00
|
|
|
#include "gtkrenderborderprivate.h"
|
|
|
|
|
|
|
|
#include <cairo-gobject.h>
|
2011-05-26 19:53:28 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2012-04-04 14:15:41 +00:00
|
|
|
#include "gtkcssbordervalueprivate.h"
|
2015-01-17 17:15:19 +00:00
|
|
|
#include "gtkcssenumvalueprivate.h"
|
2012-03-29 00:58:32 +00:00
|
|
|
#include "gtkcssimagevalueprivate.h"
|
2012-04-04 14:15:41 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2012-04-04 09:44:57 +00:00
|
|
|
#include "gtkcssrepeatvalueprivate.h"
|
2020-01-10 12:02:33 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2015-01-17 04:27:23 +00:00
|
|
|
#include "gtkcssstyleprivate.h"
|
2015-01-17 17:15:19 +00:00
|
|
|
#include "gtkhslaprivate.h"
|
|
|
|
#include "gtkroundedboxprivate.h"
|
2018-03-20 03:33:58 +00:00
|
|
|
#include "gtksnapshotprivate.h"
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2016-12-13 20:00:28 +00:00
|
|
|
#include "gsk/gskroundedrectprivate.h"
|
|
|
|
|
2011-08-19 06:26:52 +00:00
|
|
|
/* this is in case round() is not provided by the compiler,
|
|
|
|
* such as in the case of C89 compilers, like MSVC
|
|
|
|
*/
|
|
|
|
#include "fallback-c89.c"
|
|
|
|
|
2015-01-17 17:15:19 +00:00
|
|
|
typedef struct _GtkBorderImage GtkBorderImage;
|
|
|
|
|
|
|
|
struct _GtkBorderImage {
|
|
|
|
GtkCssImage *source;
|
|
|
|
|
|
|
|
GtkCssValue *slice;
|
|
|
|
GtkCssValue *width;
|
|
|
|
GtkCssValue *repeat;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_border_image_init (GtkBorderImage *image,
|
|
|
|
GtkCssStyle *style)
|
2012-01-04 03:00:58 +00:00
|
|
|
{
|
2020-01-28 07:38:25 +00:00
|
|
|
image->source = _gtk_css_image_value_get_image (style->border->border_image_source);
|
2012-01-04 03:17:38 +00:00
|
|
|
if (image->source == NULL)
|
|
|
|
return FALSE;
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
image->slice = style->border->border_image_slice;
|
|
|
|
image->width = style->border->border_image_width;
|
|
|
|
image->repeat = style->border->border_image_repeat;
|
2011-06-09 23:59:14 +00:00
|
|
|
|
2012-01-04 03:17:38 +00:00
|
|
|
return TRUE;
|
2011-05-26 19:53:28 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
typedef struct _GtkBorderImageSliceSize GtkBorderImageSliceSize;
|
|
|
|
struct _GtkBorderImageSliceSize {
|
|
|
|
double offset;
|
|
|
|
double size;
|
|
|
|
};
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
static void
|
2012-04-04 15:42:45 +00:00
|
|
|
gtk_border_image_compute_border_size (GtkBorderImageSliceSize sizes[3],
|
|
|
|
double offset,
|
|
|
|
double area_size,
|
2012-10-27 01:16:35 +00:00
|
|
|
double start_border_width,
|
|
|
|
double end_border_width,
|
2012-04-04 15:42:45 +00:00
|
|
|
const GtkCssValue *start_border,
|
|
|
|
const GtkCssValue *end_border)
|
2011-05-26 19:53:28 +00:00
|
|
|
{
|
2012-04-04 15:42:45 +00:00
|
|
|
double start, end;
|
|
|
|
|
2016-02-12 03:40:35 +00:00
|
|
|
if (gtk_css_number_value_get_dimension (start_border) == GTK_CSS_DIMENSION_NUMBER)
|
2012-04-04 15:42:45 +00:00
|
|
|
start = start_border_width * _gtk_css_number_value_get (start_border, 100);
|
|
|
|
else
|
|
|
|
start = _gtk_css_number_value_get (start_border, area_size);
|
2016-02-12 03:40:35 +00:00
|
|
|
if (gtk_css_number_value_get_dimension (end_border) == GTK_CSS_DIMENSION_NUMBER)
|
2012-04-04 15:42:45 +00:00
|
|
|
end = end_border_width * _gtk_css_number_value_get (end_border, 100);
|
|
|
|
else
|
|
|
|
end = _gtk_css_number_value_get (end_border, area_size);
|
|
|
|
|
|
|
|
/* XXX: reduce vertical and horizontal by the same factor */
|
|
|
|
if (start + end > area_size)
|
|
|
|
{
|
|
|
|
start = start * area_size / (start + end);
|
|
|
|
end = end * area_size / (start + end);
|
|
|
|
}
|
2011-06-08 23:41:18 +00:00
|
|
|
|
|
|
|
sizes[0].offset = offset;
|
2012-04-04 15:42:45 +00:00
|
|
|
sizes[0].size = start;
|
|
|
|
sizes[1].offset = offset + start;
|
|
|
|
sizes[1].size = area_size - start - end;
|
|
|
|
sizes[2].offset = offset + area_size - end;
|
|
|
|
sizes[2].size = end;
|
2011-05-26 19:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-08 23:41:18 +00:00
|
|
|
gtk_border_image_render_slice (cairo_t *cr,
|
|
|
|
cairo_surface_t *slice,
|
|
|
|
double slice_width,
|
|
|
|
double slice_height,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double width,
|
|
|
|
double height,
|
2012-04-04 09:44:57 +00:00
|
|
|
GtkCssRepeatStyle hrepeat,
|
|
|
|
GtkCssRepeatStyle vrepeat)
|
2011-05-26 19:53:28 +00:00
|
|
|
{
|
2011-06-08 23:41:18 +00:00
|
|
|
double hscale, vscale;
|
|
|
|
double xstep, ystep;
|
|
|
|
cairo_extend_t extend = CAIRO_EXTEND_PAD;
|
|
|
|
cairo_matrix_t matrix;
|
2011-05-26 19:53:28 +00:00
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
/* We can't draw center tiles yet */
|
2011-11-25 14:30:10 +00:00
|
|
|
g_assert (hrepeat == GTK_CSS_REPEAT_STYLE_STRETCH || vrepeat == GTK_CSS_REPEAT_STYLE_STRETCH);
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
hscale = width / slice_width;
|
|
|
|
vscale = height / slice_height;
|
|
|
|
xstep = width;
|
|
|
|
ystep = height;
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
switch (hrepeat)
|
2011-05-26 19:53:28 +00:00
|
|
|
{
|
2011-06-08 23:41:18 +00:00
|
|
|
case GTK_CSS_REPEAT_STYLE_REPEAT:
|
|
|
|
extend = CAIRO_EXTEND_REPEAT;
|
|
|
|
hscale = vscale;
|
|
|
|
break;
|
|
|
|
case GTK_CSS_REPEAT_STYLE_SPACE:
|
|
|
|
{
|
|
|
|
double space, n;
|
|
|
|
|
|
|
|
extend = CAIRO_EXTEND_NONE;
|
|
|
|
hscale = vscale;
|
|
|
|
|
|
|
|
xstep = hscale * slice_width;
|
|
|
|
n = floor (width / xstep);
|
|
|
|
space = (width - n * xstep) / (n + 1);
|
|
|
|
xstep += space;
|
|
|
|
x += space;
|
|
|
|
width -= 2 * space;
|
|
|
|
}
|
|
|
|
break;
|
2011-11-25 14:30:10 +00:00
|
|
|
case GTK_CSS_REPEAT_STYLE_STRETCH:
|
2011-06-08 23:41:18 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_REPEAT_STYLE_ROUND:
|
|
|
|
extend = CAIRO_EXTEND_REPEAT;
|
|
|
|
hscale = width / (slice_width * MAX (round (width / (slice_width * vscale)), 1));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2011-05-26 19:53:28 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
switch (vrepeat)
|
2011-05-26 19:53:28 +00:00
|
|
|
{
|
2011-06-08 23:41:18 +00:00
|
|
|
case GTK_CSS_REPEAT_STYLE_REPEAT:
|
|
|
|
extend = CAIRO_EXTEND_REPEAT;
|
|
|
|
vscale = hscale;
|
|
|
|
break;
|
|
|
|
case GTK_CSS_REPEAT_STYLE_SPACE:
|
|
|
|
{
|
|
|
|
double space, n;
|
|
|
|
|
|
|
|
extend = CAIRO_EXTEND_NONE;
|
|
|
|
vscale = hscale;
|
|
|
|
|
|
|
|
ystep = vscale * slice_height;
|
|
|
|
n = floor (height / ystep);
|
|
|
|
space = (height - n * ystep) / (n + 1);
|
|
|
|
ystep += space;
|
|
|
|
y += space;
|
|
|
|
height -= 2 * space;
|
|
|
|
}
|
|
|
|
break;
|
2011-11-25 14:30:10 +00:00
|
|
|
case GTK_CSS_REPEAT_STYLE_STRETCH:
|
2011-06-08 23:41:18 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_REPEAT_STYLE_ROUND:
|
|
|
|
extend = CAIRO_EXTEND_REPEAT;
|
|
|
|
vscale = height / (slice_height * MAX (round (height / (slice_height * hscale)), 1));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2011-05-26 19:53:28 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
pattern = cairo_pattern_create_for_surface (slice);
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
cairo_matrix_init_translate (&matrix,
|
|
|
|
hrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? slice_width / 2 : 0,
|
|
|
|
vrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? slice_height / 2 : 0);
|
|
|
|
cairo_matrix_scale (&matrix, 1 / hscale, 1 / vscale);
|
|
|
|
cairo_matrix_translate (&matrix,
|
|
|
|
hrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? - width / 2 : 0,
|
|
|
|
vrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? - height / 2 : 0);
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
|
|
|
cairo_pattern_set_extend (pattern, extend);
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
cairo_save (cr);
|
|
|
|
cairo_translate (cr, x, y);
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
for (y = 0; y < height; y += ystep)
|
|
|
|
{
|
|
|
|
for (x = 0; x < width; x += xstep)
|
2011-05-26 19:53:28 +00:00
|
|
|
{
|
2011-06-08 23:41:18 +00:00
|
|
|
cairo_save (cr);
|
|
|
|
cairo_translate (cr, x, y);
|
|
|
|
cairo_set_source (cr, pattern);
|
|
|
|
cairo_rectangle (cr, 0, 0, xstep, ystep);
|
|
|
|
cairo_fill (cr);
|
|
|
|
cairo_restore (cr);
|
2011-05-26 19:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
cairo_restore (cr);
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
}
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
static void
|
|
|
|
gtk_border_image_compute_slice_size (GtkBorderImageSliceSize sizes[3],
|
|
|
|
int surface_size,
|
|
|
|
int start_size,
|
|
|
|
int end_size)
|
|
|
|
{
|
|
|
|
sizes[0].size = MIN (start_size, surface_size);
|
|
|
|
sizes[0].offset = 0;
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
sizes[2].size = MIN (end_size, surface_size);
|
|
|
|
sizes[2].offset = surface_size - sizes[2].size;
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
sizes[1].size = MAX (0, surface_size - sizes[0].size - sizes[2].size);
|
|
|
|
sizes[1].offset = sizes[0].size;
|
2011-05-26 19:53:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 05:48:31 +00:00
|
|
|
static void
|
2019-02-15 05:15:50 +00:00
|
|
|
gtk_border_image_render (GtkBorderImage *image,
|
|
|
|
const float border_width[4],
|
|
|
|
cairo_t *cr,
|
|
|
|
const graphene_rect_t *rect)
|
2011-05-26 19:53:28 +00:00
|
|
|
{
|
2011-06-01 14:23:36 +00:00
|
|
|
cairo_surface_t *surface, *slice;
|
2011-06-08 23:41:18 +00:00
|
|
|
GtkBorderImageSliceSize vertical_slice[3], horizontal_slice[3];
|
|
|
|
GtkBorderImageSliceSize vertical_border[3], horizontal_border[3];
|
2011-12-21 16:43:31 +00:00
|
|
|
double source_width, source_height;
|
2011-06-08 23:41:18 +00:00
|
|
|
int h, v;
|
2011-06-01 14:23:36 +00:00
|
|
|
|
2011-12-21 16:43:31 +00:00
|
|
|
_gtk_css_image_get_concrete_size (image->source,
|
|
|
|
0, 0,
|
2019-02-15 05:15:50 +00:00
|
|
|
rect->size.width, rect->size.height,
|
2011-12-21 16:43:31 +00:00
|
|
|
&source_width, &source_height);
|
2011-06-01 14:23:36 +00:00
|
|
|
|
2011-12-21 16:43:31 +00:00
|
|
|
/* XXX: Optimize for (source_width == width && source_height == height) */
|
2011-06-01 14:23:36 +00:00
|
|
|
|
2011-12-21 16:43:31 +00:00
|
|
|
surface = _gtk_css_image_get_surface (image->source,
|
|
|
|
cairo_get_target (cr),
|
|
|
|
source_width, source_height);
|
2011-05-26 19:53:28 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
gtk_border_image_compute_slice_size (horizontal_slice,
|
2011-12-21 16:43:31 +00:00
|
|
|
source_width,
|
2012-04-04 14:15:41 +00:00
|
|
|
_gtk_css_number_value_get (_gtk_css_border_value_get_left (image->slice), source_width),
|
|
|
|
_gtk_css_number_value_get (_gtk_css_border_value_get_right (image->slice), source_width));
|
2011-06-08 23:41:18 +00:00
|
|
|
gtk_border_image_compute_slice_size (vertical_slice,
|
2011-12-21 16:43:31 +00:00
|
|
|
source_height,
|
2012-04-04 14:15:41 +00:00
|
|
|
_gtk_css_number_value_get (_gtk_css_border_value_get_top (image->slice), source_height),
|
|
|
|
_gtk_css_number_value_get (_gtk_css_border_value_get_bottom (image->slice), source_height));
|
2011-06-08 23:41:18 +00:00
|
|
|
gtk_border_image_compute_border_size (horizontal_border,
|
2019-02-15 05:15:50 +00:00
|
|
|
rect->origin.x,
|
|
|
|
rect->size.width,
|
2012-10-27 01:16:35 +00:00
|
|
|
border_width[GTK_CSS_LEFT],
|
|
|
|
border_width[GTK_CSS_RIGHT],
|
2012-04-04 15:42:45 +00:00
|
|
|
_gtk_css_border_value_get_left (image->width),
|
|
|
|
_gtk_css_border_value_get_right (image->width));
|
2011-06-08 23:41:18 +00:00
|
|
|
gtk_border_image_compute_border_size (vertical_border,
|
2019-02-15 05:15:50 +00:00
|
|
|
rect->origin.y,
|
|
|
|
rect->size.height,
|
2012-10-27 01:16:35 +00:00
|
|
|
border_width[GTK_CSS_TOP],
|
|
|
|
border_width[GTK_CSS_BOTTOM],
|
2012-04-04 15:42:45 +00:00
|
|
|
_gtk_css_border_value_get_top (image->width),
|
|
|
|
_gtk_css_border_value_get_bottom(image->width));
|
2011-06-08 23:41:18 +00:00
|
|
|
|
|
|
|
for (v = 0; v < 3; v++)
|
2011-06-01 14:23:36 +00:00
|
|
|
{
|
2011-06-08 23:41:18 +00:00
|
|
|
if (vertical_slice[v].size == 0 ||
|
|
|
|
vertical_border[v].size == 0)
|
|
|
|
continue;
|
2011-06-01 14:23:36 +00:00
|
|
|
|
2011-06-08 23:41:18 +00:00
|
|
|
for (h = 0; h < 3; h++)
|
|
|
|
{
|
|
|
|
if (horizontal_slice[h].size == 0 ||
|
2011-06-09 21:05:27 +00:00
|
|
|
horizontal_border[h].size == 0)
|
2011-06-08 23:41:18 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (h == 1 && v == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
slice = cairo_surface_create_for_rectangle (surface,
|
|
|
|
horizontal_slice[h].offset,
|
|
|
|
vertical_slice[v].offset,
|
|
|
|
horizontal_slice[h].size,
|
|
|
|
vertical_slice[v].size);
|
|
|
|
|
|
|
|
gtk_border_image_render_slice (cr,
|
|
|
|
slice,
|
|
|
|
horizontal_slice[h].size,
|
|
|
|
vertical_slice[v].size,
|
|
|
|
horizontal_border[h].offset,
|
|
|
|
vertical_border[v].offset,
|
|
|
|
horizontal_border[h].size,
|
|
|
|
vertical_border[v].size,
|
2012-04-04 09:44:57 +00:00
|
|
|
h == 1 ? _gtk_css_border_repeat_value_get_x (image->repeat) : GTK_CSS_REPEAT_STYLE_STRETCH,
|
|
|
|
v == 1 ? _gtk_css_border_repeat_value_get_y (image->repeat) : GTK_CSS_REPEAT_STYLE_STRETCH);
|
2011-06-08 23:41:18 +00:00
|
|
|
|
|
|
|
cairo_surface_destroy (slice);
|
|
|
|
}
|
2011-06-01 14:23:36 +00:00
|
|
|
}
|
2011-06-15 11:45:34 +00:00
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
2011-05-26 19:53:28 +00:00
|
|
|
}
|
2015-01-17 17:15:19 +00:00
|
|
|
|
2016-12-18 17:14:53 +00:00
|
|
|
static void
|
|
|
|
snapshot_frame_fill (GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *outline,
|
|
|
|
const float border_width[4],
|
|
|
|
const GdkRGBA colors[4],
|
|
|
|
guint hidden_side)
|
|
|
|
{
|
|
|
|
if (hidden_side)
|
|
|
|
{
|
|
|
|
GdkRGBA real_colors[4];
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (hidden_side & (1 << i))
|
|
|
|
real_colors[i] = (GdkRGBA) { 0, 0, 0, 0 };
|
|
|
|
else
|
|
|
|
real_colors[i] = colors[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot_frame_fill (snapshot, outline, border_width, real_colors, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-21 01:11:13 +00:00
|
|
|
gtk_snapshot_append_border (snapshot, outline, border_width, colors);
|
2016-12-18 17:14:53 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 17:15:19 +00:00
|
|
|
static void
|
|
|
|
set_stroke_style (cairo_t *cr,
|
|
|
|
double line_width,
|
|
|
|
GtkBorderStyle style,
|
|
|
|
double length)
|
|
|
|
{
|
|
|
|
double segments[2];
|
|
|
|
double n;
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, line_width);
|
|
|
|
|
|
|
|
if (style == GTK_BORDER_STYLE_DOTTED)
|
|
|
|
{
|
|
|
|
n = round (0.5 * length / line_width);
|
|
|
|
|
|
|
|
segments[0] = 0;
|
|
|
|
segments[1] = n ? length / n : 2;
|
|
|
|
cairo_set_dash (cr, segments, G_N_ELEMENTS (segments), 0);
|
|
|
|
|
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
|
|
|
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = length / line_width;
|
|
|
|
/* Optimize the common case of an integer-sized rectangle
|
|
|
|
* Again, we care about focus rectangles.
|
|
|
|
*/
|
|
|
|
if (n == nearbyint (n))
|
|
|
|
{
|
2018-09-21 12:25:23 +00:00
|
|
|
segments[0] = line_width;
|
|
|
|
segments[1] = 2 * line_width;
|
2015-01-17 17:15:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = round ((1. / 3) * n);
|
|
|
|
|
|
|
|
segments[0] = n ? (1. / 3) * length / n : 1;
|
|
|
|
segments[1] = 2 * segments[0];
|
|
|
|
}
|
|
|
|
cairo_set_dash (cr, segments, G_N_ELEMENTS (segments), 0);
|
|
|
|
|
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
|
|
|
|
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-15 05:15:50 +00:00
|
|
|
render_frame_stroke (cairo_t *cr,
|
|
|
|
const GskRoundedRect *border_box,
|
|
|
|
const double border_width[4],
|
|
|
|
GdkRGBA colors[4],
|
|
|
|
guint hidden_side,
|
|
|
|
GtkBorderStyle stroke_style)
|
2015-01-17 17:15:19 +00:00
|
|
|
{
|
|
|
|
gboolean different_colors, different_borders;
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect stroke_box;
|
2015-01-17 17:15:19 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
different_colors = !gdk_rgba_equal (&colors[0], &colors[1]) ||
|
|
|
|
!gdk_rgba_equal (&colors[0], &colors[2]) ||
|
|
|
|
!gdk_rgba_equal (&colors[0], &colors[3]);
|
|
|
|
different_borders = border_width[0] != border_width[1] ||
|
|
|
|
border_width[0] != border_width[2] ||
|
|
|
|
border_width[0] != border_width[3] ;
|
|
|
|
|
|
|
|
stroke_box = *border_box;
|
2016-12-18 16:10:45 +00:00
|
|
|
gsk_rounded_rect_shrink (&stroke_box,
|
2015-01-17 17:15:19 +00:00
|
|
|
border_width[GTK_CSS_TOP] / 2.0,
|
|
|
|
border_width[GTK_CSS_RIGHT] / 2.0,
|
|
|
|
border_width[GTK_CSS_BOTTOM] / 2.0,
|
|
|
|
border_width[GTK_CSS_LEFT] / 2.0);
|
|
|
|
|
|
|
|
if (!different_colors && !different_borders && hidden_side == 0)
|
|
|
|
{
|
|
|
|
double length = 0;
|
|
|
|
|
|
|
|
/* FAST PATH:
|
|
|
|
* Mostly expected to trigger for focus rectangles */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
length += _gtk_rounded_box_guess_length (&stroke_box, i);
|
|
|
|
}
|
|
|
|
|
2016-12-13 20:00:28 +00:00
|
|
|
gsk_rounded_rect_path (&stroke_box, cr);
|
2015-01-17 17:15:19 +00:00
|
|
|
gdk_cairo_set_source_rgba (cr, &colors[0]);
|
|
|
|
set_stroke_style (cr, border_width[0], stroke_style, length);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect padding_box;
|
2015-01-17 17:15:19 +00:00
|
|
|
|
|
|
|
padding_box = *border_box;
|
2016-12-18 16:10:45 +00:00
|
|
|
gsk_rounded_rect_shrink (&padding_box,
|
2015-01-17 17:15:19 +00:00
|
|
|
border_width[GTK_CSS_TOP],
|
|
|
|
border_width[GTK_CSS_RIGHT],
|
|
|
|
border_width[GTK_CSS_BOTTOM],
|
|
|
|
border_width[GTK_CSS_LEFT]);
|
|
|
|
|
2016-01-09 22:30:33 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
2015-01-17 17:15:19 +00:00
|
|
|
{
|
|
|
|
if (hidden_side & (1 << i))
|
|
|
|
continue;
|
|
|
|
|
2016-01-09 22:30:33 +00:00
|
|
|
if (border_width[i] == 0)
|
|
|
|
continue;
|
|
|
|
|
2015-01-17 17:15:19 +00:00
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
_gtk_rounded_box_path_top (border_box, &padding_box, cr);
|
|
|
|
else if (i == 1)
|
|
|
|
_gtk_rounded_box_path_right (border_box, &padding_box, cr);
|
|
|
|
else if (i == 2)
|
|
|
|
_gtk_rounded_box_path_bottom (border_box, &padding_box, cr);
|
|
|
|
else if (i == 3)
|
|
|
|
_gtk_rounded_box_path_left (border_box, &padding_box, cr);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
_gtk_rounded_box_path_side (&stroke_box, cr, i);
|
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, &colors[i]);
|
|
|
|
set_stroke_style (cr,
|
|
|
|
border_width[i],
|
|
|
|
stroke_style,
|
|
|
|
_gtk_rounded_box_guess_length (&stroke_box, i));
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-18 17:14:53 +00:00
|
|
|
static void
|
2019-02-15 05:15:50 +00:00
|
|
|
snapshot_frame_stroke (GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *outline,
|
|
|
|
const float border_width[4],
|
|
|
|
GdkRGBA colors[4],
|
|
|
|
guint hidden_side,
|
|
|
|
GtkBorderStyle stroke_style)
|
2016-12-18 17:14:53 +00:00
|
|
|
{
|
|
|
|
double double_width[4] = { border_width[0], border_width[1], border_width[2], border_width[3] };
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2017-01-13 03:46:09 +00:00
|
|
|
cr = gtk_snapshot_append_cairo (snapshot,
|
2018-04-24 01:17:23 +00:00
|
|
|
&outline->bounds);
|
2016-12-18 17:14:53 +00:00
|
|
|
render_frame_stroke (cr, outline, double_width, colors, hidden_side, stroke_style);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
}
|
|
|
|
|
2015-01-17 17:15:19 +00:00
|
|
|
static void
|
|
|
|
color_shade (const GdkRGBA *color,
|
|
|
|
gdouble factor,
|
|
|
|
GdkRGBA *color_return)
|
|
|
|
{
|
|
|
|
GtkHSLA hsla;
|
|
|
|
|
|
|
|
_gtk_hsla_init_from_rgba (&hsla, color);
|
|
|
|
_gtk_hsla_shade (&hsla, &hsla, factor);
|
|
|
|
_gdk_rgba_init_from_hsla (color_return, &hsla);
|
|
|
|
}
|
|
|
|
|
2016-12-18 17:14:53 +00:00
|
|
|
static void
|
2019-02-15 05:15:50 +00:00
|
|
|
snapshot_border (GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *border_box,
|
|
|
|
const float border_width[4],
|
|
|
|
GdkRGBA colors[4],
|
|
|
|
GtkBorderStyle border_style[4])
|
2016-12-18 17:14:53 +00:00
|
|
|
{
|
|
|
|
guint hidden_side = 0;
|
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (hidden_side & (1 << i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* NB: code below divides by this value */
|
|
|
|
/* a border smaller than this will not noticably modify
|
|
|
|
* pixels on screen, and since we don't compare with 0,
|
|
|
|
* we'll use this value */
|
|
|
|
if (border_width[i] < 1.0 / 1024)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (border_style[i])
|
|
|
|
{
|
|
|
|
case GTK_BORDER_STYLE_NONE:
|
|
|
|
case GTK_BORDER_STYLE_HIDDEN:
|
|
|
|
case GTK_BORDER_STYLE_SOLID:
|
|
|
|
break;
|
|
|
|
case GTK_BORDER_STYLE_INSET:
|
|
|
|
if (i == 1 || i == 2)
|
|
|
|
color_shade (&colors[i], 1.8, &colors[i]);
|
|
|
|
break;
|
|
|
|
case GTK_BORDER_STYLE_OUTSET:
|
|
|
|
if (i == 0 || i == 3)
|
|
|
|
color_shade (&colors[i], 1.8, &colors[i]);
|
|
|
|
break;
|
|
|
|
case GTK_BORDER_STYLE_DOTTED:
|
|
|
|
case GTK_BORDER_STYLE_DASHED:
|
|
|
|
{
|
|
|
|
guint dont_draw = hidden_side;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
if (border_style[j] == border_style[i])
|
|
|
|
hidden_side |= (1 << j);
|
|
|
|
else
|
|
|
|
dont_draw |= (1 << j);
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot_frame_stroke (snapshot, border_box, border_width, colors, dont_draw, border_style[i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_BORDER_STYLE_DOUBLE:
|
|
|
|
{
|
|
|
|
GskRoundedRect other_box;
|
|
|
|
float other_border[4];
|
|
|
|
guint dont_draw = hidden_side;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
if (border_style[j] == GTK_BORDER_STYLE_DOUBLE)
|
|
|
|
hidden_side |= (1 << j);
|
|
|
|
else
|
|
|
|
dont_draw |= (1 << j);
|
|
|
|
|
|
|
|
other_border[j] = border_width[j] / 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot_frame_fill (snapshot, border_box, other_border, colors, dont_draw);
|
|
|
|
|
|
|
|
other_box = *border_box;
|
|
|
|
gsk_rounded_rect_shrink (&other_box,
|
|
|
|
2 * other_border[GTK_CSS_TOP],
|
|
|
|
2 * other_border[GTK_CSS_RIGHT],
|
|
|
|
2 * other_border[GTK_CSS_BOTTOM],
|
|
|
|
2 * other_border[GTK_CSS_LEFT]);
|
|
|
|
snapshot_frame_fill (snapshot, &other_box, other_border, colors, dont_draw);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_BORDER_STYLE_GROOVE:
|
|
|
|
case GTK_BORDER_STYLE_RIDGE:
|
|
|
|
{
|
|
|
|
GskRoundedRect other_box;
|
|
|
|
GdkRGBA other_colors[4];
|
|
|
|
guint dont_draw = hidden_side;
|
|
|
|
float other_border[4];
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
other_colors[j] = colors[j];
|
|
|
|
if ((j == 0 || j == 3) ^ (border_style[j] == GTK_BORDER_STYLE_RIDGE))
|
|
|
|
color_shade (&other_colors[j], 1.8, &other_colors[j]);
|
|
|
|
else
|
|
|
|
color_shade (&colors[j], 1.8, &colors[j]);
|
|
|
|
if (border_style[j] == GTK_BORDER_STYLE_GROOVE ||
|
|
|
|
border_style[j] == GTK_BORDER_STYLE_RIDGE)
|
|
|
|
hidden_side |= (1 << j);
|
|
|
|
else
|
|
|
|
dont_draw |= (1 << j);
|
|
|
|
other_border[j] = border_width[j] / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot_frame_fill (snapshot, border_box, other_border, colors, dont_draw);
|
|
|
|
|
|
|
|
other_box = *border_box;
|
|
|
|
gsk_rounded_rect_shrink (&other_box,
|
|
|
|
other_border[GTK_CSS_TOP],
|
|
|
|
other_border[GTK_CSS_RIGHT],
|
|
|
|
other_border[GTK_CSS_BOTTOM],
|
|
|
|
other_border[GTK_CSS_LEFT]);
|
|
|
|
snapshot_frame_fill (snapshot, &other_box, other_border, other_colors, dont_draw);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot_frame_fill (snapshot, border_box, border_width, colors, hidden_side);
|
|
|
|
}
|
|
|
|
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2019-02-15 05:15:50 +00:00
|
|
|
gtk_css_style_snapshot_border (GtkCssBoxes *boxes,
|
|
|
|
GtkSnapshot *snapshot)
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
2020-01-28 07:38:25 +00:00
|
|
|
GtkCssBorderValues *border;
|
2016-11-13 15:16:39 +00:00
|
|
|
GtkBorderImage border_image;
|
2016-12-18 17:14:53 +00:00
|
|
|
float border_width[4];
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
border = boxes->style->border;
|
|
|
|
|
2019-02-15 05:15:50 +00:00
|
|
|
if (gtk_border_image_init (&border_image, boxes->style))
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
2018-08-20 05:52:58 +00:00
|
|
|
cairo_t *cr;
|
2019-02-15 05:15:50 +00:00
|
|
|
const graphene_rect_t *bounds;
|
2016-12-18 17:14:53 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
border_width[0] = _gtk_css_number_value_get (border->border_top_width, 100);
|
|
|
|
border_width[1] = _gtk_css_number_value_get (border->border_right_width, 100);
|
|
|
|
border_width[2] = _gtk_css_number_value_get (border->border_bottom_width, 100);
|
|
|
|
border_width[3] = _gtk_css_number_value_get (border->border_left_width, 100);
|
2019-12-20 19:56:28 +00:00
|
|
|
|
2019-02-15 05:15:50 +00:00
|
|
|
bounds = gtk_css_boxes_get_border_rect (boxes);
|
2018-08-20 05:52:58 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_push_debug (snapshot, "CSS border image");
|
2019-02-15 05:15:50 +00:00
|
|
|
cr = gtk_snapshot_append_cairo (snapshot, bounds);
|
|
|
|
gtk_border_image_render (&border_image, border_width, cr, bounds);
|
2016-11-13 15:16:39 +00:00
|
|
|
cairo_destroy (cr);
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkBorderStyle border_style[4];
|
|
|
|
GdkRGBA colors[4];
|
2017-10-19 13:41:20 +00:00
|
|
|
graphene_simd4f_t alpha_test_vector;
|
2016-11-13 15:16:39 +00:00
|
|
|
|
|
|
|
/* Optimize the most common case of "This widget has no border" */
|
2019-02-15 05:15:50 +00:00
|
|
|
if (graphene_rect_equal (gtk_css_boxes_get_border_rect (boxes),
|
|
|
|
gtk_css_boxes_get_padding_rect (boxes)))
|
2016-11-13 15:16:39 +00:00
|
|
|
return;
|
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
colors[0] = *gtk_css_color_value_get_rgba (border->border_top_color ? border->border_top_color : boxes->style->core->color);
|
|
|
|
colors[1] = *gtk_css_color_value_get_rgba (border->border_right_color ? border->border_right_color : boxes->style->core->color);
|
|
|
|
colors[2] = *gtk_css_color_value_get_rgba (border->border_bottom_color ? border->border_bottom_color : boxes->style->core->color);
|
|
|
|
colors[3] = *gtk_css_color_value_get_rgba (border->border_left_color ? border->border_left_color : boxes->style->core->color);
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2017-10-19 13:41:20 +00:00
|
|
|
alpha_test_vector = graphene_simd4f_init (colors[0].alpha, colors[1].alpha, colors[2].alpha, colors[3].alpha);
|
|
|
|
if (graphene_simd4f_is_zero4 (alpha_test_vector))
|
|
|
|
return;
|
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
border_style[0] = _gtk_css_border_style_value_get (border->border_top_style);
|
|
|
|
border_style[1] = _gtk_css_border_style_value_get (border->border_right_style);
|
|
|
|
border_style[2] = _gtk_css_border_style_value_get (border->border_bottom_style);
|
|
|
|
border_style[3] = _gtk_css_border_style_value_get (border->border_left_style);
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
border_width[0] = _gtk_css_number_value_get (border->border_top_width, 100);
|
|
|
|
border_width[1] = _gtk_css_number_value_get (border->border_right_width, 100);
|
|
|
|
border_width[2] = _gtk_css_number_value_get (border->border_bottom_width, 100);
|
|
|
|
border_width[3] = _gtk_css_number_value_get (border->border_left_width, 100);
|
2019-12-20 19:56:28 +00:00
|
|
|
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_push_debug (snapshot, "CSS border");
|
2019-02-15 05:15:50 +00:00
|
|
|
snapshot_border (snapshot,
|
|
|
|
gtk_css_boxes_get_border_box (boxes),
|
|
|
|
border_width,
|
|
|
|
colors,
|
|
|
|
border_style);
|
2018-04-24 01:17:23 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-15 05:15:50 +00:00
|
|
|
gtk_css_style_snapshot_outline (GtkCssBoxes *boxes,
|
|
|
|
GtkSnapshot *snapshot)
|
2016-11-13 15:16:39 +00:00
|
|
|
{
|
2020-01-28 07:38:25 +00:00
|
|
|
GtkCssOutlineValues *outline = boxes->style->outline;
|
2016-11-13 15:16:39 +00:00
|
|
|
GtkBorderStyle border_style[4];
|
2016-12-18 17:14:53 +00:00
|
|
|
float border_width[4];
|
2016-11-13 15:16:39 +00:00
|
|
|
GdkRGBA colors[4];
|
|
|
|
|
2020-01-28 07:38:25 +00:00
|
|
|
border_style[0] = _gtk_css_border_style_value_get (outline->outline_style);
|
2016-11-13 15:16:39 +00:00
|
|
|
if (border_style[0] != GTK_BORDER_STYLE_NONE)
|
|
|
|
{
|
|
|
|
border_style[1] = border_style[2] = border_style[3] = border_style[0];
|
2020-01-28 07:38:25 +00:00
|
|
|
border_width[0] = _gtk_css_number_value_get (outline->outline_width, 100);
|
2016-11-13 15:16:39 +00:00
|
|
|
border_width[3] = border_width[2] = border_width[1] = border_width[0];
|
2020-01-28 07:38:25 +00:00
|
|
|
colors[0] = *gtk_css_color_value_get_rgba (outline->outline_color ? outline->outline_color : boxes->style->core->color);
|
2016-11-13 15:16:39 +00:00
|
|
|
colors[3] = colors[2] = colors[1] = colors[0];
|
|
|
|
|
2019-02-15 05:15:50 +00:00
|
|
|
snapshot_border (snapshot,
|
|
|
|
gtk_css_boxes_get_outline_box (boxes),
|
|
|
|
border_width,
|
|
|
|
colors,
|
|
|
|
border_style);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
}
|