Drop support for -gtk-gradient

The standard CSS radial-gradient can be used instead, and Adwaita
and HighContrast have been ported over.
This commit is contained in:
Matthias Clasen 2016-11-07 13:44:57 -05:00
parent aceba7484f
commit d674e9c8fa
12 changed files with 2 additions and 1222 deletions

View File

@ -406,7 +406,6 @@ gtk_private_h_sources = \
gtkcssimagebuiltinprivate.h \
gtkcssimagecrossfadeprivate.h \
gtkcssimagefallbackprivate.h \
gtkcssimagegradientprivate.h \
gtkcssimageiconthemeprivate.h \
gtkcssimagelinearprivate.h \
gtkcssimageradialprivate.h \
@ -676,7 +675,6 @@ gtk_base_c_sources = \
gtkcssimagebuiltin.c \
gtkcssimagecrossfade.c \
gtkcssimagefallback.c \
gtkcssimagegradient.c \
gtkcssimageicontheme.c \
gtkcssimagelinear.c \
gtkcssimageradial.c \

View File

@ -1,11 +1,8 @@
deprecated_h_sources = \
deprecated/gtkgradient.h \
deprecated/gtksymboliccolor.h
deprecated_private_h_sources = \
deprecated/gtkgradientprivate.h \
deprecated/gtksymboliccolorprivate.h
deprecated_c_sources = \
deprecated/gtkgradient.c \
deprecated/gtksymboliccolor.c

View File

