2015-12-27 07:03:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* 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.1 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
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: Matthias Clasen <mclasen@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcssimageradialprivate.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
|
|
|
#include "gtkcsspositionvalueprivate.h"
|
2020-01-10 12:02:33 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2015-12-27 07:03:35 +00:00
|
|
|
#include "gtkcssprovider.h"
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkCssImageRadial, _gtk_css_image_radial, GTK_TYPE_CSS_IMAGE)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_image_radial_get_start_end (GtkCssImageRadial *radial,
|
|
|
|
double radius,
|
|
|
|
double *start,
|
|
|
|
double *end)
|
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
const GtkCssImageRadialColorStop *stop;
|
2015-12-27 07:03:35 +00:00
|
|
|
double pos;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (radial->repeating)
|
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
stop = &radial->color_stops[0];
|
2015-12-27 07:03:35 +00:00
|
|
|
if (stop->offset == NULL)
|
|
|
|
*start = 0;
|
|
|
|
else
|
|
|
|
*start = _gtk_css_number_value_get (stop->offset, radius) / radius;
|
|
|
|
|
|
|
|
*end = *start;
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
for (i = 0; i < radial->n_stops; i++)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
stop = &radial->color_stops[i];
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
if (stop->offset == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pos = _gtk_css_number_value_get (stop->offset, radius) / radius;
|
|
|
|
|
|
|
|
*end = MAX (pos, *end);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stop->offset == NULL)
|
|
|
|
*end = MAX (*end, 1.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*start = 0;
|
|
|
|
*end = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-02-14 01:30:42 +00:00
|
|
|
gtk_css_image_radial_snapshot (GtkCssImage *image,
|
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
double width,
|
|
|
|
double height)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
|
|
|
GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image);
|
2020-09-12 04:07:38 +00:00
|
|
|
GskColorStop *stops;
|
2015-12-27 07:03:35 +00:00
|
|
|
double x, y;
|
2020-09-12 13:16:42 +00:00
|
|
|
double hradius, vradius;
|
2015-12-27 07:03:35 +00:00
|
|
|
double start, end;
|
|
|
|
double r1, r2, r3, r4, r;
|
|
|
|
double offset;
|
|
|
|
int i, last;
|
|
|
|
|
|
|
|
x = _gtk_css_position_value_get_x (radial->position, width);
|
|
|
|
y = _gtk_css_position_value_get_y (radial->position, height);
|
|
|
|
|
|
|
|
if (radial->circle)
|
|
|
|
{
|
|
|
|
switch (radial->size)
|
|
|
|
{
|
|
|
|
case GTK_CSS_EXPLICIT_SIZE:
|
2020-09-12 13:16:42 +00:00
|
|
|
hradius = _gtk_css_number_value_get (radial->sizes[0], width);
|
2015-12-27 07:03:35 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_CLOSEST_SIDE:
|
2020-09-12 13:16:42 +00:00
|
|
|
hradius = MIN (MIN (x, width - x), MIN (y, height - y));
|
2015-12-27 07:03:35 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_FARTHEST_SIDE:
|
2020-09-12 13:16:42 +00:00
|
|
|
hradius = MAX (MAX (x, width - x), MAX (y, height - y));
|
2015-12-27 07:03:35 +00:00
|
|
|
break;
|
|
|
|
case GTK_CSS_CLOSEST_CORNER:
|
|
|
|
case GTK_CSS_FARTHEST_CORNER:
|
|
|
|
r1 = x*x + y*y;
|
|
|
|
r2 = x*x + (height - y)*(height - y);
|
|
|
|
r3 = (width - x)*(width - x) + y*y;
|
|
|
|
r4 = (width - x)*(width - x) + (height - y)*(height - y);
|
|
|
|
if (radial->size == GTK_CSS_CLOSEST_CORNER)
|
|
|
|
r = MIN ( MIN (r1, r2), MIN (r3, r4));
|
|
|
|
else
|
|
|
|
r = MAX ( MAX (r1, r2), MAX (r3, r4));
|
2020-09-12 13:16:42 +00:00
|
|
|
hradius = sqrt (r);
|
2015-12-27 07:03:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2020-09-12 13:16:42 +00:00
|
|
|
hradius = MAX (1.0, hradius);
|
|
|
|
vradius = hradius;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (radial->size)
|
|
|
|
{
|
|
|
|
case GTK_CSS_EXPLICIT_SIZE:
|
|
|
|
hradius = _gtk_css_number_value_get (radial->sizes[0], width);
|
|
|
|
vradius = _gtk_css_number_value_get (radial->sizes[1], height);
|
|
|
|
break;
|
|
|
|
case GTK_CSS_CLOSEST_SIDE:
|
|
|
|
hradius = MIN (x, width - x);
|
|
|
|
vradius = MIN (y, height - y);
|
|
|
|
break;
|
|
|
|
case GTK_CSS_FARTHEST_SIDE:
|
|
|
|
hradius = MAX (x, width - x);
|
|
|
|
vradius = MAX (y, height - y);
|
|
|
|
break;
|
|
|
|
case GTK_CSS_CLOSEST_CORNER:
|
|
|
|
hradius = M_SQRT2 * MIN (x, width - x);
|
|
|
|
vradius = M_SQRT2 * MIN (y, height - y);
|
|
|
|
break;
|
|
|
|
case GTK_CSS_FARTHEST_CORNER:
|
|
|
|
hradius = M_SQRT2 * MAX (x, width - x);
|
|
|
|
vradius = M_SQRT2 * MAX (y, height - y);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
hradius = MAX (1.0, hradius);
|
|
|
|
vradius = MAX (1.0, vradius);
|
|
|
|
}
|
|
|
|
|
2020-09-12 13:16:42 +00:00
|
|
|
gtk_css_image_radial_get_start_end (radial, hradius, &start, &end);
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
offset = start;
|
|
|
|
last = -1;
|
2020-09-12 04:07:38 +00:00
|
|
|
stops = g_newa (GskColorStop, radial->n_stops);
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
for (i = 0; i < radial->n_stops; i++)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
|
2015-12-27 07:03:35 +00:00
|
|
|
double pos, step;
|
|
|
|
|
|
|
|
if (stop->offset == NULL)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
pos = 0.0;
|
2020-01-11 09:00:25 +00:00
|
|
|
else if (i + 1 == radial->n_stops)
|
2015-12-27 07:03:35 +00:00
|
|
|
pos = 1.0;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
2020-09-19 06:55:18 +00:00
|
|
|
pos = MIN (1.0, _gtk_css_number_value_get (stop->offset, hradius) / hradius);
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2020-09-12 13:16:42 +00:00
|
|
|
pos = MAX (pos, 0);
|
2016-11-02 14:19:49 +00:00
|
|
|
step = (pos - offset) / (i - last);
|
2015-12-27 07:03:35 +00:00
|
|
|
for (last = last + 1; last <= i; last++)
|
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
stop = &radial->color_stops[last];
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
offset += step;
|
|
|
|
|
2020-09-12 04:07:38 +00:00
|
|
|
stops[last].offset = (offset - start) / (end - start);
|
|
|
|
stops[last].color = *gtk_css_color_value_get_rgba (stop->color);
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offset = pos;
|
|
|
|
last = i;
|
|
|
|
}
|
|
|
|
|
2020-09-12 04:07:38 +00:00
|
|
|
if (radial->repeating)
|
|
|
|
gtk_snapshot_append_repeating_radial_gradient (snapshot,
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
|
|
|
&GRAPHENE_POINT_INIT (x, y),
|
2020-09-12 13:16:42 +00:00
|
|
|
hradius,
|
|
|
|
vradius,
|
2020-09-12 04:07:38 +00:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
stops,
|
|
|
|
radial->n_stops);
|
|
|
|
else
|
|
|
|
gtk_snapshot_append_radial_gradient (snapshot,
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
|
|
|
&GRAPHENE_POINT_INIT (x, y),
|
2020-09-12 13:16:42 +00:00
|
|
|
hradius,
|
|
|
|
vradius,
|
2020-09-12 04:07:38 +00:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
stops,
|
|
|
|
radial->n_stops);
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
static guint
|
|
|
|
gtk_css_image_radial_parse_color_stop (GtkCssImageRadial *radial,
|
2020-01-11 09:00:25 +00:00
|
|
|
GtkCssParser *parser,
|
|
|
|
GArray *stop_array)
|
2019-03-31 00:17:44 +00:00
|
|
|
{
|
|
|
|
GtkCssImageRadialColorStop stop;
|
|
|
|
|
|
|
|
stop.color = _gtk_css_color_value_parse (parser);
|
|
|
|
if (stop.color == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (gtk_css_number_value_can_parse (parser))
|
|
|
|
{
|
|
|
|
stop.offset = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_PERCENT
|
|
|
|
| GTK_CSS_PARSE_LENGTH);
|
|
|
|
if (stop.offset == NULL)
|
|
|
|
{
|
|
|
|
_gtk_css_value_unref (stop.color);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stop.offset = NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
g_array_append_val (stop_array, stop);
|
2019-03-31 00:17:44 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gtk_css_image_radial_parse_first_arg (GtkCssImageRadial *radial,
|
2020-01-11 09:00:25 +00:00
|
|
|
GtkCssParser *parser,
|
|
|
|
GArray *stop_array)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
|
|
|
gboolean has_shape = FALSE;
|
|
|
|
gboolean has_size = FALSE;
|
|
|
|
gboolean found_one = FALSE;
|
|
|
|
guint i;
|
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
guint value;
|
|
|
|
} names[] = {
|
|
|
|
{ "closest-side", GTK_CSS_CLOSEST_SIDE },
|
|
|
|
{ "farthest-side", GTK_CSS_FARTHEST_SIDE },
|
|
|
|
{ "closest-corner", GTK_CSS_CLOSEST_CORNER },
|
|
|
|
{ "farthest-corner", GTK_CSS_FARTHEST_CORNER }
|
|
|
|
};
|
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
found_one = FALSE;
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
do {
|
2019-03-24 13:03:52 +00:00
|
|
|
if (!has_shape && gtk_css_parser_try_ident (parser, "circle"))
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
|
|
|
radial->circle = TRUE;
|
|
|
|
found_one = has_shape = TRUE;
|
|
|
|
}
|
2019-03-24 13:03:52 +00:00
|
|
|
else if (!has_shape && gtk_css_parser_try_ident (parser, "ellipse"))
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
|
|
|
radial->circle = FALSE;
|
|
|
|
found_one = has_shape = TRUE;
|
|
|
|
}
|
|
|
|
else if (!has_size)
|
|
|
|
{
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (names); i++)
|
|
|
|
{
|
2019-03-31 00:17:44 +00:00
|
|
|
if (gtk_css_parser_try_ident (parser, names[i].name))
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
|
|
|
found_one = has_size = TRUE;
|
|
|
|
radial->size = names[i].value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
if (!has_size && gtk_css_number_value_can_parse (parser))
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2019-03-31 00:17:44 +00:00
|
|
|
radial->sizes[0] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH | GTK_CSS_PARSE_PERCENT);
|
|
|
|
if (radial->sizes[0] == NULL)
|
|
|
|
return 0;
|
2016-02-12 05:45:06 +00:00
|
|
|
if (gtk_css_number_value_can_parse (parser))
|
2019-03-31 00:17:44 +00:00
|
|
|
{
|
|
|
|
radial->sizes[1] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH | GTK_CSS_PARSE_PERCENT);
|
|
|
|
if (radial->sizes[1] == NULL)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
found_one = has_size = TRUE;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
2019-03-31 00:17:44 +00:00
|
|
|
if (!has_size)
|
|
|
|
break;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
2019-03-31 00:17:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!(has_shape && has_size));
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
if (gtk_css_parser_try_ident (parser, "at"))
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2016-02-05 18:01:48 +00:00
|
|
|
radial->position = _gtk_css_position_value_parse (parser);
|
|
|
|
if (!radial->position)
|
2019-03-31 00:17:44 +00:00
|
|
|
return 0;
|
|
|
|
found_one = TRUE;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
2016-02-05 18:01:48 +00:00
|
|
|
else
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2016-02-05 18:01:48 +00:00
|
|
|
radial->position = _gtk_css_position_value_new (_gtk_css_number_value_new (50, GTK_CSS_PERCENT),
|
|
|
|
_gtk_css_number_value_new (50, GTK_CSS_PERCENT));
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_size)
|
|
|
|
{
|
|
|
|
radial->size = GTK_CSS_FARTHEST_CORNER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_shape)
|
|
|
|
{
|
2016-11-07 20:40:21 +00:00
|
|
|
if (radial->sizes[0] && !radial->sizes[1])
|
2015-12-27 07:03:35 +00:00
|
|
|
radial->circle = TRUE;
|
2016-11-07 20:40:21 +00:00
|
|
|
else
|
|
|
|
radial->circle = FALSE;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_shape && radial->circle)
|
|
|
|
{
|
|
|
|
if (radial->sizes[0] && radial->sizes[1])
|
|
|
|
{
|
2019-04-09 03:40:50 +00:00
|
|
|
gtk_css_parser_error_syntax (parser, "Circular gradient can only have one size");
|
2019-03-31 00:17:44 +00:00
|
|
|
return 0;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 03:40:35 +00:00
|
|
|
if (radial->sizes[0] && gtk_css_number_value_has_percent (radial->sizes[0]))
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2019-04-09 03:40:50 +00:00
|
|
|
gtk_css_parser_error_syntax (parser, "Circular gradient cannot have percentage as size");
|
2019-03-31 00:17:44 +00:00
|
|
|
return 0;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_size && !radial->circle)
|
|
|
|
{
|
2016-11-07 19:44:29 +00:00
|
|
|
if (radial->sizes[0] && !radial->sizes[1])
|
2015-12-27 07:03:35 +00:00
|
|
|
radial->sizes[1] = _gtk_css_value_ref (radial->sizes[0]);
|
|
|
|
}
|
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
if (found_one)
|
|
|
|
return 1;
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
if (!gtk_css_image_radial_parse_color_stop (radial, parser, stop_array))
|
2019-03-31 00:17:44 +00:00
|
|
|
return 0;
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkCssImageRadial *self;
|
|
|
|
GArray *stop_array;
|
|
|
|
} ParseData;
|
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
static guint
|
|
|
|
gtk_css_image_radial_parse_arg (GtkCssParser *parser,
|
|
|
|
guint arg,
|
2020-01-11 09:00:25 +00:00
|
|
|
gpointer user_data)
|
2019-03-31 00:17:44 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
ParseData *parse_data = user_data;
|
|
|
|
GtkCssImageRadial *self = parse_data->self;
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
if (arg == 0)
|
2020-01-11 09:00:25 +00:00
|
|
|
return gtk_css_image_radial_parse_first_arg (self, parser, parse_data->stop_array);
|
2019-03-31 00:17:44 +00:00
|
|
|
else
|
2020-01-11 09:00:25 +00:00
|
|
|
return gtk_css_image_radial_parse_color_stop (self, parser, parse_data->stop_array);
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
}
|
2016-04-18 18:25:11 +00:00
|
|
|
|
2019-03-31 00:17:44 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_radial_parse (GtkCssImage *image,
|
|
|
|
GtkCssParser *parser)
|
|
|
|
{
|
|
|
|
GtkCssImageRadial *self = GTK_CSS_IMAGE_RADIAL (image);
|
2020-01-11 09:00:25 +00:00
|
|
|
ParseData parse_data;
|
|
|
|
gboolean success;
|
2019-03-31 00:17:44 +00:00
|
|
|
|
|
|
|
if (gtk_css_parser_has_function (parser, "repeating-radial-gradient"))
|
|
|
|
self->repeating = TRUE;
|
|
|
|
else if (gtk_css_parser_has_function (parser, "radial-gradient"))
|
|
|
|
self->repeating = FALSE;
|
|
|
|
else
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2019-04-09 03:40:50 +00:00
|
|
|
gtk_css_parser_error_syntax (parser, "Not a radial gradient");
|
2015-12-27 07:03:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
parse_data.self = self;
|
|
|
|
parse_data.stop_array = g_array_new (TRUE, FALSE, sizeof (GtkCssImageRadialColorStop));
|
|
|
|
|
|
|
|
success = gtk_css_parser_consume_function (parser, 3, G_MAXUINT, gtk_css_image_radial_parse_arg, &parse_data);
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
g_array_free (parse_data.stop_array, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->n_stops = parse_data.stop_array->len;
|
|
|
|
self->color_stops = (GtkCssImageRadialColorStop *)g_array_free (parse_data.stop_array, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_image_radial_print (GtkCssImage *image,
|
|
|
|
GString *string)
|
|
|
|
{
|
|
|
|
GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image);
|
|
|
|
guint i;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *names[] = {
|
2015-12-27 07:03:35 +00:00
|
|
|
NULL,
|
|
|
|
"closest-side",
|
|
|
|
"farthest-side",
|
|
|
|
"closest-corner",
|
|
|
|
"farthest-corner"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (radial->repeating)
|
|
|
|
g_string_append (string, "repeating-radial-gradient(");
|
|
|
|
else
|
|
|
|
g_string_append (string, "radial-gradient(");
|
|
|
|
|
|
|
|
if (radial->circle)
|
|
|
|
g_string_append (string, "circle ");
|
|
|
|
else
|
|
|
|
g_string_append (string, "ellipse ");
|
|
|
|
|
|
|
|
if (radial->size != 0)
|
|
|
|
g_string_append (string, names[radial->size]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (radial->sizes[0])
|
|
|
|
_gtk_css_value_print (radial->sizes[0], string);
|
|
|
|
if (radial->sizes[1])
|
2016-02-12 20:22:23 +00:00
|
|
|
{
|
|
|
|
g_string_append (string, " ");
|
|
|
|
_gtk_css_value_print (radial->sizes[1], string);
|
|
|
|
}
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append (string, " at ");
|
|
|
|
_gtk_css_value_print (radial->position, string);
|
|
|
|
|
|
|
|
g_string_append (string, ", ");
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
for (i = 0; i < radial->n_stops; i++)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
g_string_append (string, ", ");
|
|
|
|
|
|
|
|
_gtk_css_value_print (stop->color, string);
|
|
|
|
|
|
|
|
if (stop->offset)
|
|
|
|
{
|
|
|
|
g_string_append (string, " ");
|
|
|
|
_gtk_css_value_print (stop->offset, string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append (string, ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCssImage *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_image_radial_compute (GtkCssImage *image,
|
|
|
|
guint property_id,
|
|
|
|
GtkStyleProvider *provider,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkCssStyle *parent_style)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
|
|
|
GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image);
|
|
|
|
GtkCssImageRadial *copy;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
copy = g_object_new (GTK_TYPE_CSS_IMAGE_RADIAL, NULL);
|
|
|
|
copy->repeating = radial->repeating;
|
|
|
|
copy->circle = radial->circle;
|
|
|
|
copy->size = radial->size;
|
|
|
|
|
|
|
|
copy->position = _gtk_css_value_compute (radial->position, property_id, provider, style, parent_style);
|
|
|
|
|
|
|
|
if (radial->sizes[0])
|
|
|
|
copy->sizes[0] = _gtk_css_value_compute (radial->sizes[0], property_id, provider, style, parent_style);
|
|
|
|
|
|
|
|
if (radial->sizes[1])
|
|
|
|
copy->sizes[1] = _gtk_css_value_compute (radial->sizes[1], property_id, provider, style, parent_style);
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
copy->n_stops = radial->n_stops;
|
|
|
|
copy->color_stops = g_malloc (sizeof (GtkCssImageRadialColorStop) * copy->n_stops);
|
|
|
|
for (i = 0; i < radial->n_stops; i++)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
|
|
|
|
GtkCssImageRadialColorStop *scopy = ©->color_stops[i];
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
scopy->color = _gtk_css_value_compute (stop->color, property_id, provider, style, parent_style);
|
|
|
|
|
|
|
|
if (stop->offset)
|
|
|
|
{
|
|
|
|
scopy->offset = _gtk_css_value_compute (stop->offset, property_id, provider, style, parent_style);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scopy->offset = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_CSS_IMAGE (copy);
|
|
|
|
}
|
|
|
|
|
2016-01-07 21:30:19 +00:00
|
|
|
static GtkCssImage *
|
|
|
|
gtk_css_image_radial_transition (GtkCssImage *start_image,
|
|
|
|
GtkCssImage *end_image,
|
|
|
|
guint property_id,
|
|
|
|
double progress)
|
|
|
|
{
|
|
|
|
GtkCssImageRadial *start, *end, *result;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
start = GTK_CSS_IMAGE_RADIAL (start_image);
|
|
|
|
|
|
|
|
if (end_image == NULL)
|
|
|
|
return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);
|
|
|
|
|
|
|
|
if (!GTK_IS_CSS_IMAGE_RADIAL (end_image))
|
|
|
|
return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);
|
|
|
|
|
|
|
|
end = GTK_CSS_IMAGE_RADIAL (end_image);
|
|
|
|
|
|
|
|
if (start->repeating != end->repeating ||
|
2020-01-11 09:00:25 +00:00
|
|
|
start->n_stops != end->n_stops ||
|
2016-01-07 21:30:19 +00:00
|
|
|
start->size != end->size ||
|
|
|
|
start->circle != end->circle)
|
|
|
|
return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);
|
|
|
|
|
|
|
|
result = g_object_new (GTK_TYPE_CSS_IMAGE_RADIAL, NULL);
|
|
|
|
result->repeating = start->repeating;
|
|
|
|
result->circle = start->circle;
|
|
|
|
result->size = start->size;
|
|
|
|
|
|
|
|
result->position = _gtk_css_value_transition (start->position, end->position, property_id, progress);
|
|
|
|
if (result->position == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (start->sizes[0] && end->sizes[0])
|
|
|
|
{
|
|
|
|
result->sizes[0] = _gtk_css_value_transition (start->sizes[0], end->sizes[0], property_id, progress);
|
|
|
|
if (result->sizes[0] == NULL)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result->sizes[0] = 0;
|
|
|
|
|
|
|
|
if (start->sizes[1] && end->sizes[1])
|
|
|
|
{
|
|
|
|
result->sizes[1] = _gtk_css_value_transition (start->sizes[1], end->sizes[1], property_id, progress);
|
|
|
|
if (result->sizes[1] == NULL)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result->sizes[1] = 0;
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
result->color_stops = g_malloc (sizeof (GtkCssImageRadialColorStop) * start->n_stops);
|
|
|
|
result->n_stops = 0;
|
|
|
|
for (i = 0; i < start->n_stops; i++)
|
2016-01-07 21:30:19 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
const GtkCssImageRadialColorStop *start_stop = &start->color_stops[i];
|
|
|
|
const GtkCssImageRadialColorStop *end_stop = &end->color_stops[i];
|
|
|
|
GtkCssImageRadialColorStop *stop = &result->color_stops[i];
|
2016-01-07 21:30:19 +00:00
|
|
|
|
|
|
|
if ((start_stop->offset != NULL) != (end_stop->offset != NULL))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (start_stop->offset == NULL)
|
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
stop->offset = NULL;
|
2016-01-07 21:30:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
stop->offset = _gtk_css_value_transition (start_stop->offset,
|
|
|
|
end_stop->offset,
|
|
|
|
property_id,
|
|
|
|
progress);
|
|
|
|
if (stop->offset == NULL)
|
2016-01-07 21:30:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
stop->color = _gtk_css_value_transition (start_stop->color,
|
|
|
|
end_stop->color,
|
|
|
|
property_id,
|
|
|
|
progress);
|
|
|
|
if (stop->color == NULL)
|
2016-01-07 21:30:19 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
if (stop->offset)
|
|
|
|
_gtk_css_value_unref (stop->offset);
|
2016-01-07 21:30:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
result->n_stops++;
|
2016-01-07 21:30:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_CSS_IMAGE (result);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
g_object_unref (result);
|
|
|
|
return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);
|
|
|
|
}
|
|
|
|
|
2015-12-27 07:03:35 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_radial_equal (GtkCssImage *image1,
|
|
|
|
GtkCssImage *image2)
|
|
|
|
{
|
2019-08-17 16:55:35 +00:00
|
|
|
GtkCssImageRadial *radial1 = (GtkCssImageRadial *) image1;
|
|
|
|
GtkCssImageRadial *radial2 = (GtkCssImageRadial *) image2;
|
2015-12-27 07:03:35 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (radial1->repeating != radial2->repeating ||
|
|
|
|
radial1->size != radial2->size ||
|
|
|
|
!_gtk_css_value_equal (radial1->position, radial2->position) ||
|
|
|
|
((radial1->sizes[0] == NULL) != (radial2->sizes[0] == NULL)) ||
|
|
|
|
(radial1->sizes[0] && radial2->sizes[0] && !_gtk_css_value_equal (radial1->sizes[0], radial2->sizes[0])) ||
|
|
|
|
((radial1->sizes[1] == NULL) != (radial2->sizes[1] == NULL)) ||
|
|
|
|
(radial1->sizes[1] && radial2->sizes[1] && !_gtk_css_value_equal (radial1->sizes[1], radial2->sizes[1])) ||
|
2020-01-11 09:00:25 +00:00
|
|
|
radial1->n_stops != radial2->n_stops)
|
2015-12-27 07:03:35 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
for (i = 0; i < radial1->n_stops; i++)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
const GtkCssImageRadialColorStop *stop1 = &radial1->color_stops[i];
|
|
|
|
const GtkCssImageRadialColorStop *stop2 = &radial2->color_stops[i];
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
if (!_gtk_css_value_equal0 (stop1->offset, stop2->offset) ||
|
|
|
|
!_gtk_css_value_equal (stop1->color, stop2->color))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_image_radial_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (object);
|
2020-01-11 09:00:25 +00:00
|
|
|
guint i;
|
2015-12-27 07:03:35 +00:00
|
|
|
|
2020-01-11 09:00:25 +00:00
|
|
|
for (i = 0; i < radial->n_stops; i ++)
|
2015-12-27 07:03:35 +00:00
|
|
|
{
|
2020-01-11 09:00:25 +00:00
|
|
|
GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
|
|
|
|
|
|
|
|
_gtk_css_value_unref (stop->color);
|
|
|
|
if (stop->offset)
|
|
|
|
_gtk_css_value_unref (stop->offset);
|
2015-12-27 07:03:35 +00:00
|
|
|
}
|
2020-01-11 09:00:25 +00:00
|
|
|
g_free (radial->color_stops);
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
if (radial->position)
|
|
|
|
{
|
|
|
|
_gtk_css_value_unref (radial->position);
|
|
|
|
radial->position = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
if (radial->sizes[i])
|
|
|
|
{
|
|
|
|
_gtk_css_value_unref (radial->sizes[i]);
|
|
|
|
radial->sizes[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (_gtk_css_image_radial_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2020-01-11 13:38:49 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_radial_is_computed (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image);
|
|
|
|
guint i;
|
|
|
|
gboolean computed = TRUE;
|
|
|
|
|
|
|
|
computed = computed && (!radial->position || gtk_css_value_is_computed (radial->position));
|
|
|
|
computed = computed && (!radial->sizes[0] || gtk_css_value_is_computed (radial->sizes[0]));
|
|
|
|
computed = computed && (!radial->sizes[1] || gtk_css_value_is_computed (radial->sizes[1]));
|
|
|
|
|
|
|
|
if (computed)
|
|
|
|
for (i = 0; i < radial->n_stops; i ++)
|
|
|
|
{
|
|
|
|
const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
|
|
|
|
|
|
|
|
if (stop->offset && !gtk_css_value_is_computed (stop->offset))
|
|
|
|
{
|
|
|
|
computed = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_css_value_is_computed (stop->color))
|
|
|
|
{
|
|
|
|
computed = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return computed;
|
|
|
|
}
|
2015-12-27 07:03:35 +00:00
|
|
|
static void
|
|
|
|
_gtk_css_image_radial_class_init (GtkCssImageRadialClass *klass)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2018-02-14 01:30:42 +00:00
|
|
|
image_class->snapshot = gtk_css_image_radial_snapshot;
|
2015-12-27 07:03:35 +00:00
|
|
|
image_class->parse = gtk_css_image_radial_parse;
|
|
|
|
image_class->print = gtk_css_image_radial_print;
|
|
|
|
image_class->compute = gtk_css_image_radial_compute;
|
2016-01-07 21:30:19 +00:00
|
|
|
image_class->transition = gtk_css_image_radial_transition;
|
2015-12-27 07:03:35 +00:00
|
|
|
image_class->equal = gtk_css_image_radial_equal;
|
2020-01-11 13:38:49 +00:00
|
|
|
image_class->is_computed = gtk_css_image_radial_is_computed;
|
2015-12-27 07:03:35 +00:00
|
|
|
|
|
|
|
object_class->dispose = gtk_css_image_radial_dispose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_css_image_radial_init (GtkCssImageRadial *radial)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|