shadow: Add equal and transition support

... and enable transitions for the shadow properties.
This commit is contained in:
Benjamin Otte 2012-04-03 15:33:00 +02:00
parent ac6d61f6bb
commit c366b5b8b7
4 changed files with 82 additions and 8 deletions

View File

@ -31,6 +31,9 @@ struct _GtkCssValue {
GtkCssValue *values[1]; GtkCssValue *values[1];
}; };
static GtkCssValue * gtk_css_shadows_value_new (GtkCssValue **values,
guint len);
static void static void
gtk_css_value_shadows_free (GtkCssValue *value) gtk_css_value_shadows_free (GtkCssValue *value)
{ {
@ -69,7 +72,42 @@ gtk_css_value_shadows_transition (GtkCssValue *start,
GtkCssValue *end, GtkCssValue *end,
double progress) double progress)
{ {
return NULL; GtkCssValue *result;
guint i;
/* catches the important case of 2 none values */
if (start == end)
return _gtk_css_value_ref (start);
if (start->len > end->len)
result = gtk_css_shadows_value_new (start->values, start->len);
else
result = gtk_css_shadows_value_new (end->values, end->len);
for (i = 0; i < MIN (start->len, end->len); i++)
{
result->values[i] = _gtk_css_value_transition (start->values[i], end->values[i], progress);
}
if (start->len > end->len)
{
for (; i < result->len; i++)
{
GtkCssValue *fill = _gtk_css_shadow_value_new_for_transition (start->values[i]);
result->values[i] = _gtk_css_value_transition (start->values[i], fill, progress);
_gtk_css_value_unref (fill);
}
}
else
{
for (; i < result->len; i++)
{
GtkCssValue *fill = _gtk_css_shadow_value_new_for_transition (end->values[i]);
result->values[i] = _gtk_css_value_transition (fill, end->values[i], progress);
_gtk_css_value_unref (fill);
}
}
return result;
} }
static void static void
@ -107,7 +145,7 @@ _gtk_css_shadows_value_new_none (void)
return _gtk_css_value_ref (&none_singleton); return _gtk_css_value_ref (&none_singleton);
} }
GtkCssValue * static GtkCssValue *
gtk_css_shadows_value_new (GtkCssValue **values, gtk_css_shadows_value_new (GtkCssValue **values,
guint len) guint len)
{ {

View File

@ -40,6 +40,13 @@ struct _GtkCssValue {
GtkCssValue *color; GtkCssValue *color;
}; };
static GtkCssValue * gtk_css_shadow_value_new (GtkCssValue *hoffset,
GtkCssValue *voffset,
GtkCssValue *radius,
GtkCssValue *spread,
gboolean inset,
GtkCssValue *color);
static void static void
gtk_css_value_shadow_free (GtkCssValue *shadow) gtk_css_value_shadow_free (GtkCssValue *shadow)
{ {
@ -56,8 +63,12 @@ static gboolean
gtk_css_value_shadow_equal (const GtkCssValue *shadow1, gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
const GtkCssValue *shadow2) const GtkCssValue *shadow2)
{ {
/* FIXME */ return shadow1->inset == shadow2->inset
return shadow1 == shadow2; && _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);
} }
static GtkCssValue * static GtkCssValue *
@ -65,7 +76,15 @@ gtk_css_value_shadow_transition (GtkCssValue *start,
GtkCssValue *end, GtkCssValue *end,
double progress) double progress)
{ {
return NULL; if (start->inset != end->inset)
return NULL;
return gtk_css_shadow_value_new (_gtk_css_value_transition (start->hoffset, end->hoffset, progress),
_gtk_css_value_transition (start->voffset, end->voffset, progress),
_gtk_css_value_transition (start->radius, end->radius, progress),
_gtk_css_value_transition (start->spread, end->spread, progress),
start->inset,
_gtk_css_value_transition (start->color, end->color, progress));
} }
static void static void
@ -125,6 +144,21 @@ gtk_css_shadow_value_new (GtkCssValue *hoffset,
return retval; return retval;
} }
GtkCssValue *
_gtk_css_shadow_value_new_for_transition (GtkCssValue *target)
{
GdkRGBA transparent = { 0, 0, 0, 0 };
g_return_val_if_fail (target->class == &GTK_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));
}
static gboolean static gboolean
value_is_done_parsing (GtkCssParser *parser) value_is_done_parsing (GtkCssParser *parser)
{ {

View File

@ -30,6 +30,8 @@
G_BEGIN_DECLS G_BEGIN_DECLS
GtkCssValue * _gtk_css_shadow_value_new_for_transition (GtkCssValue *target);
GtkCssValue * _gtk_css_shadow_value_parse (GtkCssParser *parser); GtkCssValue * _gtk_css_shadow_value_parse (GtkCssParser *parser);
GtkCssValue * _gtk_css_shadow_value_compute (GtkCssValue *shadow, GtkCssValue * _gtk_css_shadow_value_compute (GtkCssValue *shadow,

View File

@ -1330,7 +1330,7 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("text-shadow", gtk_css_style_property_register ("text-shadow",
GTK_CSS_PROPERTY_TEXT_SHADOW, GTK_CSS_PROPERTY_TEXT_SHADOW,
G_TYPE_NONE, G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
shadow_value_parse, shadow_value_parse,
NULL, NULL,
shadow_value_compute, shadow_value_compute,
@ -1342,7 +1342,7 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("icon-shadow", gtk_css_style_property_register ("icon-shadow",
GTK_CSS_PROPERTY_ICON_SHADOW, GTK_CSS_PROPERTY_ICON_SHADOW,
G_TYPE_NONE, G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
shadow_value_parse, shadow_value_parse,
NULL, NULL,
shadow_value_compute, shadow_value_compute,
@ -1354,7 +1354,7 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("box-shadow", gtk_css_style_property_register ("box-shadow",
GTK_CSS_PROPERTY_BOX_SHADOW, GTK_CSS_PROPERTY_BOX_SHADOW,
G_TYPE_NONE, G_TYPE_NONE,
0, GTK_STYLE_PROPERTY_ANIMATED,
shadow_value_parse, shadow_value_parse,
NULL, NULL,
shadow_value_compute, shadow_value_compute,