@ -1,483 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2010 Carlos Garnacho <carlosg@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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#define GDK_DISABLE_DEPRECATION_WARNINGS
#include "gtkgradientprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssrgbavalueprivate.h"
#include "gtkstylecontextprivate.h"
#include "gtksymboliccolorprivate.h"
/**
* SECTION:gtkgradient
* @Short_description: Gradients
* @Title: GtkGradient
*
* GtkGradient is a boxed type that represents a gradient.
* It is the result of parsing a
* [gradient expression][gtkcssprovider-gradients].
* To obtain the gradient represented by a GtkGradient, it has to
* be resolved with gtk_gradient_resolve(), which replaces all
* symbolic color references by the colors they refer to (in a given
* context) and constructs a #cairo_pattern_t value.
*
* It is not normally necessary to deal directly with #GtkGradients,
* since they are mostly used behind the scenes by #GtkStyleContext and
* #GtkCssProvider.
*
* #GtkGradient is deprecated. It was used internally by GTKs CSS engine
* to represent gradients. As its handling is not conforming to modern
* web standards, it is not used anymore. If you want to use gradients in
* your own code, please use Cairo directly.
*/
G_DEFINE_BOXED_TYPE (GtkGradient, gtk_gradient,
gtk_gradient_ref, gtk_gradient_unref)
typedef struct ColorStop ColorStop;
struct ColorStop
{
gdouble offset;
GtkSymbolicColor *color;
};
struct _GtkGradient
{
gdouble x0;
gdouble y0;
gdouble x1;
gdouble y1;
gdouble radius0;
gdouble radius1;
GArray *stops;
guint ref_count;
};
/**
* gtk_gradient_new_linear:
* @x0: X coordinate of the starting point
* @y0: Y coordinate of the starting point
* @x1: X coordinate of the end point
* @y1: Y coordinate of the end point
*
* Creates a new linear gradient along the line defined by (x0, y0) and (x1, y1). Before using the gradient
* a number of stop colors must be added through gtk_gradient_add_color_stop().
*
* Returns: A newly created #GtkGradient
*
* Since: 3.0
*
* Deprecated: 3.8: #GtkGradient is deprecated.
**/
GtkGradient *
gtk_gradient_new_linear (gdouble x0,
gdouble y0,
gdouble x1,
gdouble y1)
{
GtkGradient *gradient;
gradient = g_slice_new (GtkGradient);
gradient->stops = g_array_new (FALSE, FALSE, sizeof (ColorStop));
gradient->x0 = x0;
gradient->y0 = y0;
gradient->x1 = x1;
gradient->y1 = y1;
gradient->radius0 = 0;
gradient->radius1 = 0;
gradient->ref_count = 1;
return gradient;
}
/**
* gtk_gradient_new_radial:
* @x0: X coordinate of the start circle
* @y0: Y coordinate of the start circle
* @radius0: radius of the start circle
* @x1: X coordinate of the end circle
* @y1: Y coordinate of the end circle
* @radius1: radius of the end circle
*
* Creates a new radial gradient along the two circles defined by (x0, y0, radius0) and
* (x1, y1, radius1). Before using the gradient a number of stop colors must be added
* through gtk_gradient_add_color_stop().
*
* Returns: A newly created #GtkGradient
*
* Since: 3.0
*
* Deprecated: 3.8: #GtkGradient is deprecated.
**/
GtkGradient *
gtk_gradient_new_radial (gdouble x0,
gdouble y0,
gdouble radius0,
gdouble x1,
gdouble y1,
gdouble radius1)
{
GtkGradient *gradient;
gradient = g_slice_new (GtkGradient);
gradient->stops = g_array_new (FALSE, FALSE, sizeof (ColorStop));
gradient->x0 = x0;
gradient->y0 = y0;
gradient->x1 = x1;
gradient->y1 = y1;
gradient->radius0 = radius0;
gradient->radius1 = radius1;
gradient->ref_count = 1;
return gradient;
}
/**
* gtk_gradient_add_color_stop:
* @gradient: a #GtkGradient
* @offset: offset for the color stop
* @color: color to use
*
* Adds a stop color to @gradient.
*
* Since: 3.0
*
* Deprecated: 3.8: #GtkGradient is deprecated.
**/
void
gtk_gradient_add_color_stop (GtkGradient *gradient,
gdouble offset,
GtkSymbolicColor *color)
{
ColorStop stop;
g_return_if_fail (gradient != NULL);
stop.offset = offset;
stop.color = gtk_symbolic_color_ref (color);
g_array_append_val (gradient->stops, stop);
}
/**
* gtk_gradient_ref:
* @gradient: a #GtkGradient
*
* Increases the reference count of @gradient.
*
* Returns: The same @gradient
*
* Since: 3.0
*
* Deprecated: 3.8: #GtkGradient is deprecated.
**/
GtkGradient *
gtk_gradient_ref (GtkGradient *gradient)
{
g_return_val_if_fail (gradient != NULL, NULL);
gradient->ref_count++;
return gradient;
}
/**
* gtk_gradient_unref:
* @gradient: a #GtkGradient
*
* Decreases the reference count of @gradient, freeing its memory
* if the reference count reaches 0.
*
* Since: 3.0
*
* Deprecated: 3.8: #GtkGradient is deprecated.
**/
void
gtk_gradient_unref (GtkGradient *gradient)
{
g_return_if_fail (gradient != NULL);
gradient->ref_count--;
if (gradient->ref_count == 0)
{
guint i;
for (i = 0; i < gradient->stops->len; i++)
{
ColorStop *stop;
stop = &g_array_index (gradient->stops, ColorStop, i);
gtk_symbolic_color_unref (stop->color);
}
g_array_free (gradient->stops, TRUE);
g_slice_free (GtkGradient, gradient);
}
}
cairo_pattern_t *
_gtk_gradient_resolve_full (GtkGradient *gradient,
GtkStyleProviderPrivate *provider,
GtkCssStyle *style,
GtkCssStyle *parent_style)
{
cairo_pattern_t *pattern;
guint i;
g_return_val_if_fail (gradient != NULL, NULL);
g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
g_return_val_if_fail (GTK_IS_CSS_STYLE (style), NULL);
g_return_val_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style), NULL);
if (gradient->radius0 == 0 && gradient->radius1 == 0)
pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0,
gradient->x1, gradient->y1);
else
pattern = cairo_pattern_create_radial (gradient->x0, gradient->y0,
gradient->radius0,
gradient->x1, gradient->y1,
gradient->radius1);
for (i = 0; i < gradient->stops->len; i++)
{
ColorStop *stop;
GtkCssValue *val;
GdkRGBA rgba;
stop = &g_array_index (gradient->stops, ColorStop, i);
/* if color resolving fails, assume transparency */
val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (stop->color),
provider,
gtk_css_style_get_value (style, GTK_CSS_PROPERTY_COLOR),
NULL);
if (val)
{
rgba = *_gtk_css_rgba_value_get_rgba (val);
_gtk_css_value_unref (val);
}
else
{
rgba.red = rgba.green = rgba.blue = rgba.alpha = 0.0;
}
cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
rgba.red, rgba.green,
rgba.blue, rgba.alpha);
}
return pattern;
}
static void
append_number (GString *str,
double d,
const char *zero,
const char *half,
const char *one)
{
if (zero && d == 0.0)
g_string_append (str, zero);
else if (half && d == 0.5)
g_string_append (str, half);
else if (one && d == 1.0)
g_string_append (str, one);
else
{
char buf[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_dtostr (buf, sizeof (buf), d);
g_string_append (str, buf);
}
}
/**
* gtk_gradient_to_string:
* @gradient: the gradient to print
*
* Creates a string representation for @gradient that is suitable
* for using in GTK CSS files.
*
* Returns: A string representation for @gradient
*
* Deprecated: 3.8: #GtkGradient is deprecated.
**/
char *
gtk_gradient_to_string (GtkGradient *gradient)
{
GString *str;
guint i;
g_return_val_if_fail (gradient != NULL, NULL);
str = g_string_new ("-gtk-gradient (");
if (gradient->radius0 == 0 && gradient->radius1 == 0)
{
g_string_append (str, "linear, ");
append_number (str, gradient->x0, "left", "center", "right");
g_string_append_c (str, ' ');
append_number (str, gradient->y0, "top", "center", "bottom");
g_string_append (str, ", ");
append_number (str, gradient->x1, "left", "center", "right");
g_string_append_c (str, ' ');
append_number (str, gradient->y1, "top", "center", "bottom");
}
else
{
g_string_append (str, "radial, ");
append_number (str, gradient->x0, "left", "center", "right");
g_string_append_c (str, ' ');
append_number (str, gradient->y0, "top", "center", "bottom");
g_string_append (str, ", ");
append_number (str, gradient->radius0, NULL, NULL, NULL);
g_string_append (str, ", ");
append_number (str, gradient->x1, "left", "center", "right");
g_string_append_c (str, ' ');
append_number (str, gradient->y1, "top", "center", "bottom");
g_string_append (str, ", ");
append_number (str, gradient->radius1, NULL, NULL, NULL);
}
for (i = 0; i < gradient->stops->len; i++)
{
ColorStop *stop;
char *s;
stop = &g_array_index (gradient->stops, ColorStop, i);
g_string_append (str, ", ");
if (stop->offset == 0.0)
g_string_append (str, "from (");
else if (stop->offset == 1.0)
g_string_append (str, "to (");
else
{
g_string_append (str, "color-stop (");
append_number (str, stop->offset, NULL, NULL, NULL);
g_string_append (str, ", ");
}
s = gtk_symbolic_color_to_string (stop->color);
g_string_append (str, s);
g_free (s);
g_string_append (str, ")");
}
g_string_append (str, ")");
return g_string_free (str, FALSE);
}
static GtkGradient *
gtk_gradient_fade (GtkGradient *gradient,
double opacity)
{
GtkGradient *faded;
guint i;
faded = g_slice_new (GtkGradient);
faded->stops = g_array_new (FALSE, FALSE, sizeof (ColorStop));
faded->x0 = gradient->x0;
faded->y0 = gradient->y0;
faded->x1 = gradient->x1;
faded->y1 = gradient->y1;
faded->radius0 = gradient->radius0;
faded->radius1 = gradient->radius1;
faded->ref_count = 1;
for (i = 0; i < gradient->stops->len; i++)
{
GtkSymbolicColor *color;
ColorStop *stop;
stop = &g_array_index (gradient->stops, ColorStop, i);
color = gtk_symbolic_color_new_alpha (stop->color, opacity);
gtk_gradient_add_color_stop (faded, stop->offset, color);
gtk_symbolic_color_unref (color);
}
return faded;
}
GtkGradient *
_gtk_gradient_transition (GtkGradient *start,
GtkGradient *end,
guint property_id,
double progress)
{
GtkGradient *gradient;
guint i;
g_return_val_if_fail (start != NULL, NULL);
if (end == NULL)
return gtk_gradient_fade (start, 1.0 - CLAMP (progress, 0.0, 1.0));
if (start->stops->len != end->stops->len)
return NULL;
/* check both are radial/linear */
if ((start->radius0 == 0 && start->radius1 == 0) != (end->radius0 == 0 && end->radius1 == 0))
return NULL;
gradient = g_slice_new (GtkGradient);
gradient->stops = g_array_new (FALSE, FALSE, sizeof (ColorStop));
gradient->x0 = (1 - progress) * start->x0 + progress * end->x0;
gradient->y0 = (1 - progress) * start->y0 + progress * end->y0;
gradient->x1 = (1 - progress) * start->x1 + progress * end->x1;
gradient->y1 = (1 - progress) * start->y1 + progress * end->y1;
gradient->radius0 = (1 - progress) * start->radius0 + progress * end->radius0;
gradient->radius1 = (1 - progress) * start->radius1 + progress * end->radius1;
gradient->ref_count = 1;
for (i = 0; i < start->stops->len; i++)
{
ColorStop *start_stop, *end_stop;
GtkSymbolicColor *color;
double offset;
start_stop = &g_array_index (start->stops, ColorStop, i);
end_stop = &g_array_index (end->stops, ColorStop, i);
offset = (1 - progress) * start_stop->offset + progress * end_stop->offset;
color = gtk_symbolic_color_new_mix (start_stop->color,
end_stop->color,
progress);
gtk_gradient_add_color_stop (gradient, offset, color);
gtk_symbolic_color_unref (color);
}
return gradient;
}

View File

@ -1,65 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2010 Carlos Garnacho <carlosg@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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_GRADIENT_H__
#define __GTK_GRADIENT_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
#include <gtk/deprecated/gtksymboliccolor.h>
G_BEGIN_DECLS
typedef struct _GtkGradient GtkGradient;
#define GTK_TYPE_GRADIENT (gtk_gradient_get_type ())
GDK_DEPRECATED_IN_3_8
GType gtk_gradient_get_type (void) G_GNUC_CONST;
GDK_DEPRECATED_IN_3_8
GtkGradient * gtk_gradient_new_linear (gdouble x0,
gdouble y0,
gdouble x1,
gdouble y1);
GDK_DEPRECATED_IN_3_8
GtkGradient * gtk_gradient_new_radial (gdouble x0,
gdouble y0,
gdouble radius0,
gdouble x1,
gdouble y1,
gdouble radius1);
GDK_DEPRECATED_IN_3_8
void gtk_gradient_add_color_stop (GtkGradient *gradient,
gdouble offset,
GtkSymbolicColor *color);
GDK_DEPRECATED_IN_3_8
GtkGradient * gtk_gradient_ref (GtkGradient *gradient);
GDK_DEPRECATED_IN_3_8
void gtk_gradient_unref (GtkGradient *gradient);
GDK_DEPRECATED_IN_3_8
char * gtk_gradient_to_string (GtkGradient *gradient);
G_END_DECLS
#endif /* __GTK_GRADIENT_H__ */

View File

@ -1,38 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2012 Benjamin Otte <otte@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_GRADIENT_PRIVATE_H__
#define __GTK_GRADIENT_PRIVATE_H__
#include "gtkgradient.h"
#include "gtkcsstypesprivate.h"
G_BEGIN_DECLS
cairo_pattern_t * _gtk_gradient_resolve_full (GtkGradient *gradient,
GtkStyleProviderPrivate *provider,
GtkCssStyle *style,
GtkCssStyle *parent_style);
GtkGradient * _gtk_gradient_transition (GtkGradient *start,
GtkGradient *end,
guint property_id,
double progress);
G_END_DECLS
#endif /* __GTK_STYLE_PROPERTIES_PRIVATE_H__ */

View File

@ -242,7 +242,6 @@
#include <gtk/gtkwindowgroup.h>
#ifndef GTK_DISABLE_DEPRECATED
#include <gtk/deprecated/gtkgradient.h>
#include <gtk/deprecated/gtksymboliccolor.h>
#endif /* GTK_DISABLE_DEPRECATED */

View File

@ -25,7 +25,6 @@
/* for the types only */
#include "gtk/gtkcssimagecrossfadeprivate.h"
#include "gtk/gtkcssimagegradientprivate.h"
#include "gtk/gtkcssimageiconthemeprivate.h"
#include "gtk/gtkcssimagelinearprivate.h"
#include "gtk/gtkcssimageradialprivate.h"
@ -418,7 +417,6 @@ gtk_css_image_get_parser_type (GtkCssParser *parser)
GType (* type_func) (void);
} image_types[] = {
{ "url", _gtk_css_image_url_get_type },
{ "-gtk-gradient", _gtk_css_image_gradient_get_type },
{ "-gtk-icontheme", _gtk_css_image_icon_theme_get_type },
{ "-gtk-scaled", _gtk_css_image_scaled_get_type },
{ "-gtk-recolor", _gtk_css_image_recolor_get_type },

View File

@ -1,507 +0,0 @@
/*
* Copyright © 2011 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: Benjamin Otte <otte@gnome.org>
*/
#include "config.h"
#define GDK_DISABLE_DEPRECATION_WARNINGS
#include "gtkcssimagegradientprivate.h"
#include "gtkcssprovider.h"
#include "deprecated/gtkgradientprivate.h"
#include "deprecated/gtksymboliccolorprivate.h"
G_DEFINE_TYPE (GtkCssImageGradient, _gtk_css_image_gradient, GTK_TYPE_CSS_IMAGE)
static GtkCssImage *
gtk_css_image_gradient_compute (GtkCssImage *image,
guint property_id,
GtkStyleProviderPrivate *provider,
GtkCssStyle *style,
GtkCssStyle *parent_style)
{
GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);
GtkCssImageGradient *copy;
if (gradient->pattern)
return g_object_ref (gradient);
copy = g_object_new (GTK_TYPE_CSS_IMAGE_GRADIENT, NULL);
copy->gradient = gtk_gradient_ref (gradient->gradient);
copy->pattern = _gtk_gradient_resolve_full (copy->gradient, provider, style, parent_style);
return GTK_CSS_IMAGE (copy);
}
static cairo_pattern_t *
fade_pattern (cairo_pattern_t *pattern,
double opacity)
{
double x0, y0, x1, y1, r0, r1;
cairo_pattern_t *result;
int i, n;
switch (cairo_pattern_get_type (pattern))
{
case CAIRO_PATTERN_TYPE_LINEAR:
cairo_pattern_get_linear_points (pattern, &x0, &y0, &x1, &y1);
result = cairo_pattern_create_linear (x0, y0, x1, y1);
break;
case CAIRO_PATTERN_TYPE_RADIAL:
cairo_pattern_get_radial_circles (pattern, &x0, &y0, &r0, &x1, &y1, &r1);
result = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
break;
default:
g_return_val_if_reached (NULL);
}
cairo_pattern_get_color_stop_count (pattern, &n);
for (i = 0; i < n; i++)
{
double o, r, g, b, a;
cairo_pattern_get_color_stop_rgba (pattern, i, &o, &r, &g, &b, &a);
cairo_pattern_add_color_stop_rgba (result, o, r, g, b, a * opacity);
}
return result;
}
static cairo_pattern_t *
transition_pattern (cairo_pattern_t *start,
cairo_pattern_t *end,
double progress)
{
double sx0, sy0, sx1, sy1, sr0, sr1, ex0, ey0, ex1, ey1, er0, er1;
cairo_pattern_t *result;
int i, n;
progress = CLAMP (progress, 0.0, 1.0);
if (end == NULL)
return fade_pattern (start, 1.0 - progress);
g_assert (cairo_pattern_get_type (start) == cairo_pattern_get_type (end));
switch (cairo_pattern_get_type (start))
{
case CAIRO_PATTERN_TYPE_LINEAR:
cairo_pattern_get_linear_points (start, &sx0, &sy0, &sx1, &sy1);
cairo_pattern_get_linear_points (end, &ex0, &ey0, &ex1, &ey1);
result = cairo_pattern_create_linear ((1 - progress) * sx0 + progress * ex0,
(1 - progress) * sx1 + progress * ex1,
(1 - progress) * sy0 + progress * ey0,
(1 - progress) * sy1 + progress * ey1);
break;
case CAIRO_PATTERN_TYPE_RADIAL:
cairo_pattern_get_radial_circles (start, &sx0, &sy0, &sr0, &sx1, &sy1, &sr1);
cairo_pattern_get_radial_circles (end, &ex0, &ey0, &er0, &ex1, &ey1, &er1);
result = cairo_pattern_create_radial ((1 - progress) * sx0 + progress * ex0,
(1 - progress) * sy0 + progress * ey0,
(1 - progress) * sr0 + progress * er0,
(1 - progress) * sx1 + progress * ex1,
(1 - progress) * sy1 + progress * ey1,
(1 - progress) * sr1 + progress * er1);
break;
default:
g_return_val_if_reached (NULL);
}
cairo_pattern_get_color_stop_count (start, &n);
for (i = 0; i < n; i++)
{
double so, sr, sg, sb, sa, eo, er, eg, eb, ea;
cairo_pattern_get_color_stop_rgba (start, i, &so, &sr, &sg, &sb, &sa);
cairo_pattern_get_color_stop_rgba (end, i, &eo, &er, &eg, &eb, &ea);
cairo_pattern_add_color_stop_rgba (result,
(1 - progress) * so + progress * eo,
(1 - progress) * sr + progress * er,
(1 - progress) * sg + progress * eg,
(1 - progress) * sb + progress * eb,
(1 - progress) * sa + progress * ea);
}
return result;
}
static GtkCssImage *
gtk_css_image_gradient_transition (GtkCssImage *start_image,
GtkCssImage *end_image,
guint property_id,
double progress)
{
GtkGradient *start_gradient, *end_gradient, *gradient;
cairo_pattern_t *start_pattern, *end_pattern;
GtkCssImageGradient *result;
start_gradient = GTK_CSS_IMAGE_GRADIENT (start_image)->gradient;
start_pattern = GTK_CSS_IMAGE_GRADIENT (start_image)->pattern;
if (end_image == NULL)
{
end_gradient = NULL;
end_pattern = NULL;
}
else
{
if (!GTK_IS_CSS_IMAGE_GRADIENT (end_image))
return GTK_CSS_IMAGE_CLASS (_gtk_css_image_gradient_parent_class)->transition (start_image, end_image, property_id, progress);
end_gradient = GTK_CSS_IMAGE_GRADIENT (end_image)->gradient;
end_pattern = GTK_CSS_IMAGE_GRADIENT (end_image)->pattern;
}
gradient = _gtk_gradient_transition (start_gradient, end_gradient, property_id, progress);
if (gradient == NULL)
return GTK_CSS_IMAGE_CLASS (_gtk_css_image_gradient_parent_class)->transition (start_image, end_image, property_id, progress);
result = g_object_new (GTK_TYPE_CSS_IMAGE_GRADIENT, NULL);
result->gradient = gradient;
result->pattern = transition_pattern (start_pattern, end_pattern, progress);
return GTK_CSS_IMAGE (result);
}
static gboolean
gtk_css_image_gradient_draw_circle (GtkCssImageGradient *image,
cairo_t *cr,
double width,
double height)
{
cairo_pattern_t *pattern = image->pattern;
double x0, y0, x1, y1, r0, r1;
GdkRGBA color0, color1;
double offset0, offset1;
int n_stops;
if (cairo_pattern_get_type (pattern) != CAIRO_PATTERN_TYPE_RADIAL)
return FALSE;
if (cairo_pattern_get_extend (pattern) != CAIRO_EXTEND_PAD)
return FALSE;
cairo_pattern_get_radial_circles (pattern, &x0, &y0, &r0, &x1, &y1, &r1);
if (x0 != x1 ||
y0 != y1 ||
r0 != 0.0)
return FALSE;
cairo_pattern_get_color_stop_count (pattern, &n_stops);
if (n_stops != 2)
return FALSE;
cairo_pattern_get_color_stop_rgba (pattern, 0, &offset0, &color0.red, &color0.green, &color0.blue, &color0.alpha);
cairo_pattern_get_color_stop_rgba (pattern, 1, &offset1, &color1.red, &color1.green, &color1.blue, &color1.alpha);
if (offset0 != offset1)
return FALSE;
cairo_scale (cr, width, height);
cairo_rectangle (cr, 0, 0, 1, 1);
cairo_clip (cr);
gdk_cairo_set_source_rgba (cr, &color1);
cairo_paint (cr);
gdk_cairo_set_source_rgba (cr, &color0);
cairo_arc (cr, x1, y1, r1 * offset1, 0, 2 * G_PI);
cairo_fill (cr);
return TRUE;
}
static void
gtk_css_image_gradient_draw (GtkCssImage *image,
cairo_t *cr,
double width,
double height)
{
GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);
if (!gradient->pattern)
{
g_warning ("trying to paint unresolved gradient");
return;
}
if (gtk_css_image_gradient_draw_circle (gradient, cr, width, height))
return;
cairo_scale (cr, width, height);
cairo_rectangle (cr, 0, 0, 1, 1);
cairo_set_source (cr, gradient->pattern);
cairo_fill (cr);
}
static gboolean
gtk_css_image_gradient_parse (GtkCssImage *image,
GtkCssParser *parser)
{
GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);
gradient->gradient = _gtk_gradient_parse (parser);
return gradient->gradient != NULL;
}
static void
gtk_css_image_gradient_print (GtkCssImage *image,
GString *string)
{
GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);
char *s;
s = gtk_gradient_to_string (gradient->gradient);
g_string_append (string, s);
g_free (s);
}
static void
gtk_css_image_gradient_dispose (GObject *object)
{
GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (object);
if (gradient->gradient)
{
gtk_gradient_unref (gradient->gradient);
gradient->gradient = NULL;
}
if (gradient->pattern)
{
cairo_pattern_destroy (gradient->pattern);
gradient->pattern = NULL;
}
G_OBJECT_CLASS (_gtk_css_image_gradient_parent_class)->dispose (object);
}
static void
_gtk_css_image_gradient_class_init (GtkCssImageGradientClass *klass)
{
GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
image_class->compute = gtk_css_image_gradient_compute;
image_class->transition = gtk_css_image_gradient_transition;
image_class->draw = gtk_css_image_gradient_draw;
image_class->parse = gtk_css_image_gradient_parse;
image_class->print = gtk_css_image_gradient_print;
object_class->dispose = gtk_css_image_gradient_dispose;
}
static void
_gtk_css_image_gradient_init (GtkCssImageGradient *image_gradient)
{
}
GtkGradient *
_gtk_gradient_parse (GtkCssParser *parser)
{
GtkGradient *gradient;
cairo_pattern_type_t type;
gdouble coords[6];
guint i;
g_return_val_if_fail (parser != NULL, NULL);
if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
{
_gtk_css_parser_error (parser,
"Expected '-gtk-gradient'");
return NULL;
}
if (!_gtk_css_parser_try (parser, "(", TRUE))
{
_gtk_css_parser_error (parser,
"Expected '(' after '-gtk-gradient'");
return NULL;
}
/* Parse gradient type */
if (_gtk_css_parser_try (parser, "linear", TRUE))
type = CAIRO_PATTERN_TYPE_LINEAR;
else if (_gtk_css_parser_try (parser, "radial", TRUE))
type = CAIRO_PATTERN_TYPE_RADIAL;
else
{
_gtk_css_parser_error (parser,
"Gradient type must be 'radial' or 'linear'");
return NULL;
}
/* Parse start/stop position parameters */
for (i = 0; i < 2; i++)
{
if (! _gtk_css_parser_try (parser, ",", TRUE))
{
_gtk_css_parser_error (parser,
"Expected ','");
return NULL;
}
if (_gtk_css_parser_try (parser, "left", TRUE))
coords[i * 3] = 0;
else if (_gtk_css_parser_try (parser, "right", TRUE))
coords[i * 3] = 1;
else if (_gtk_css_parser_try (parser, "center", TRUE))
coords[i * 3] = 0.5;
else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
{
_gtk_css_parser_error (parser,
"Expected a valid X coordinate");
return NULL;
}
if (_gtk_css_parser_try (parser, "top", TRUE))
coords[i * 3 + 1] = 0;
else if (_gtk_css_parser_try (parser, "bottom", TRUE))
coords[i * 3 + 1] = 1;
else if (_gtk_css_parser_try (parser, "center", TRUE))
coords[i * 3 + 1] = 0.5;
else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
{
_gtk_css_parser_error (parser,
"Expected a valid Y coordinate");
return NULL;
}
if (type == CAIRO_PATTERN_TYPE_RADIAL)
{
/* Parse radius */
if (! _gtk_css_parser_try (parser, ",", TRUE))
{
_gtk_css_parser_error (parser,
"Expected ','");
return NULL;
}
if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
{
_gtk_css_parser_error (parser,
"Expected a number for the radius");
return NULL;
}
}
}
if (type == CAIRO_PATTERN_TYPE_LINEAR)
gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
else
gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
coords[3], coords[4], coords[5]);
while (_gtk_css_parser_try (parser, ",", TRUE))
{
GtkSymbolicColor *color;
gdouble position;
if (_gtk_css_parser_try (parser, "from", TRUE))
{
position = 0;
if (!_gtk_css_parser_try (parser, "(", TRUE))
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Expected '('");
return NULL;
}
}
else if (_gtk_css_parser_try (parser, "to", TRUE))
{
position = 1;
if (!_gtk_css_parser_try (parser, "(", TRUE))
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Expected '('");
return NULL;
}
}
else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
{
if (!_gtk_css_parser_try (parser, "(", TRUE))
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Expected '('");
return NULL;
}
if (!_gtk_css_parser_try_double (parser, &position))
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Expected a valid number");
return NULL;
}
if (!_gtk_css_parser_try (parser, ",", TRUE))
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Expected a comma");
return NULL;
}
}
else
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Not a valid color-stop definition");
return NULL;
}
color = _gtk_css_symbolic_value_new (parser);
if (color == NULL)
{
gtk_gradient_unref (gradient);
return NULL;
}
gtk_gradient_add_color_stop (gradient, position, color);
gtk_symbolic_color_unref (color);
if (!_gtk_css_parser_try (parser, ")", TRUE))
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Expected ')'");
return NULL;
}
}
if (!_gtk_css_parser_try (parser, ")", TRUE))
{
gtk_gradient_unref (gradient);
_gtk_css_parser_error (parser,
"Expected ')'");
return NULL;
}
return gradient;
}

