2011-05-19 18:47:17 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Author: 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-19 18:47:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-28 01:34:19 +00:00
|
|
|
#include "gtkcssshadowvalueprivate.h"
|
2012-01-02 14:44:45 +00:00
|
|
|
|
2012-04-17 19:43:58 +00:00
|
|
|
#include "gtkcairoblurprivate.h"
|
2012-11-08 16:33:53 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2012-04-03 11:29:29 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2012-04-03 10:07:53 +00:00
|
|
|
#include "gtkcssrgbavalueprivate.h"
|
2012-01-02 14:44:45 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2014-06-16 02:18:51 +00:00
|
|
|
#include "gtkrenderprivate.h"
|
2011-05-20 20:05:57 +00:00
|
|
|
#include "gtkpango.h"
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2013-05-03 10:50:18 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
struct _GtkCssValue {
|
|
|
|
GTK_CSS_VALUE_BASE
|
|
|
|
guint inset :1;
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
GtkCssValue *hoffset;
|
|
|
|
GtkCssValue *voffset;
|
|
|
|
GtkCssValue *radius;
|
|
|
|
GtkCssValue *spread;
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-04-03 10:07:53 +00:00
|
|
|
GtkCssValue *color;
|
2011-05-19 18:47:17 +00:00
|
|
|
};
|
|
|
|
|
2012-04-03 13:33:00 +00:00
|
|
|
static GtkCssValue * gtk_css_shadow_value_new (GtkCssValue *hoffset,
|
|
|
|
GtkCssValue *voffset,
|
|
|
|
GtkCssValue *radius,
|
|
|
|
GtkCssValue *spread,
|
|
|
|
gboolean inset,
|
|
|
|
GtkCssValue *color);
|
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static void
|
|
|
|
gtk_css_value_shadow_free (GtkCssValue *shadow)
|
2011-05-19 18:47:17 +00:00
|
|
|
{
|
2012-04-03 11:29:29 +00:00
|
|
|
_gtk_css_value_unref (shadow->hoffset);
|
|
|
|
_gtk_css_value_unref (shadow->voffset);
|
|
|
|
_gtk_css_value_unref (shadow->radius);
|
|
|
|
_gtk_css_value_unref (shadow->spread);
|
2012-04-03 10:07:53 +00:00
|
|
|
_gtk_css_value_unref (shadow->color);
|
2012-04-03 09:49:46 +00:00
|
|
|
|
2012-03-28 01:31:20 +00:00
|
|
|
g_slice_free (GtkCssValue, shadow);
|
2012-03-27 23:56:57 +00:00
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-07-11 04:56:07 +00:00
|
|
|
static GtkCssValue *
|
2012-09-28 16:02:46 +00:00
|
|
|
gtk_css_value_shadow_compute (GtkCssValue *shadow,
|
|
|
|
guint property_id,
|
|
|
|
GtkStyleProviderPrivate *provider,
|
2015-01-31 10:56:15 +00:00
|
|
|
GtkCssStyle *style,
|
2015-02-14 01:27:39 +00:00
|
|
|
GtkCssStyle *parent_style)
|
2012-07-11 04:56:07 +00:00
|
|
|
{
|
2012-08-25 15:22:14 +00:00
|
|
|
GtkCssValue *hoffset, *voffset, *radius, *spread, *color;
|
|
|
|
|
2015-02-14 01:27:39 +00:00
|
|
|
hoffset = _gtk_css_value_compute (shadow->hoffset, property_id, provider, style, parent_style);
|
|
|
|
voffset = _gtk_css_value_compute (shadow->voffset, property_id, provider, style, parent_style);
|
|
|
|
radius = _gtk_css_value_compute (shadow->radius, property_id, provider, style, parent_style);
|
|
|
|
spread = _gtk_css_value_compute (shadow->spread, property_id, provider, style, parent_style),
|
|
|
|
color = _gtk_css_value_compute (shadow->color, property_id, provider, style, parent_style);
|
2012-08-25 15:22:14 +00:00
|
|
|
|
|
|
|
return gtk_css_shadow_value_new (hoffset, voffset, radius, spread, shadow->inset, color);
|
2012-07-11 04:56:07 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
|
|
|
|
const GtkCssValue *shadow2)
|
|
|
|
{
|
2012-04-03 13:33:00 +00:00
|
|
|
return shadow1->inset == shadow2->inset
|
|
|
|
&& _gtk_css_value_equal (shadow1->hoffset, shadow2->hoffset)
|
|
|
|
&& _gtk_css_value_equal (shadow1->voffset, shadow2->voffset)
|
|
|
|
&& _gtk_css_value_equal (shadow1->radius, shadow2->radius)
|
|
|
|
&& _gtk_css_value_equal (shadow1->spread, shadow2->spread)
|
|
|
|
&& _gtk_css_value_equal (shadow1->color, shadow2->color);
|
2011-05-19 18:47:17 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 15:47:26 +00:00
|
|
|
static GtkCssValue *
|
|
|
|
gtk_css_value_shadow_transition (GtkCssValue *start,
|
|
|
|
GtkCssValue *end,
|
2012-08-30 13:51:29 +00:00
|
|
|
guint property_id,
|
2012-03-30 15:47:26 +00:00
|
|
|
double progress)
|
|
|
|
{
|
2012-04-03 13:33:00 +00:00
|
|
|
if (start->inset != end->inset)
|
|
|
|
return NULL;
|
|
|
|
|
2012-08-30 13:51:29 +00:00
|
|
|
return gtk_css_shadow_value_new (_gtk_css_value_transition (start->hoffset, end->hoffset, property_id, progress),
|
|
|
|
_gtk_css_value_transition (start->voffset, end->voffset, property_id, progress),
|
|
|
|
_gtk_css_value_transition (start->radius, end->radius, property_id, progress),
|
|
|
|
_gtk_css_value_transition (start->spread, end->spread, property_id, progress),
|
2012-04-03 13:33:00 +00:00
|
|
|
start->inset,
|
2012-08-30 13:51:29 +00:00
|
|
|
_gtk_css_value_transition (start->color, end->color, property_id, progress));
|
2012-03-30 15:47:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static void
|
|
|
|
gtk_css_value_shadow_print (const GtkCssValue *shadow,
|
|
|
|
GString *string)
|
2011-05-19 18:47:17 +00:00
|
|
|
{
|
2012-04-03 11:29:29 +00:00
|
|
|
_gtk_css_value_print (shadow->hoffset, string);
|
|
|
|
g_string_append_c (string, ' ');
|
|
|
|
_gtk_css_value_print (shadow->voffset, string);
|
|
|
|
g_string_append_c (string, ' ');
|
|
|
|
if (_gtk_css_number_value_get (shadow->radius, 100) != 0 ||
|
|
|
|
_gtk_css_number_value_get (shadow->spread, 100) != 0)
|
|
|
|
{
|
|
|
|
_gtk_css_value_print (shadow->radius, string);
|
|
|
|
g_string_append_c (string, ' ');
|
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
if (_gtk_css_number_value_get (shadow->spread, 100) != 0)
|
|
|
|
{
|
|
|
|
_gtk_css_value_print (shadow->spread, string);
|
|
|
|
g_string_append_c (string, ' ');
|
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
_gtk_css_value_print (shadow->color, string);
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
if (shadow->inset)
|
|
|
|
g_string_append (string, " inset");
|
2011-05-19 18:47:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
|
|
|
|
gtk_css_value_shadow_free,
|
2012-07-11 04:56:07 +00:00
|
|
|
gtk_css_value_shadow_compute,
|
2012-03-27 23:56:57 +00:00
|
|
|
gtk_css_value_shadow_equal,
|
2012-03-30 15:47:26 +00:00
|
|
|
gtk_css_value_shadow_transition,
|
2012-03-27 23:56:57 +00:00
|
|
|
gtk_css_value_shadow_print
|
|
|
|
};
|
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
static GtkCssValue *
|
2012-04-03 11:29:29 +00:00
|
|
|
gtk_css_shadow_value_new (GtkCssValue *hoffset,
|
|
|
|
GtkCssValue *voffset,
|
|
|
|
GtkCssValue *radius,
|
|
|
|
GtkCssValue *spread,
|
|
|
|
gboolean inset,
|
2012-04-03 10:07:53 +00:00
|
|
|
GtkCssValue *color)
|
2012-03-27 23:56:57 +00:00
|
|
|
{
|
2012-04-03 09:49:46 +00:00
|
|
|
GtkCssValue *retval;
|
|
|
|
|
|
|
|
retval = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_SHADOW);
|
|
|
|
|
|
|
|
retval->hoffset = hoffset;
|
|
|
|
retval->voffset = voffset;
|
|
|
|
retval->radius = radius;
|
|
|
|
retval->spread = spread;
|
|
|
|
retval->inset = inset;
|
2012-04-03 10:07:53 +00:00
|
|
|
retval->color = color;
|
2012-04-03 09:49:46 +00:00
|
|
|
|
|
|
|
return retval;
|
2014-08-29 19:54:01 +00:00
|
|
|
}
|
2012-03-27 23:56:57 +00:00
|
|
|
|
2012-04-03 13:33:00 +00:00
|
|
|
GtkCssValue *
|
|
|
|
_gtk_css_shadow_value_new_for_transition (GtkCssValue *target)
|
|
|
|
{
|
|
|
|
GdkRGBA transparent = { 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
g_return_val_if_fail (target->class == >K_CSS_VALUE_SHADOW, NULL);
|
|
|
|
|
|
|
|
return gtk_css_shadow_value_new (_gtk_css_number_value_new (0, GTK_CSS_PX),
|
|
|
|
_gtk_css_number_value_new (0, GTK_CSS_PX),
|
|
|
|
_gtk_css_number_value_new (0, GTK_CSS_PX),
|
|
|
|
_gtk_css_number_value_new (0, GTK_CSS_PX),
|
|
|
|
target->inset,
|
|
|
|
_gtk_css_rgba_value_new_from_rgba (&transparent));
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
static gboolean
|
|
|
|
value_is_done_parsing (GtkCssParser *parser)
|
|
|
|
{
|
|
|
|
return _gtk_css_parser_is_eof (parser) ||
|
|
|
|
_gtk_css_parser_begins_with (parser, ',') ||
|
|
|
|
_gtk_css_parser_begins_with (parser, ';') ||
|
|
|
|
_gtk_css_parser_begins_with (parser, '}');
|
|
|
|
}
|
|
|
|
|
2012-03-28 01:31:20 +00:00
|
|
|
GtkCssValue *
|
2014-06-09 23:04:55 +00:00
|
|
|
_gtk_css_shadow_value_parse (GtkCssParser *parser,
|
|
|
|
gboolean box_shadow_mode)
|
2011-05-19 18:47:17 +00:00
|
|
|
{
|
2012-04-03 11:29:29 +00:00
|
|
|
enum {
|
|
|
|
HOFFSET,
|
|
|
|
VOFFSET,
|
|
|
|
RADIUS,
|
|
|
|
SPREAD,
|
|
|
|
COLOR,
|
|
|
|
N_VALUES
|
|
|
|
};
|
|
|
|
GtkCssValue *values[N_VALUES] = { NULL, };
|
|
|
|
gboolean inset;
|
2012-03-28 00:25:22 +00:00
|
|
|
guint i;
|
|
|
|
|
2014-06-09 23:04:55 +00:00
|
|
|
if (box_shadow_mode)
|
|
|
|
inset = _gtk_css_parser_try (parser, "inset", TRUE);
|
2014-06-10 13:57:57 +00:00
|
|
|
else
|
|
|
|
inset = FALSE;
|
2012-04-03 11:29:29 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (values[HOFFSET] == NULL &&
|
|
|
|
_gtk_css_parser_has_number (parser))
|
|
|
|
{
|
|
|
|
values[HOFFSET] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS);
|
|
|
|
if (values[HOFFSET] == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
values[VOFFSET] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS);
|
|
|
|
if (values[VOFFSET] == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (_gtk_css_parser_has_number (parser))
|
|
|
|
{
|
|
|
|
values[RADIUS] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH
|
|
|
|
| GTK_CSS_POSITIVE_ONLY
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS);
|
|
|
|
if (values[RADIUS] == NULL)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
values[RADIUS] = _gtk_css_number_value_new (0.0, GTK_CSS_PX);
|
2014-08-29 19:54:01 +00:00
|
|
|
|
2014-06-09 23:04:55 +00:00
|
|
|
if (box_shadow_mode && _gtk_css_parser_has_number (parser))
|
2012-04-03 11:29:29 +00:00
|
|
|
{
|
|
|
|
values[SPREAD] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH
|
|
|
|
| GTK_CSS_NUMBER_AS_PIXELS);
|
|
|
|
if (values[SPREAD] == NULL)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
values[SPREAD] = _gtk_css_number_value_new (0.0, GTK_CSS_PX);
|
|
|
|
}
|
2014-06-09 23:04:55 +00:00
|
|
|
else if (!inset && box_shadow_mode && _gtk_css_parser_try (parser, "inset", TRUE))
|
2012-04-03 11:29:29 +00:00
|
|
|
{
|
|
|
|
if (values[HOFFSET] == NULL)
|
|
|
|
goto fail;
|
|
|
|
inset = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (values[COLOR] == NULL)
|
|
|
|
{
|
2012-11-08 16:33:53 +00:00
|
|
|
values[COLOR] = _gtk_css_color_value_parse (parser);
|
2012-04-03 11:29:29 +00:00
|
|
|
|
2012-04-07 04:18:03 +00:00
|
|
|
if (values[COLOR] == NULL)
|
2012-04-03 11:29:29 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We parsed everything and there's still stuff left?
|
|
|
|
* Pretend we didn't notice and let the normal code produce
|
|
|
|
* a 'junk at end of value' error */
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (values[HOFFSET] == NULL || !value_is_done_parsing (parser));
|
|
|
|
|
|
|
|
if (values[COLOR] == NULL)
|
2012-11-08 16:33:53 +00:00
|
|
|
values[COLOR] = _gtk_css_color_value_new_current_color ();
|
2012-04-03 11:29:29 +00:00
|
|
|
|
|
|
|
return gtk_css_shadow_value_new (values[HOFFSET], values[VOFFSET],
|
|
|
|
values[RADIUS], values[SPREAD],
|
|
|
|
inset, values[COLOR]);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
for (i = 0; i < N_VALUES; i++)
|
2012-03-28 00:25:22 +00:00
|
|
|
{
|
2012-04-03 11:29:29 +00:00
|
|
|
if (values[i])
|
|
|
|
_gtk_css_value_unref (values[i]);
|
2012-04-03 09:49:46 +00:00
|
|
|
}
|
2012-03-28 00:25:22 +00:00
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
return NULL;
|
2011-05-19 18:47:17 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 21:48:29 +00:00
|
|
|
static gboolean
|
|
|
|
needs_blur (const GtkCssValue *shadow)
|
|
|
|
{
|
|
|
|
double radius = _gtk_css_number_value_get (shadow->radius, 0);
|
2015-03-20 13:31:57 +00:00
|
|
|
|
|
|
|
/* The code doesn't actually do any blurring for radius 1, as it
|
|
|
|
* ends up with box filter size 1 */
|
|
|
|
if (radius <= 1.0)
|
2014-08-29 21:48:29 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-08-30 00:33:27 +00:00
|
|
|
static const cairo_user_data_key_t original_cr_key;
|
2012-04-17 19:43:58 +00:00
|
|
|
|
|
|
|
static cairo_t *
|
|
|
|
gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
|
2015-03-20 13:34:44 +00:00
|
|
|
cairo_t *cr,
|
|
|
|
GtkBlurFlags blur_flags)
|
2012-04-17 19:43:58 +00:00
|
|
|
{
|
2012-09-21 16:51:46 +00:00
|
|
|
cairo_rectangle_int_t clip_rect;
|
2012-04-17 19:43:58 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *blur_cr;
|
2013-05-06 14:05:08 +00:00
|
|
|
gdouble radius, clip_radius;
|
2015-03-20 13:34:44 +00:00
|
|
|
gboolean blur_x = (blur_flags & GTK_BLUR_X) != 0;
|
|
|
|
gboolean blur_y = (blur_flags & GTK_BLUR_Y) != 0;
|
2012-04-17 19:43:58 +00:00
|
|
|
|
2014-08-29 21:48:29 +00:00
|
|
|
if (!needs_blur (shadow))
|
2012-04-17 19:43:58 +00:00
|
|
|
return cr;
|
|
|
|
|
2012-09-21 16:51:46 +00:00
|
|
|
gdk_cairo_get_clip_rectangle (cr, &clip_rect);
|
2012-04-17 19:43:58 +00:00
|
|
|
|
2014-08-29 21:48:29 +00:00
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
2014-02-03 14:56:59 +00:00
|
|
|
clip_radius = _gtk_cairo_blur_compute_pixels (radius);
|
2013-05-06 14:05:08 +00:00
|
|
|
|
2015-03-20 13:56:42 +00:00
|
|
|
if (blur_flags & GTK_BLUR_REPEAT)
|
|
|
|
{
|
|
|
|
if (!blur_x)
|
|
|
|
clip_rect.width = 1;
|
|
|
|
if (!blur_y)
|
|
|
|
clip_rect.height = 1;
|
|
|
|
}
|
|
|
|
|
2012-04-17 19:43:58 +00:00
|
|
|
/* Create a larger surface to center the blur. */
|
2014-09-02 18:21:02 +00:00
|
|
|
surface = cairo_surface_create_similar_image (cairo_get_target (cr),
|
|
|
|
CAIRO_FORMAT_A8,
|
2015-03-20 13:34:44 +00:00
|
|
|
clip_rect.width + (blur_x ? 2 * clip_radius : 0),
|
|
|
|
clip_rect.height + (blur_y ? 2 * clip_radius : 0));
|
|
|
|
cairo_surface_set_device_offset (surface,
|
|
|
|
(blur_x ? clip_radius : 0) - clip_rect.x,
|
|
|
|
(blur_y ? clip_radius : 0) - clip_rect.y);
|
2012-04-17 19:43:58 +00:00
|
|
|
blur_cr = cairo_create (surface);
|
2014-08-30 00:33:27 +00:00
|
|
|
cairo_set_user_data (blur_cr, &original_cr_key, cairo_reference (cr), (cairo_destroy_func_t) cairo_destroy);
|
2012-04-17 19:43:58 +00:00
|
|
|
|
|
|
|
if (cairo_has_current_point (cr))
|
|
|
|
{
|
|
|
|
double x, y;
|
2014-08-29 19:54:01 +00:00
|
|
|
|
2012-04-17 19:43:58 +00:00
|
|
|
cairo_get_current_point (cr, &x, &y);
|
|
|
|
cairo_move_to (blur_cr, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return blur_cr;
|
|
|
|
}
|
|
|
|
|
2015-03-20 13:56:42 +00:00
|
|
|
void
|
|
|
|
mask_surface_repeat (cairo_t *cr,
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
{
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
|
|
|
|
|
|
|
cairo_mask (cr, pattern);
|
|
|
|
|
|
|
|
cairo_pattern_destroy (pattern);
|
|
|
|
}
|
|
|
|
|
2012-04-17 19:43:58 +00:00
|
|
|
static cairo_t *
|
|
|
|
gtk_css_shadow_value_finish_drawing (const GtkCssValue *shadow,
|
2015-03-20 13:34:44 +00:00
|
|
|
cairo_t *cr,
|
|
|
|
GtkBlurFlags blur_flags)
|
2012-04-17 19:43:58 +00:00
|
|
|
{
|
|
|
|
gdouble radius;
|
2012-09-21 16:51:46 +00:00
|
|
|
cairo_t *original_cr;
|
|
|
|
cairo_surface_t *surface;
|
2012-04-17 19:43:58 +00:00
|
|
|
|
2014-08-29 21:48:29 +00:00
|
|
|
if (!needs_blur (shadow))
|
2012-04-17 19:43:58 +00:00
|
|
|
return cr;
|
|
|
|
|
2014-08-30 00:33:27 +00:00
|
|
|
original_cr = cairo_get_user_data (cr, &original_cr_key);
|
2012-04-17 19:43:58 +00:00
|
|
|
|
|
|
|
/* Blur the surface. */
|
2014-08-29 21:48:29 +00:00
|
|
|
surface = cairo_get_target (cr);
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
2015-03-20 13:34:44 +00:00
|
|
|
_gtk_cairo_blur_surface (surface, radius, blur_flags);
|
2012-09-21 16:51:46 +00:00
|
|
|
|
2014-07-28 20:04:09 +00:00
|
|
|
gdk_cairo_set_source_rgba (original_cr, _gtk_css_rgba_value_get_rgba (shadow->color));
|
2015-03-20 13:56:42 +00:00
|
|
|
if (blur_flags & GTK_BLUR_REPEAT)
|
|
|
|
mask_surface_repeat (original_cr, surface);
|
|
|
|
else
|
|
|
|
cairo_mask_surface (original_cr, surface, 0, 0);
|
2012-04-17 19:43:58 +00:00
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2015-03-20 13:34:44 +00:00
|
|
|
|
2012-10-16 15:54:33 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2012-04-17 19:43:58 +00:00
|
|
|
|
|
|
|
return original_cr;
|
|
|
|
}
|
|
|
|
|
2014-08-29 20:51:30 +00:00
|
|
|
static const cairo_user_data_key_t radius_key;
|
|
|
|
static const cairo_user_data_key_t layout_serial_key;
|
|
|
|
|
|
|
|
G_DEFINE_QUARK (GtkCssShadowValue pango_cached_blurred_surface, pango_cached_blurred_surface)
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
get_cached_pango_surface (PangoLayout *layout,
|
|
|
|
const GtkCssValue *shadow)
|
|
|
|
{
|
|
|
|
cairo_surface_t *cached_surface = g_object_get_qdata (G_OBJECT (layout), pango_cached_blurred_surface_quark ());
|
|
|
|
guint cached_radius, cached_serial;
|
|
|
|
guint radius, serial;
|
|
|
|
|
|
|
|
if (!cached_surface)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
|
|
|
cached_radius = GPOINTER_TO_UINT (cairo_surface_get_user_data (cached_surface, &radius_key));
|
|
|
|
if (radius != cached_radius)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
serial = pango_layout_get_serial (layout);
|
|
|
|
cached_serial = GPOINTER_TO_UINT (cairo_surface_get_user_data (cached_surface, &layout_serial_key));
|
|
|
|
if (serial != cached_serial)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return cached_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
make_blurred_pango_surface (cairo_t *existing_cr,
|
|
|
|
PangoLayout *layout,
|
|
|
|
const GtkCssValue *shadow)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
gdouble radius, clip_radius;
|
2014-10-09 23:02:34 +00:00
|
|
|
gdouble x_scale, y_scale;
|
2014-08-29 20:51:30 +00:00
|
|
|
PangoRectangle ink_rect;
|
|
|
|
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
|
|
|
|
|
|
|
pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
|
|
|
|
clip_radius = _gtk_cairo_blur_compute_pixels (radius);
|
2014-10-09 23:02:34 +00:00
|
|
|
x_scale = y_scale = 1;
|
2014-10-25 19:23:16 +00:00
|
|
|
cairo_surface_get_device_scale (cairo_get_target (existing_cr), &x_scale, &y_scale);
|
2014-08-29 20:51:30 +00:00
|
|
|
|
|
|
|
surface = cairo_surface_create_similar_image (cairo_get_target (existing_cr),
|
|
|
|
CAIRO_FORMAT_A8,
|
2014-10-09 23:02:34 +00:00
|
|
|
x_scale * (ink_rect.width + 2 * clip_radius),
|
|
|
|
y_scale * (ink_rect.height + 2 * clip_radius));
|
|
|
|
cairo_surface_set_device_scale (surface, x_scale, y_scale);
|
2014-08-29 20:51:30 +00:00
|
|
|
cairo_surface_set_device_offset (surface, -ink_rect.x + clip_radius, -ink_rect.y + clip_radius);
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
_gtk_pango_fill_layout (cr, layout);
|
2015-03-20 13:34:44 +00:00
|
|
|
_gtk_cairo_blur_surface (surface, radius * x_scale, GTK_BLUR_X | GTK_BLUR_Y);
|
2014-08-29 20:51:30 +00:00
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
get_blurred_pango_surface (cairo_t *cr,
|
|
|
|
PangoLayout *layout,
|
|
|
|
const GtkCssValue *shadow)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
guint radius, serial;
|
|
|
|
|
|
|
|
surface = get_cached_pango_surface (layout, shadow);
|
|
|
|
if (!surface)
|
|
|
|
{
|
|
|
|
surface = make_blurred_pango_surface (cr, layout, shadow);
|
|
|
|
|
|
|
|
/* Cache the surface on the PangoLayout */
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
|
|
|
cairo_surface_set_user_data (surface, &radius_key, GUINT_TO_POINTER (radius), NULL);
|
|
|
|
|
|
|
|
serial = pango_layout_get_serial (layout);
|
|
|
|
cairo_surface_set_user_data (surface, &layout_serial_key, GUINT_TO_POINTER (serial), NULL);
|
|
|
|
|
|
|
|
g_object_set_qdata_full (G_OBJECT (layout), pango_cached_blurred_surface_quark (),
|
|
|
|
surface, (GDestroyNotify) cairo_surface_destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2011-05-20 20:05:57 +00:00
|
|
|
void
|
2012-03-28 01:31:20 +00:00
|
|
|
_gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
|
|
|
|
cairo_t *cr,
|
|
|
|
PangoLayout *layout)
|
2011-05-20 20:05:57 +00:00
|
|
|
{
|
2012-04-03 09:49:46 +00:00
|
|
|
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
|
2011-05-20 20:05:57 +00:00
|
|
|
|
2011-05-22 02:24:23 +00:00
|
|
|
if (!cairo_has_current_point (cr))
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
cairo_save (cr);
|
2011-05-20 20:05:57 +00:00
|
|
|
|
2014-08-29 20:51:30 +00:00
|
|
|
if (needs_blur (shadow))
|
|
|
|
{
|
|
|
|
cairo_surface_t *blurred_surface = get_blurred_pango_surface (cr, layout, shadow);
|
|
|
|
double x, y;
|
|
|
|
cairo_get_current_point (cr, &x, &y);
|
|
|
|
cairo_translate (cr, x, y);
|
|
|
|
cairo_translate (cr,
|
|
|
|
_gtk_css_number_value_get (shadow->hoffset, 0),
|
|
|
|
_gtk_css_number_value_get (shadow->voffset, 0));
|
2011-05-20 20:05:57 +00:00
|
|
|
|
2014-08-29 20:51:30 +00:00
|
|
|
gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
|
|
|
|
cairo_mask_surface (cr, blurred_surface, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The no blur case -- just paint directly. */
|
|
|
|
cairo_rel_move_to (cr,
|
|
|
|
_gtk_css_number_value_get (shadow->hoffset, 0),
|
|
|
|
_gtk_css_number_value_get (shadow->voffset, 0));
|
|
|
|
gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
|
|
|
|
_gtk_pango_fill_layout (cr, layout);
|
|
|
|
cairo_rel_move_to (cr,
|
|
|
|
- _gtk_css_number_value_get (shadow->hoffset, 0),
|
|
|
|
- _gtk_css_number_value_get (shadow->voffset, 0));
|
|
|
|
}
|
2012-04-17 20:14:39 +00:00
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
cairo_restore (cr);
|
2011-05-20 20:05:57 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 03:51:16 +00:00
|
|
|
void
|
2012-03-28 01:31:20 +00:00
|
|
|
_gtk_css_shadow_value_paint_icon (const GtkCssValue *shadow,
|
|
|
|
cairo_t *cr)
|
2011-05-21 03:51:16 +00:00
|
|
|
{
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
|
2011-05-21 03:51:16 +00:00
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
cairo_save (cr);
|
|
|
|
pattern = cairo_pattern_reference (cairo_get_source (cr));
|
2012-04-16 12:02:59 +00:00
|
|
|
|
2012-04-03 10:07:53 +00:00
|
|
|
gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
|
2015-03-20 13:34:44 +00:00
|
|
|
cr = gtk_css_shadow_value_start_drawing (shadow, cr, GTK_BLUR_X | GTK_BLUR_Y);
|
2011-05-21 03:51:16 +00:00
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
cairo_translate (cr,
|
|
|
|
_gtk_css_number_value_get (shadow->hoffset, 0),
|
|
|
|
_gtk_css_number_value_get (shadow->voffset, 0));
|
2012-04-03 09:49:46 +00:00
|
|
|
cairo_mask (cr, pattern);
|
2011-05-21 03:51:16 +00:00
|
|
|
|
2015-03-20 13:34:44 +00:00
|
|
|
cr = gtk_css_shadow_value_finish_drawing (shadow, cr, GTK_BLUR_X | GTK_BLUR_Y);
|
2012-04-16 12:02:59 +00:00
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
cairo_pattern_destroy (pattern);
|
2011-05-21 03:51:16 +00:00
|
|
|
}
|
2011-06-06 15:38:45 +00:00
|
|
|
|
2013-04-05 09:54:03 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_css_shadow_value_get_inset (const GtkCssValue *shadow)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (shadow->class == >K_CSS_VALUE_SHADOW, FALSE);
|
|
|
|
|
|
|
|
return shadow->inset;
|
|
|
|
}
|
|
|
|
|
2013-04-22 20:50:39 +00:00
|
|
|
void
|
|
|
|
_gtk_css_shadow_value_get_geometry (const GtkCssValue *shadow,
|
|
|
|
gdouble *hoffset,
|
|
|
|
gdouble *voffset,
|
|
|
|
gdouble *radius,
|
|
|
|
gdouble *spread)
|
|
|
|
{
|
|
|
|
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
|
|
|
|
|
|
|
|
if (hoffset != NULL)
|
|
|
|
*hoffset = _gtk_css_number_value_get (shadow->hoffset, 0);
|
|
|
|
if (voffset != NULL)
|
|
|
|
*voffset = _gtk_css_number_value_get (shadow->voffset, 0);
|
|
|
|
|
|
|
|
if (radius != NULL)
|
|
|
|
*radius = _gtk_css_number_value_get (shadow->radius, 0);
|
|
|
|
if (spread != NULL)
|
|
|
|
*spread = _gtk_css_number_value_get (shadow->spread, 0);
|
|
|
|
}
|
|
|
|
|
2013-05-06 10:34:09 +00:00
|
|
|
static gboolean
|
|
|
|
has_empty_clip (cairo_t *cr)
|
|
|
|
{
|
|
|
|
double x1, y1, x2, y2;
|
|
|
|
|
|
|
|
cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
|
|
|
|
return x1 == x2 && y1 == y2;
|
|
|
|
}
|
|
|
|
|
2013-05-06 07:48:10 +00:00
|
|
|
static void
|
|
|
|
draw_shadow (const GtkCssValue *shadow,
|
|
|
|
cairo_t *cr,
|
|
|
|
GtkRoundedBox *box,
|
2013-05-06 11:06:13 +00:00
|
|
|
GtkRoundedBox *clip_box,
|
2015-03-20 13:34:44 +00:00
|
|
|
GtkBlurFlags blur_flags)
|
2013-05-06 07:48:10 +00:00
|
|
|
{
|
|
|
|
cairo_t *shadow_cr;
|
2015-03-20 13:34:44 +00:00
|
|
|
gboolean do_blur;
|
2013-05-06 07:48:10 +00:00
|
|
|
|
2013-05-06 10:34:09 +00:00
|
|
|
if (has_empty_clip (cr))
|
|
|
|
return;
|
|
|
|
|
gtkcssshadowvalue: Don't double-apply the alpha to shadows
It turns out that when we were painting the shadows, we painted the them
with the base color once, which contained the alpha, and then blurred it
and used it as a mask for the fill, which has the fill again.
To fix this, always paint the base surface with full alpha. The existing
code applies the blur conditionally sometimes in weird ways, so the code
shuffling fix may not look correct, but be assured it is. If the blur
happens, the new cr we return has the *default* color applied, which is
fully opaque black, which works perfectly against the A8 surface.
The fallback spinner code needs some modification, since it is
intentionally using the alpha to paint the lobes which are "in the past".
Since we shouldn't be hitting this fallback path very often, we use a
temporary group and paint it with paint_with_alpha, even though it is
slow.
2014-07-31 16:27:46 +00:00
|
|
|
gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
|
2015-03-20 13:34:44 +00:00
|
|
|
do_blur = (blur_flags & (GTK_BLUR_X | GTK_BLUR_Y)) != 0;
|
|
|
|
if (do_blur)
|
|
|
|
shadow_cr = gtk_css_shadow_value_start_drawing (shadow, cr, blur_flags);
|
2013-05-06 11:06:13 +00:00
|
|
|
else
|
|
|
|
shadow_cr = cr;
|
2013-05-06 07:48:10 +00:00
|
|
|
|
|
|
|
cairo_set_fill_rule (shadow_cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
_gtk_rounded_box_path (box, shadow_cr);
|
|
|
|
if (shadow->inset)
|
|
|
|
_gtk_rounded_box_clip_path (clip_box, shadow_cr);
|
|
|
|
|
|
|
|
cairo_fill (shadow_cr);
|
|
|
|
|
2015-03-20 13:34:44 +00:00
|
|
|
if (do_blur)
|
|
|
|
gtk_css_shadow_value_finish_drawing (shadow, shadow_cr, blur_flags);
|
2013-05-06 07:48:10 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 09:46:57 +00:00
|
|
|
static void
|
|
|
|
draw_shadow_corner (const GtkCssValue *shadow,
|
|
|
|
cairo_t *cr,
|
|
|
|
GtkRoundedBox *box,
|
|
|
|
GtkRoundedBox *clip_box,
|
|
|
|
GtkCssCorner corner,
|
|
|
|
cairo_rectangle_int_t *drawn_rect)
|
|
|
|
{
|
|
|
|
gdouble radius, clip_radius;
|
|
|
|
int x1, x2, y1, y2;
|
|
|
|
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
|
|
|
clip_radius = _gtk_cairo_blur_compute_pixels (radius);
|
|
|
|
|
|
|
|
if (corner == GTK_CSS_TOP_LEFT || corner == GTK_CSS_BOTTOM_LEFT)
|
|
|
|
{
|
|
|
|
x1 = floor (box->box.x - clip_radius);
|
|
|
|
x2 = ceil (box->box.x + box->corner[corner].horizontal + clip_radius);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = floor (box->box.x + box->box.width - box->corner[corner].horizontal - clip_radius);
|
|
|
|
x2 = ceil (box->box.x + box->box.width + clip_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (corner == GTK_CSS_TOP_LEFT || corner == GTK_CSS_TOP_RIGHT)
|
|
|
|
{
|
|
|
|
y1 = floor (box->box.y - clip_radius);
|
|
|
|
y2 = ceil (box->box.y + box->corner[corner].vertical + clip_radius);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y1 = floor (box->box.y + box->box.height - box->corner[corner].vertical - clip_radius);
|
|
|
|
y2 = ceil (box->box.y + box->box.height + clip_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
drawn_rect->x = x1;
|
|
|
|
drawn_rect->y = y1;
|
|
|
|
drawn_rect->width = x2 - x1;
|
|
|
|
drawn_rect->height = y2 - y1;
|
|
|
|
|
|
|
|
cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
draw_shadow (shadow, cr, box, clip_box, GTK_BLUR_X | GTK_BLUR_Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_shadow_side (const GtkCssValue *shadow,
|
|
|
|
cairo_t *cr,
|
|
|
|
GtkRoundedBox *box,
|
|
|
|
GtkRoundedBox *clip_box,
|
|
|
|
GtkCssSide side,
|
|
|
|
cairo_rectangle_int_t *drawn_rect)
|
|
|
|
{
|
|
|
|
GtkBlurFlags blur_flags = GTK_BLUR_REPEAT;
|
|
|
|
gdouble radius, clip_radius;
|
|
|
|
int x1, x2, y1, y2;
|
|
|
|
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
|
|
|
clip_radius = _gtk_cairo_blur_compute_pixels (radius);
|
|
|
|
|
|
|
|
if (side == GTK_CSS_TOP || side == GTK_CSS_BOTTOM)
|
|
|
|
{
|
|
|
|
blur_flags |= GTK_BLUR_Y;
|
|
|
|
x1 = floor (box->box.x - clip_radius);
|
|
|
|
x2 = ceil (box->box.x + box->box.width + clip_radius);
|
|
|
|
}
|
|
|
|
else if (side == GTK_CSS_LEFT)
|
|
|
|
{
|
|
|
|
x1 = floor (box->box.x -clip_radius);
|
|
|
|
x2 = ceil (box->box.x + clip_radius);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = floor (box->box.x + box->box.width -clip_radius);
|
|
|
|
x2 = ceil (box->box.x + box->box.width + clip_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (side == GTK_CSS_LEFT || side == GTK_CSS_RIGHT)
|
|
|
|
{
|
|
|
|
blur_flags |= GTK_BLUR_X;
|
|
|
|
y1 = floor (box->box.y - clip_radius);
|
|
|
|
y2 = ceil (box->box.y + box->box.height + clip_radius);
|
|
|
|
}
|
|
|
|
else if (side == GTK_CSS_TOP)
|
|
|
|
{
|
|
|
|
y1 = floor (box->box.y -clip_radius);
|
|
|
|
y2 = ceil (box->box.y + clip_radius);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y1 = floor (box->box.y + box->box.height -clip_radius);
|
|
|
|
y2 = ceil (box->box.y + box->box.height + clip_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
drawn_rect->x = x1;
|
|
|
|
drawn_rect->y = y1;
|
|
|
|
drawn_rect->width = x2 - x1;
|
|
|
|
drawn_rect->height = y2 - y1;
|
|
|
|
|
|
|
|
cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
cairo_clip (cr);
|
|
|
|
draw_shadow (shadow, cr, box, clip_box, blur_flags);
|
|
|
|
}
|
|
|
|
|
2011-06-02 00:58:53 +00:00
|
|
|
void
|
2012-03-28 01:31:20 +00:00
|
|
|
_gtk_css_shadow_value_paint_box (const GtkCssValue *shadow,
|
|
|
|
cairo_t *cr,
|
|
|
|
const GtkRoundedBox *padding_box)
|
2011-06-02 00:58:53 +00:00
|
|
|
{
|
2012-04-16 11:02:41 +00:00
|
|
|
GtkRoundedBox box, clip_box;
|
2013-05-06 14:05:08 +00:00
|
|
|
double spread, radius, clip_radius, x, y, outside;
|
2015-05-31 01:24:48 +00:00
|
|
|
double x1c, y1c, x2c, y2c;
|
2012-04-03 09:49:46 +00:00
|
|
|
|
|
|
|
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
|
2011-06-02 00:58:53 +00:00
|
|
|
|
2015-05-31 01:24:48 +00:00
|
|
|
cairo_clip_extents (cr, &x1c, &y1c, &x2c, &y2c);
|
|
|
|
if ((shadow->inset && !_gtk_rounded_box_intersects_rectangle (padding_box, x1c, y1c, x2c, y2c)) ||
|
|
|
|
(!shadow->inset && _gtk_rounded_box_contains_rectangle (padding_box, x1c, y1c, x2c, y2c)))
|
2014-12-02 13:29:24 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-02 00:58:53 +00:00
|
|
|
cairo_save (cr);
|
|
|
|
|
2013-05-03 10:50:18 +00:00
|
|
|
spread = _gtk_css_number_value_get (shadow->spread, 0);
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
2014-02-03 14:56:59 +00:00
|
|
|
clip_radius = _gtk_cairo_blur_compute_pixels (radius);
|
2013-05-03 10:50:18 +00:00
|
|
|
x = _gtk_css_number_value_get (shadow->hoffset, 0);
|
|
|
|
y = _gtk_css_number_value_get (shadow->voffset, 0);
|
|
|
|
|
2013-04-05 09:54:03 +00:00
|
|
|
if (shadow->inset)
|
|
|
|
{
|
|
|
|
_gtk_rounded_box_path (padding_box, cr);
|
|
|
|
cairo_clip (cr);
|
|
|
|
}
|
2013-05-03 10:50:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
_gtk_rounded_box_path (padding_box, cr);
|
2013-05-06 14:05:08 +00:00
|
|
|
outside = spread + clip_radius + MAX (fabs (x), fabs (y));
|
2013-05-03 10:50:18 +00:00
|
|
|
clip_box = *padding_box;
|
|
|
|
_gtk_rounded_box_grow (&clip_box, outside, outside, outside, outside);
|
|
|
|
_gtk_rounded_box_clip_path (&clip_box, cr);
|
2013-05-06 11:06:13 +00:00
|
|
|
|
2013-05-03 10:50:18 +00:00
|
|
|
cairo_clip (cr);
|
|
|
|
}
|
2011-06-02 00:58:53 +00:00
|
|
|
|
2012-04-03 09:49:46 +00:00
|
|
|
box = *padding_box;
|
2013-05-03 10:50:18 +00:00
|
|
|
_gtk_rounded_box_move (&box, x, y);
|
|
|
|
|
2013-04-05 09:54:03 +00:00
|
|
|
if (shadow->inset)
|
|
|
|
_gtk_rounded_box_shrink (&box, spread, spread, spread, spread);
|
|
|
|
else /* Outset */
|
|
|
|
_gtk_rounded_box_grow (&box, spread, spread, spread, spread);
|
2011-06-02 00:58:53 +00:00
|
|
|
|
2012-04-16 11:02:41 +00:00
|
|
|
clip_box = *padding_box;
|
2013-05-06 14:05:08 +00:00
|
|
|
_gtk_rounded_box_shrink (&clip_box, -clip_radius, -clip_radius, -clip_radius, -clip_radius);
|
2012-04-16 11:02:41 +00:00
|
|
|
|
2014-08-29 21:48:29 +00:00
|
|
|
if (!needs_blur (shadow))
|
2015-03-20 13:34:44 +00:00
|
|
|
draw_shadow (shadow, cr, &box, &clip_box, GTK_BLUR_NONE);
|
2013-05-06 11:06:13 +00:00
|
|
|
else
|
|
|
|
{
|
2015-09-15 09:46:57 +00:00
|
|
|
int i;
|
2013-05-06 11:06:13 +00:00
|
|
|
cairo_region_t *remaining;
|
|
|
|
cairo_rectangle_int_t r;
|
|
|
|
|
|
|
|
/* For the blurred case we divide the rendering into 9 parts,
|
|
|
|
* 4 of the corners, 4 for the horizonat/vertical lines and
|
|
|
|
* one for the interior. We make the non-interior parts
|
|
|
|
* large enought to fit the full radius of the blur, so that
|
|
|
|
* the interior part can be drawn solidly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (shadow->inset)
|
|
|
|
{
|
|
|
|
/* In the inset case we want to paint the whole clip-box.
|
|
|
|
* We could remove the part of "box" where the blur doesn't
|
|
|
|
* reach, but computing that is a bit tricky since the
|
|
|
|
* rounded corners are on the "inside" of it. */
|
|
|
|
r.x = floor (clip_box.box.x);
|
|
|
|
r.y = floor (clip_box.box.y);
|
|
|
|
r.width = ceil (clip_box.box.x + clip_box.box.width) - r.x;
|
|
|
|
r.height = ceil (clip_box.box.y + clip_box.box.height) - r.y;
|
|
|
|
remaining = cairo_region_create_rectangle (&r);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* In the outset case we want to paint the entire box, plus as far
|
|
|
|
* as the radius reaches from it */
|
2013-05-06 14:05:08 +00:00
|
|
|
r.x = floor (box.box.x - clip_radius);
|
|
|
|
r.y = floor (box.box.y - clip_radius);
|
|
|
|
r.width = ceil (box.box.x + box.box.width + clip_radius) - r.x;
|
|
|
|
r.height = ceil (box.box.y + box.box.height + clip_radius) - r.y;
|
2013-05-06 11:06:13 +00:00
|
|
|
|
|
|
|
remaining = cairo_region_create_rectangle (&r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First do the corners of box */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
cairo_save (cr);
|
2015-09-15 09:46:57 +00:00
|
|
|
/* Always clip with remaining to ensure we never draw any area twice */
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
|
|
|
draw_shadow_corner (shadow, cr, &box, &clip_box, i, &r);
|
2013-05-06 11:06:13 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
/* We drew the region, remove it from remaining */
|
|
|
|
cairo_region_subtract_rectangle (remaining, &r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then the sides */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
cairo_save (cr);
|
2015-09-15 09:46:57 +00:00
|
|
|
/* Always clip with remaining to ensure we never draw any area twice */
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
|
|
|
draw_shadow_side (shadow, cr, &box, &clip_box, i, &r);
|
2013-05-06 11:06:13 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
/* We drew the region, remove it from remaining */
|
|
|
|
cairo_region_subtract_rectangle (remaining, &r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then the rest, which needs no blurring */
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
gdk_cairo_region (cr, remaining);
|
|
|
|
cairo_clip (cr);
|
2015-03-20 13:34:44 +00:00
|
|
|
draw_shadow (shadow, cr, &box, &clip_box, GTK_BLUR_NONE);
|
2013-05-06 11:06:13 +00:00
|
|
|
cairo_restore (cr);
|
2013-08-21 10:56:21 +00:00
|
|
|
|
|
|
|
cairo_region_destroy (remaining);
|
2013-05-06 11:06:13 +00:00
|
|
|
}
|
2012-04-16 11:02:41 +00:00
|
|
|
|
2011-06-02 00:58:53 +00:00
|
|
|
cairo_restore (cr);
|
|
|
|
}
|