cssanimation: Recompute values while playing

This will be necessary for supporting variables in animations.

For this we need to pass all the gtk_css_value_compute() parameters into
GtkCssAnimatedStyle: parent style and provider.
This commit is contained in:
Alice Mikhaylenko 2023-11-21 23:59:40 +04:00
parent fed1c3d3fc
commit 14d7eb97d2
4 changed files with 69 additions and 12 deletions

View File

@ -96,6 +96,9 @@ gtk_css_animated_style_finalize (GObject *object)
GtkCssAnimatedStyle *style = GTK_CSS_ANIMATED_STYLE (object);
g_object_unref (style->style);
if (style->parent_style)
g_object_unref (style->parent_style);
g_object_unref (style->provider);
G_OBJECT_CLASS (gtk_css_animated_style_parent_class)->finalize (object);
}
@ -770,7 +773,6 @@ gtk_css_animated_style_find_animation (GtkStyleAnimation **animations,
static GPtrArray *
gtk_css_animated_style_create_css_animations (GPtrArray *animations,
GtkCssStyle *base_style,
GtkCssStyle *parent_style,
gint64 timestamp,
GtkStyleProvider *provider,
GtkCssStyle *source)
@ -832,8 +834,6 @@ gtk_css_animated_style_create_css_animations (GPtrArray *animations,
if (keyframes == NULL)
continue;
keyframes = _gtk_css_keyframes_compute (keyframes, provider, base_style, parent_style);
animation = _gtk_css_animation_new (name,
keyframes,
timestamp,
@ -844,7 +844,6 @@ gtk_css_animated_style_create_css_animations (GPtrArray *animations,
_gtk_css_play_state_value_get (_gtk_css_array_value_get_nth (play_states, i)),
_gtk_css_fill_mode_value_get (_gtk_css_array_value_get_nth (fill_modes, i)),
_gtk_css_number_value_get (_gtk_css_array_value_get_nth (iteration_counts, i), 100));
_gtk_css_keyframes_unref (keyframes);
}
if (!animations)
@ -893,7 +892,7 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
if (previous_style != NULL)
animations = gtk_css_animated_style_create_css_transitions (animations, base_style, timestamp, previous_style);
animations = gtk_css_animated_style_create_css_animations (animations, base_style, parent_style, timestamp, provider, previous_style);
animations = gtk_css_animated_style_create_css_animations (animations, base_style, timestamp, provider, previous_style);
animations = gtk_css_animated_style_create_dynamic (animations, base_style, timestamp);
if (animations == NULL)
@ -902,6 +901,9 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
result->style = g_object_ref (base_style);
if (parent_style)
result->parent_style = g_object_ref (parent_style);
result->provider = g_object_ref (provider);
result->current_time = timestamp;
result->n_animations = animations->len;
result->animations = g_ptr_array_free (animations, FALSE);
@ -927,7 +929,9 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
GtkCssStyle *
gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
GtkCssStyle *base_style,
gint64 timestamp)
GtkCssStyle *parent_style,
gint64 timestamp,
GtkStyleProvider *provider)
{
GtkCssAnimatedStyle *result;
GtkCssStyle *style;
@ -936,6 +940,8 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (source), NULL);
gtk_internal_return_val_if_fail (GTK_IS_CSS_STYLE (base_style), NULL);
gtk_internal_return_val_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style), NULL);
gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
if (timestamp == 0)
return g_object_ref (source->style);
@ -966,6 +972,9 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
result->style = g_object_ref (base_style);
if (parent_style)
result->parent_style = g_object_ref (parent_style);
result->provider = g_object_ref (provider);
result->current_time = timestamp;
result->n_animations = animations->len;
result->animations = g_ptr_array_free (animations, FALSE);
@ -987,3 +996,27 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
return GTK_CSS_STYLE (result);
}
GtkCssStyle *
gtk_css_animated_style_get_base_style (GtkCssAnimatedStyle *style)
{
gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), NULL);
return style->style;
}
GtkCssStyle *
gtk_css_animated_style_get_parent_style (GtkCssAnimatedStyle *style)
{
gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), NULL);
return style->parent_style;
}
GtkStyleProvider *
gtk_css_animated_style_get_provider (GtkCssAnimatedStyle *style)
{
gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), NULL);
return style->provider;
}