View File

@ -1,59 +0,0 @@
/*
* Copyright © 2011 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: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_CSS_IMAGE_GRADIENT_PRIVATE_H__
#define __GTK_CSS_IMAGE_GRADIENT_PRIVATE_H__
#include "gtk/gtkcssimageprivate.h"
#include <gtk/deprecated/gtkgradient.h>
G_BEGIN_DECLS
#define GTK_TYPE_CSS_IMAGE_GRADIENT (_gtk_css_image_gradient_get_type ())
#define GTK_CSS_IMAGE_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_IMAGE_GRADIENT, GtkCssImageGradient))
#define GTK_CSS_IMAGE_GRADIENT_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_IMAGE_GRADIENT, GtkCssImageGradientClass))
#define GTK_IS_CSS_IMAGE_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_IMAGE_GRADIENT))
#define GTK_IS_CSS_IMAGE_GRADIENT_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_IMAGE_GRADIENT))
#define GTK_CSS_IMAGE_GRADIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_IMAGE_GRADIENT, GtkCssImageGradientClass))
typedef struct _GtkCssImageGradient GtkCssImageGradient;
typedef struct _GtkCssImageGradientClass GtkCssImageGradientClass;
struct _GtkCssImageGradient
{
GtkCssImage parent;
GtkGradient *gradient;
cairo_pattern_t *pattern; /* the resolved gradient */
};
struct _GtkCssImageGradientClass
{
GtkCssImageClass parent_class;
};
GType _gtk_css_image_gradient_get_type (void) G_GNUC_CONST;
/* for lack of a better place to put it */
GtkGradient * _gtk_gradient_parse (GtkCssParser *parser);
G_END_DECLS
#endif /* __GTK_CSS_IMAGE_GRADIENT_PRIVATE_H__ */

