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"
|
2015-01-17 17:15:19 +00:00
|
|
|
#include "gtkcssrgbavalueprivate.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"
|
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
|
|
|
{
|
2015-01-17 04:27:23 +00:00
|
|
|
image->source = _gtk_css_image_value_get_image (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_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
|
|
|
|
2015-01-17 04:27:23 +00:00
|
|
|
image->slice = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_IMAGE_SLICE);
|
|
|
|
image->width = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_IMAGE_WIDTH);
|
|
|
|
image->repeat = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_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
|
2015-01-17 17:15:19 +00:00
|
|
|
gtk_border_image_render (GtkBorderImage *image,
|
|
|
|
const double border_width[4],
|
|
|
|
cairo_t *cr,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
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,
|
|
|
|
width, height,
|
|
|
|
&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,
|
|
|
|
x,
|
|
|
|
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,
|
|
|
|
y,
|
|
|
|
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
|
|
|
|
|
|
|
static void
|
2016-12-13 19:48:58 +00:00
|
|
|
render_frame_fill (cairo_t *cr,
|
|
|
|
GskRoundedRect *border_box,
|
|
|
|
const double border_width[4],
|
|
|
|
GdkRGBA colors[4],
|
|
|
|
guint hidden_side)
|
2015-01-17 17:15:19 +00:00
|
|
|
{
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect padding_box;
|
2015-01-17 17:15:19 +00:00
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
if (hidden_side == 0 &&
|
|
|
|
gdk_rgba_equal (&colors[0], &colors[1]) &&
|
|
|
|
gdk_rgba_equal (&colors[0], &colors[2]) &&
|
|
|
|
gdk_rgba_equal (&colors[0], &colors[3]))
|
|
|
|
{
|
|
|
|
gdk_cairo_set_source_rgba (cr, &colors[0]);
|
|
|
|
|
2016-12-13 20:00:28 +00:00
|
|
|
gsk_rounded_rect_path (border_box, cr);
|
|
|
|
gsk_rounded_rect_path (&padding_box, cr);
|
2015-01-17 17:15:19 +00:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (hidden_side & (1 << i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
if (hidden_side & (1 << j))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i == j ||
|
|
|
|
(gdk_rgba_equal (&colors[i], &colors[j])))
|
|
|
|
{
|
|
|
|
/* We were already painted when i == j */
|
|
|
|
if (i > j)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (j == 0)
|
|
|
|
_gtk_rounded_box_path_top (border_box, &padding_box, cr);
|
|
|
|
else if (j == 1)
|
|
|
|
_gtk_rounded_box_path_right (border_box, &padding_box, cr);
|
|
|
|
else if (j == 2)
|
|
|
|
_gtk_rounded_box_path_bottom (border_box, &padding_box, cr);
|
|
|
|
else if (j == 3)
|
|
|
|
_gtk_rounded_box_path_left (border_box, &padding_box, cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* We were already painted when i == j */
|
|
|
|
if (i > j)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, &colors[i]);
|
|
|
|
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GskRoundedRect offset_outline;
|
|
|
|
GskRenderNode *node;
|
2017-01-11 15:14:03 +00:00
|
|
|
int off_x, off_y;
|
2016-12-18 17:14:53 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_snapshot_get_offset (snapshot, &off_x, &off_y);
|
|
|
|
gsk_rounded_rect_init_copy (&offset_outline, outline);
|
|
|
|
gsk_rounded_rect_offset (&offset_outline, off_x, off_y);
|
|
|
|
|
|
|
|
node = gsk_border_node_new (&offset_outline, border_width, colors);
|
2018-03-11 05:29:46 +00:00
|
|
|
if (gtk_snapshot_get_record_names (snapshot))
|
2017-01-11 09:08:58 +00:00
|
|
|
gsk_render_node_set_name (node, "Border");
|
2016-12-18 17:14:53 +00:00
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
segments[0] = 1;
|
|
|
|
segments[1] = 2;
|
|
|
|
}
|
|
|
|
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
|
2016-12-13 19:48:58 +00:00
|
|
|
render_frame_stroke (cairo_t *cr,
|
|
|
|
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
|
|
|
|
snapshot_frame_stroke (GtkSnapshot *snapshot,
|
|
|
|
GskRoundedRect *outline,
|
|
|
|
const float border_width[4],
|
|
|
|
GdkRGBA colors[4],
|
|
|
|
guint hidden_side,
|
|
|
|
GtkBorderStyle stroke_style)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
&outline->bounds,
|
|
|
|
"BorderStroke");
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-12-13 19:48:58 +00:00
|
|
|
render_border (cairo_t *cr,
|
|
|
|
GskRoundedRect *border_box,
|
|
|
|
const double border_width[4],
|
|
|
|
GdkRGBA colors[4],
|
|
|
|
GtkBorderStyle border_style[4])
|
2015-01-17 17:15:19 +00:00
|
|
|
{
|
2016-12-18 16:52:47 +00:00
|
|
|
guint hidden_side = 0;
|
2015-01-17 17:15:19 +00:00
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
render_frame_stroke (cr, border_box, border_width, colors, dont_draw, border_style[i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_BORDER_STYLE_DOUBLE:
|
|
|
|
{
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect other_box;
|
2015-01-17 17:15:19 +00:00
|
|
|
double 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);
|
|
|
|
|
2016-01-09 19:36:05 +00:00
|
|
|
other_border[j] = border_width[j] / 3;
|
2015-01-17 17:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render_frame_fill (cr, border_box, other_border, colors, dont_draw);
|
|
|
|
|
|
|
|
other_box = *border_box;
|
2016-12-18 16:10:45 +00:00
|
|
|
gsk_rounded_rect_shrink (&other_box,
|
2015-01-17 17:15:19 +00:00
|
|
|
2 * other_border[GTK_CSS_TOP],
|
|
|
|
2 * other_border[GTK_CSS_RIGHT],
|
|
|
|
2 * other_border[GTK_CSS_BOTTOM],
|
|
|
|
2 * other_border[GTK_CSS_LEFT]);
|
|
|
|
render_frame_fill (cr, &other_box, other_border, colors, dont_draw);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_BORDER_STYLE_GROOVE:
|
|
|
|
case GTK_BORDER_STYLE_RIDGE:
|
|
|
|
{
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect other_box;
|
2015-01-17 17:15:19 +00:00
|
|
|
GdkRGBA other_colors[4];
|
|
|
|
guint dont_draw = hidden_side;
|
|
|
|
double 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);
|
2015-06-23 19:45:33 +00:00
|
|
|
other_border[j] = border_width[j] / 2;
|
2015-01-17 17:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render_frame_fill (cr, border_box, other_border, colors, dont_draw);
|
|
|
|
|
|
|
|
other_box = *border_box;
|
2016-12-18 16:10:45 +00:00
|
|
|
gsk_rounded_rect_shrink (&other_box,
|
2015-01-17 17:15:19 +00:00
|
|
|
other_border[GTK_CSS_TOP],
|
|
|
|
other_border[GTK_CSS_RIGHT],
|
|
|
|
other_border[GTK_CSS_BOTTOM],
|
|
|
|
other_border[GTK_CSS_LEFT]);
|
|
|
|
render_frame_fill (cr, &other_box, other_border, other_colors, dont_draw);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render_frame_fill (cr, border_box, border_width, colors, hidden_side);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2016-12-18 17:14:53 +00:00
|
|
|
static void
|
|
|
|
snapshot_border (GtkSnapshot *snapshot,
|
|
|
|
GskRoundedRect *border_box,
|
|
|
|
const float border_width[4],
|
|
|
|
GdkRGBA colors[4],
|
|
|
|
GtkBorderStyle border_style[4])
|
|
|
|
{
|
|
|
|
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-02-21 00:01:41 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_style_render_has_border (GtkCssStyle *style)
|
|
|
|
{
|
|
|
|
if (_gtk_css_image_value_get_image (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE)))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100) > 0
|
|
|
|
|| _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100) > 0
|
|
|
|
|| _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100) > 0
|
|
|
|
|| _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100) > 0;
|
|
|
|
}
|
|
|
|
|
2015-01-17 17:15:19 +00:00
|
|
|
void
|
2016-12-19 17:46:24 +00:00
|
|
|
gtk_css_style_render_border (GtkCssStyle *style,
|
|
|
|
cairo_t *cr,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
2015-01-17 17:15:19 +00:00
|
|
|
{
|
|
|
|
GtkBorderImage border_image;
|
|
|
|
double border_width[4];
|
|
|
|
|
|
|
|
border_width[0] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100);
|
|
|
|
border_width[1] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100);
|
|
|
|
border_width[2] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100);
|
|
|
|
border_width[3] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100);
|
|
|
|
|
|
|
|
if (gtk_border_image_init (&border_image, style))
|
|
|
|
{
|
|
|
|
gtk_border_image_render (&border_image, border_width, cr, x, y, width, height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkBorderStyle border_style[4];
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect border_box;
|
2015-01-17 17:15:19 +00:00
|
|
|
GdkRGBA colors[4];
|
|
|
|
|
|
|
|
/* Optimize the most common case of "This widget has no border" */
|
|
|
|
if (border_width[0] == 0 &&
|
|
|
|
border_width[1] == 0 &&
|
|
|
|
border_width[2] == 0 &&
|
|
|
|
border_width[3] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
border_style[0] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
|
|
|
|
border_style[1] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
|
|
|
|
border_style[2] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
|
|
|
|
border_style[3] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
|
|
|
|
|
|
|
|
colors[0] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_COLOR));
|
|
|
|
colors[1] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR));
|
|
|
|
colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR));
|
|
|
|
colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_COLOR));
|
|
|
|
|
2016-12-19 18:19:15 +00:00
|
|
|
gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, x, y, width, height);
|
2015-01-17 17:15:19 +00:00
|
|
|
|
2016-12-18 16:52:47 +00:00
|
|
|
render_border (cr, &border_box, border_width, colors, border_style);
|
2015-01-17 17:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2016-12-19 17:46:24 +00:00
|
|
|
gtk_css_style_snapshot_border (GtkCssStyle *style,
|
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
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
|
|
|
graphene_rect_t bounds;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
border_width[0] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100);
|
|
|
|
border_width[1] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100);
|
|
|
|
border_width[2] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100);
|
|
|
|
border_width[3] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100);
|
|
|
|
|
|
|
|
graphene_rect_init (&bounds, 0, 0, width, height);
|
|
|
|
|
|
|
|
if (gtk_border_image_init (&border_image, 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] };
|
|
|
|
|
2017-01-13 03:46:09 +00:00
|
|
|
cr = gtk_snapshot_append_cairo (snapshot,
|
|
|
|
&bounds,
|
|
|
|
"Border Image");
|
2016-12-18 17:14:53 +00:00
|
|
|
gtk_border_image_render (&border_image, double_width, cr, 0, 0, width, height);
|
2016-11-13 15:16:39 +00:00
|
|
|
cairo_destroy (cr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkBorderStyle border_style[4];
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect border_box;
|
2016-11-13 15:16:39 +00:00
|
|
|
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" */
|
|
|
|
if (border_width[0] == 0 &&
|
|
|
|
border_width[1] == 0 &&
|
|
|
|
border_width[2] == 0 &&
|
|
|
|
border_width[3] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
colors[0] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_COLOR));
|
|
|
|
colors[1] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR));
|
|
|
|
colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR));
|
|
|
|
colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_COLOR));
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
border_style[0] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
|
|
|
|
border_style[1] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
|
|
|
|
border_style[2] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
|
|
|
|
border_style[3] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
|
|
|
|
|
2016-12-19 18:19:15 +00:00
|
|
|
gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, 0, 0, width, height);
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2016-12-18 17:14:53 +00:00
|
|
|
snapshot_border (snapshot, &border_box, border_width, colors, border_style);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 00:01:41 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_style_render_border_get_clip (GtkCssStyle *style,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height,
|
|
|
|
GdkRectangle *out_clip)
|
|
|
|
{
|
|
|
|
if (!gtk_css_style_render_has_border (style))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
out_clip->x = floor (x);
|
|
|
|
out_clip->y = floor (y);
|
|
|
|
out_clip->width = ceil (x + width) - out_clip->x;
|
|
|
|
out_clip->height = ceil (y + height) - out_clip->y;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_css_style_render_has_outline (GtkCssStyle *style)
|
|
|
|
{
|
|
|
|
return _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
compute_outline_rect (GtkCssStyle *style,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height,
|
|
|
|
cairo_rectangle_t *out_rect)
|
|
|
|
{
|
|
|
|
double offset, owidth;
|
|
|
|
|
|
|
|
owidth = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100);
|
|
|
|
offset = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_OFFSET), 100);
|
|
|
|
|
|
|
|
if (width <= -2 * offset)
|
|
|
|
{
|
|
|
|
x += width / 2;
|
|
|
|
out_rect->x = x - owidth;
|
|
|
|
out_rect->width = 2 * owidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out_rect->x = x - offset - owidth;
|
|
|
|
out_rect->width = width + 2 * (offset + owidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height <= -2 * offset)
|
|
|
|
{
|
|
|
|
y += height / 2;
|
|
|
|
out_rect->y = y - owidth;
|
|
|
|
out_rect->height = 2 * owidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out_rect->y = y - offset - owidth;
|
|
|
|
out_rect->height = height + 2 * (offset + owidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-17 17:15:19 +00:00
|
|
|
void
|
|
|
|
gtk_css_style_render_outline (GtkCssStyle *style,
|
|
|
|
cairo_t *cr,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
|
|
|
GtkBorderStyle border_style[4];
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect border_box;
|
2015-01-17 17:15:19 +00:00
|
|
|
double border_width[4];
|
|
|
|
GdkRGBA colors[4];
|
|
|
|
|
|
|
|
border_style[0] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_STYLE));
|
|
|
|
if (border_style[0] != GTK_BORDER_STYLE_NONE)
|
|
|
|
{
|
2016-02-21 00:01:41 +00:00
|
|
|
cairo_rectangle_t rect;
|
|
|
|
|
|
|
|
compute_outline_rect (style, x, y, width, height, &rect);
|
2015-01-17 17:15:19 +00:00
|
|
|
|
|
|
|
border_style[1] = border_style[2] = border_style[3] = border_style[0];
|
|
|
|
border_width[0] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100);
|
|
|
|
border_width[3] = border_width[2] = border_width[1] = border_width[0];
|
|
|
|
colors[0] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_COLOR));
|
|
|
|
colors[3] = colors[2] = colors[1] = colors[0];
|
|
|
|
|
2016-02-21 00:01:41 +00:00
|
|
|
_gtk_rounded_box_init_rect (&border_box, rect.x, rect.y, rect.width, rect.height);
|
2016-12-19 17:46:24 +00:00
|
|
|
_gtk_rounded_box_apply_outline_radius_for_style (&border_box, style);
|
2015-01-17 17:15:19 +00:00
|
|
|
|
2016-12-18 16:52:47 +00:00
|
|
|
render_border (cr, &border_box, border_width, colors, border_style);
|
2015-01-17 17:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
|
|
|
gtk_css_style_snapshot_outline (GtkCssStyle *style,
|
2016-12-18 17:14:53 +00:00
|
|
|
GtkSnapshot *snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
|
|
|
GtkBorderStyle border_style[4];
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect border_box;
|
2016-12-18 17:14:53 +00:00
|
|
|
float border_width[4];
|
2016-11-13 15:16:39 +00:00
|
|
|
GdkRGBA colors[4];
|
|
|
|
|
|
|
|
border_style[0] = _gtk_css_border_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_STYLE));
|
|
|
|
if (border_style[0] != GTK_BORDER_STYLE_NONE)
|
|
|
|
{
|
|
|
|
cairo_rectangle_t rect;
|
|
|
|
|
|
|
|
compute_outline_rect (style, 0, 0, width, height, &rect);
|
|
|
|
|
|
|
|
border_style[1] = border_style[2] = border_style[3] = border_style[0];
|
|
|
|
border_width[0] = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100);
|
|
|
|
border_width[3] = border_width[2] = border_width[1] = border_width[0];
|
|
|
|
colors[0] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_OUTLINE_COLOR));
|
|
|
|
colors[3] = colors[2] = colors[1] = colors[0];
|
|
|
|
|
|
|
|
_gtk_rounded_box_init_rect (&border_box, rect.x, rect.y, rect.width, rect.height);
|
2016-12-19 17:46:24 +00:00
|
|
|
_gtk_rounded_box_apply_outline_radius_for_style (&border_box, style);
|
2016-11-13 15:16:39 +00:00
|
|
|
|
2016-12-18 17:14:53 +00:00
|
|
|
snapshot_border (snapshot, &border_box, border_width, colors, border_style);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 00:01:41 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_style_render_outline_get_clip (GtkCssStyle *style,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height,
|
|
|
|
GdkRectangle *out_clip)
|
|
|
|
{
|
|
|
|
cairo_rectangle_t rect;
|
|
|
|
|
|
|
|
if (!gtk_css_style_render_has_outline (style))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
compute_outline_rect (style, x, y, width, height, &rect);
|
|
|
|
|
|
|
|
out_clip->x = floor (rect.x);
|
|
|
|
out_clip->y = floor (rect.y);
|
|
|
|
out_clip->width = ceil (rect.x + rect.width) - out_clip->x;
|
|
|
|
out_clip->height = ceil (rect.y + rect.height) - out_clip->y;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|