cssvalue: Add _gtk_css_value_transition()

Returns a value that transitions between start and end or %NULL if the
values cannot be transitioned.

So far, all implementations but numbers and rgba return NULL.
This commit is contained in:
Benjamin Otte 2012-03-30 17:47:26 +02:00
parent bf92f2f7ac
commit 1a9dfab825
11 changed files with 128 additions and 0 deletions

View File

@ -59,6 +59,14 @@ gtk_css_value_array_equal (const GtkCssValue *value1,
return TRUE;
}
static GtkCssValue *
gtk_css_value_array_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_array_print (const GtkCssValue *value,
GString *string)
@ -82,6 +90,7 @@ gtk_css_value_array_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
gtk_css_value_array_free,
gtk_css_value_array_equal,
gtk_css_value_array_transition,
gtk_css_value_array_print
};

View File

@ -42,6 +42,14 @@ gtk_css_value_enum_equal (const GtkCssValue *enum1,
return enum1 == enum2;
}
static GtkCssValue *
gtk_css_value_enum_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_enum_print (const GtkCssValue *value,
GString *string)
@ -54,6 +62,7 @@ gtk_css_value_enum_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_BORDER_STYLE = {
gtk_css_value_enum_free,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};
@ -107,6 +116,7 @@ _gtk_css_border_style_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
gtk_css_value_enum_free,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};
@ -153,6 +163,7 @@ _gtk_css_font_style_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT = {
gtk_css_value_enum_free,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};
@ -198,6 +209,7 @@ _gtk_css_font_variant_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
gtk_css_value_enum_free,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};
@ -261,6 +273,7 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
gtk_css_value_enum_free,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};

View File

@ -40,6 +40,14 @@ gtk_css_value_image_equal (const GtkCssValue *value1,
return value1->image == value2->image;
}
static GtkCssValue *
gtk_css_value_image_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_image_print (const GtkCssValue *value,
GString *string)
@ -53,6 +61,7 @@ gtk_css_value_image_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
gtk_css_value_image_free,
gtk_css_value_image_equal,
gtk_css_value_image_transition,
gtk_css_value_image_print
};

View File

@ -37,6 +37,14 @@ gtk_css_value_inherit_equal (const GtkCssValue *value1,
return TRUE;
}
static GtkCssValue *
gtk_css_value_inherit_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_inherit_print (const GtkCssValue *value,
GString *string)
@ -47,6 +55,7 @@ gtk_css_value_inherit_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
gtk_css_value_inherit_free,
gtk_css_value_inherit_equal,
gtk_css_value_inherit_transition,
gtk_css_value_inherit_print
};

View File

@ -37,6 +37,14 @@ gtk_css_value_initial_equal (const GtkCssValue *value1,
return TRUE;
}
static GtkCssValue *
gtk_css_value_initial_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_initial_print (const GtkCssValue *value,
GString *string)
@ -47,6 +55,7 @@ gtk_css_value_initial_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
gtk_css_value_initial_free,
gtk_css_value_initial_equal,
gtk_css_value_initial_transition,
gtk_css_value_initial_print
};

View File

@ -41,6 +41,20 @@ gtk_css_value_number_equal (const GtkCssValue *number1,
number1->value == number2->value;
}
static GtkCssValue *
gtk_css_value_number_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
/* FIXME: This needs to be supported at least for percentages,
* but for that we kinda need to support calc(5px + 50%) */
if (start->unit != end->unit)
return NULL;
return _gtk_css_number_value_new (start->value + (end->value - start->value) * progress,
start->unit);
}
static void
gtk_css_value_number_print (const GtkCssValue *number,
GString *string)
@ -73,6 +87,7 @@ gtk_css_value_number_print (const GtkCssValue *number,
static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = {
gtk_css_value_number_free,
gtk_css_value_number_equal,
gtk_css_value_number_transition,
gtk_css_value_number_print
};

View File

@ -40,6 +40,22 @@ gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
}
static GtkCssValue *
gtk_css_value_rgba_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
GdkRGBA transition;
progress = CLAMP (progress, 0, 1);
transition.red = start->rgba.red + (end->rgba.red - start->rgba.red) * progress;
transition.green = start->rgba.green + (end->rgba.green - start->rgba.green) * progress;
transition.blue = start->rgba.blue + (end->rgba.blue - start->rgba.blue) * progress;
transition.alpha = start->rgba.alpha + (end->rgba.alpha - start->rgba.alpha) * progress;
return _gtk_css_rgba_value_new_from_rgba (&transition);
}
static void
gtk_css_value_rgba_print (const GtkCssValue *rgba,
GString *string)
@ -52,6 +68,7 @@ gtk_css_value_rgba_print (const GtkCssValue *rgba,
static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
gtk_css_value_rgba_free,
gtk_css_value_rgba_equal,
gtk_css_value_rgba_transition,
gtk_css_value_rgba_print
};

View File

@ -129,6 +129,14 @@ gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
return shadow1 == shadow2;
}
static GtkCssValue *
gtk_css_value_shadow_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_shadow_print (const GtkCssValue *shadow,
GString *string)
@ -159,6 +167,7 @@ gtk_css_value_shadow_print (const GtkCssValue *shadow,
static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
gtk_css_value_shadow_free,
gtk_css_value_shadow_equal,
gtk_css_value_shadow_transition,
gtk_css_value_shadow_print
};

View File

@ -39,6 +39,14 @@ gtk_css_value_string_equal (const GtkCssValue *value1,
return g_strcmp0 (value1->string, value2->string) == 0;
}
static GtkCssValue *
gtk_css_value_string_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_string_print (const GtkCssValue *value,
GString *str)
@ -83,6 +91,7 @@ gtk_css_value_string_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
gtk_css_value_string_free,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
gtk_css_value_string_print
};

View File

@ -86,6 +86,14 @@ gtk_css_value_default_equal (const GtkCssValue *value1,
return FALSE;
}
static GtkCssValue *
gtk_css_value_default_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_default_print (const GtkCssValue *value,
GString *string)
@ -100,6 +108,7 @@ gtk_css_value_default_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_DEFAULT = {
gtk_css_value_default_free,
gtk_css_value_default_equal,
gtk_css_value_default_transition,
gtk_css_value_default_print
};
@ -395,6 +404,20 @@ _gtk_css_value_equal (const GtkCssValue *value1,
return value1->class->equal (value1, value2);
}
GtkCssValue *
_gtk_css_value_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
g_return_val_if_fail (start != NULL, FALSE);
g_return_val_if_fail (end != NULL, FALSE);
if (start->class != end->class)
return NULL;
return start->class->transition (start, end, progress);
}
void
_gtk_css_value_print (const GtkCssValue *value,
GString *string)

View File

@ -49,6 +49,9 @@ struct _GtkCssValueClass {
gboolean (* equal) (const GtkCssValue *value1,
const GtkCssValue *value2);
GtkCssValue * (* transition) (GtkCssValue *start,
GtkCssValue *end,
double progress);
void (* print) (const GtkCssValue *value,
GString *string);
};
@ -64,6 +67,9 @@ void _gtk_css_value_unref (GtkCssValue
gboolean _gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2);
GtkCssValue *_gtk_css_value_transition (GtkCssValue *start,
GtkCssValue *end,
double progress);
void _gtk_css_value_print (const GtkCssValue *value,
GString *string);