View File

@ -28,7 +28,6 @@
#include <cairo-gobject.h>
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssimagegradientprivate.h"
#include "gtkcssprovider.h"
#include "gtkcssrgbavalueprivate.h"
#include "gtkcsstypesprivate.h"
@ -37,7 +36,6 @@
#include "gtktypebuiltins.h"
#include "gtkcsswin32sizevalueprivate.h"
#include "deprecated/gtkgradientprivate.h"
#include "deprecated/gtksymboliccolorprivate.h"
/* this is in case round() is not provided by the compiler,
@ -475,40 +473,6 @@ border_value_print (const GValue *value, GString *string)
g_string_append_printf (string, "%d", border->top);
}
static gboolean
gradient_value_parse (GtkCssParser *parser,
GValue *value)
{
GtkGradient *gradient;
gradient = _gtk_gradient_parse (parser);
if (gradient == NULL)
return FALSE;
g_value_take_boxed (value, gradient);
return TRUE;
}
static void
gradient_value_print (const GValue *value,
GString *string)
{
GtkGradient *gradient = g_value_get_boxed (value);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
if (gradient == NULL)
g_string_append (string, "none");
else
{
char *s = gtk_gradient_to_string (gradient);
g_string_append (string, s);
g_free (s);
}
G_GNUC_END_IGNORE_DEPRECATIONS;
}
static gboolean
pattern_value_parse (GtkCssParser *parser,
GValue *value)
@ -517,17 +481,6 @@ pattern_value_parse (GtkCssParser *parser,
{
/* nothing to do here */
}
else if (_gtk_css_parser_begins_with (parser, '-'))
{
g_value_unset (value);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
g_value_init (value, GTK_TYPE_GRADIENT);
return gradient_value_parse (parser, value);
G_GNUC_END_IGNORE_DEPRECATIONS;
}
else
{
GError *error = NULL;
@ -778,15 +731,6 @@ gtk_css_style_funcs_init (void)
register_conversion_function (GTK_TYPE_BORDER,
border_value_parse,
border_value_print);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
register_conversion_function (GTK_TYPE_GRADIENT,
gradient_value_parse,
gradient_value_print);
G_GNUC_END_IGNORE_DEPRECATIONS;
register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
pattern_value_parse,
pattern_value_print);

View File

@ -47,7 +47,6 @@
#include "gtkcssiconthemevalueprivate.h"
#include "gtkcssimageprivate.h"
#include "gtkcssimagebuiltinprivate.h"
#include "gtkcssimagegradientprivate.h"
#include "gtkcssimagevalueprivate.h"
#include "gtkcssinitialvalueprivate.h"
#include "gtkcssenumvalueprivate.h"
@ -607,12 +606,10 @@ css_image_value_query (GtkCssStyleProperty *property,
cairo_pattern_t *pattern;
cairo_surface_t *surface;
cairo_matrix_t matrix;
g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
if (GTK_IS_CSS_IMAGE_GRADIENT (image))
g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern);
else if (image != NULL)
if (image != NULL)
{
double width, height;

View File

@ -55,7 +55,6 @@
#include "gtkwidgetpath.h"
#include "gtkwidgetprivate.h"
#include "deprecated/gtkgradientprivate.h"
#include "deprecated/gtksymboliccolorprivate.h"
#include "fallback-c89.c"