View File

@ -38,6 +38,8 @@ struct _GtkCssAnimatedStyle
GtkCssStyle parent;
GtkCssStyle *style; /* the style if we weren't animating */
GtkCssStyle *parent_style;
GtkStyleProvider *provider;
gint64 current_time; /* the current time in our world */
gpointer *animations; /* GtkStyleAnimation**, least important one first */
@ -57,8 +59,10 @@ GtkCssStyle * gtk_css_animated_style_new (GtkCssStyle
GtkStyleProvider *provider,
GtkCssStyle *previous_style);
GtkCssStyle * gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
GtkCssStyle *base,
gint64 timestamp);
GtkCssStyle *base_style,
GtkCssStyle *parent_style,
gint64 timestamp,
GtkStyleProvider *provider);
void gtk_css_animated_style_set_animated_value(GtkCssAnimatedStyle *style,
guint id,
@ -67,5 +71,9 @@ void gtk_css_animated_style_set_animated_value(GtkCssAnimated
GtkCssValue * gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style,
guint id);
GtkCssStyle * gtk_css_animated_style_get_base_style (GtkCssAnimatedStyle *style);
GtkCssStyle * gtk_css_animated_style_get_parent_style (GtkCssAnimatedStyle *style);
GtkStyleProvider * gtk_css_animated_style_get_provider (GtkCssAnimatedStyle *style);
G_END_DECLS

View File

@ -90,6 +90,9 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation,
GtkCssAnimatedStyle *style)
{
GtkCssAnimation *animation = (GtkCssAnimation *)style_animation;
GtkCssStyle *base_style, *parent_style;
GtkStyleProvider *provider;
GtkCssKeyframes *resolved_keyframes;
double progress;
guint i;
@ -99,19 +102,29 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation,
progress = gtk_css_animation_get_progress (animation);
progress = _gtk_css_ease_value_transform (animation->ease, progress);
for (i = 0; i < _gtk_css_keyframes_get_n_properties (animation->keyframes); i++)
base_style = gtk_css_animated_style_get_base_style (style);
parent_style = gtk_css_animated_style_get_parent_style (style);
provider = gtk_css_animated_style_get_provider (style);
resolved_keyframes = _gtk_css_keyframes_compute (animation->keyframes,
provider,
base_style,
parent_style);
for (i = 0; i < _gtk_css_keyframes_get_n_properties (resolved_keyframes); i++)
{
GtkCssValue *value;
guint property_id;
property_id = _gtk_css_keyframes_get_property_id (animation->keyframes, i);
property_id = _gtk_css_keyframes_get_property_id (resolved_keyframes, i);
value = _gtk_css_keyframes_get_value (animation->keyframes,
value = _gtk_css_keyframes_get_value (resolved_keyframes,
i,
progress,
gtk_css_animated_style_get_intrinsic_value (style, property_id));
gtk_css_animated_style_set_animated_value (style, property_id, value);
}
_gtk_css_keyframes_unref (resolved_keyframes);
}
static gboolean

View File

@ -445,9 +445,12 @@ gtk_css_node_real_update_style (GtkCssNode *cssnode,
}
else if (static_style != style && (change & GTK_CSS_CHANGE_TIMESTAMP))
{
GtkCssNode *parent = gtk_css_node_get_parent (cssnode);
new_style = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (style),
static_style,
timestamp);
parent ? gtk_css_node_get_style (parent) : NULL,
timestamp,
gtk_css_node_get_style_provider (cssnode));
}
else
{