diff options
-rw-r--r-- | gtk/gtkcssanimatedstyle.c | 5 | ||||
-rw-r--r-- | gtk/gtkcsstransition.c | 39 | ||||
-rw-r--r-- | gtk/gtkcsstransitionprivate.h | 15 |
3 files changed, 32 insertions, 27 deletions
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c index 2c92fa7463..e3a22604cc 100644 --- a/gtk/gtkcssanimatedstyle.c +++ b/gtk/gtkcssanimatedstyle.c @@ -301,8 +301,9 @@ gtk_css_animated_style_create_css_transitions (GSList *animations, animation = _gtk_css_transition_new (i, gtk_css_style_get_value (source, i), _gtk_css_array_value_get_nth (timing_functions, i), - timestamp + delay * G_USEC_PER_SEC, - timestamp + (delay + duration) * G_USEC_PER_SEC); + timestamp, + duration * G_USEC_PER_SEC, + delay * G_USEC_PER_SEC); animations = g_slist_prepend (animations, animation); } diff --git a/gtk/gtkcsstransition.c b/gtk/gtkcsstransition.c index 747bac1dc7..c9b319736c 100644 --- a/gtk/gtkcsstransition.c +++ b/gtk/gtkcsstransition.c @@ -22,6 +22,7 @@ #include "gtkcsstransitionprivate.h" #include "gtkcsseasevalueprivate.h" +#include "gtkprogresstrackerprivate.h" G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION) @@ -33,31 +34,33 @@ gtk_css_transition_set_values (GtkStyleAnimation *animation, GtkCssTransition *transition = GTK_CSS_TRANSITION (animation); GtkCssValue *value, *end; double progress; + GtkProgressState state; end = gtk_css_animated_style_get_intrinsic_value (style, transition->property); - if (transition->start_time >= for_time_us) + gtk_progress_tracker_advance_frame (&transition->tracker, for_time_us); + state = gtk_progress_tracker_get_state (&transition->tracker); + + if (state == GTK_PROGRESS_STATE_BEFORE) value = _gtk_css_value_ref (transition->start); - else if (transition->end_time > for_time_us) + else if (state == GTK_PROGRESS_STATE_DURING) { - progress = (double) (for_time_us - transition->start_time) / (transition->end_time - transition->start_time); + progress = gtk_progress_tracker_get_progress (&transition->tracker, FALSE); progress = _gtk_css_ease_value_transform (transition->ease, progress); value = _gtk_css_value_transition (transition->start, end, transition->property, progress); - if (value == NULL) - value = _gtk_css_value_ref (end); } else - value = NULL; + return; - if (value) - { - gtk_css_animated_style_set_animated_value (style, transition->property, value); - _gtk_css_value_unref (value); - } + if (value == NULL) + value = _gtk_css_value_ref (end); + + gtk_css_animated_style_set_animated_value (style, transition->property, value); + _gtk_css_value_unref (value); } static gboolean @@ -66,7 +69,7 @@ gtk_css_transition_is_finished (GtkStyleAnimation *animation, { GtkCssTransition *transition = GTK_CSS_TRANSITION (animation); - return at_time_us >= transition->end_time; + return gtk_progress_tracker_get_state (&transition->tracker) == GTK_PROGRESS_STATE_AFTER; } static gboolean @@ -75,7 +78,7 @@ gtk_css_transition_is_static (GtkStyleAnimation *animation, { GtkCssTransition *transition = GTK_CSS_TRANSITION (animation); - return at_time_us >= transition->end_time; + return gtk_progress_tracker_get_state (&transition->tracker) == GTK_PROGRESS_STATE_AFTER; } static void @@ -111,22 +114,22 @@ GtkStyleAnimation * _gtk_css_transition_new (guint property, GtkCssValue *start, GtkCssValue *ease, - gint64 start_time_us, - gint64 end_time_us) + gint64 timestamp, + gint64 duration_us, + gint64 delay_us) { GtkCssTransition *transition; g_return_val_if_fail (start != NULL, NULL); g_return_val_if_fail (ease != NULL, NULL); - g_return_val_if_fail (start_time_us <= end_time_us, NULL); transition = g_object_new (GTK_TYPE_CSS_TRANSITION, NULL); transition->property = property; transition->start = _gtk_css_value_ref (start); transition->ease = _gtk_css_value_ref (ease); - transition->start_time = start_time_us; - transition->end_time = end_time_us; + gtk_progress_tracker_start (&transition->tracker, duration_us, delay_us, 1.0); + gtk_progress_tracker_advance_frame (&transition->tracker, timestamp); return GTK_STYLE_ANIMATION (transition); } diff --git a/gtk/gtkcsstransitionprivate.h b/gtk/gtkcsstransitionprivate.h index 2d075b01df..822a8246d9 100644 --- a/gtk/gtkcsstransitionprivate.h +++ b/gtk/gtkcsstransitionprivate.h @@ -21,6 +21,7 @@ #define __GTK_CSS_TRANSITION_PRIVATE_H__ #include "gtkstyleanimationprivate.h" +#include "gtkprogresstrackerprivate.h" G_BEGIN_DECLS @@ -38,11 +39,10 @@ struct _GtkCssTransition { GtkStyleAnimation parent; - guint property; - GtkCssValue *start; - GtkCssValue *ease; - gint64 start_time; - gint64 end_time; + guint property; + GtkCssValue *start; + GtkCssValue *ease; + GtkProgressTracker tracker; }; struct _GtkCssTransitionClass @@ -55,8 +55,9 @@ GType _gtk_css_transition_get_type (void) G_GNUC_CONST; GtkStyleAnimation * _gtk_css_transition_new (guint property, GtkCssValue *start, GtkCssValue *ease, - gint64 start_time_us, - gint64 end_time_us); + gint64 timestamp, + gint64 duration_us, + gint64 delay_us); guint _gtk_css_transition_get_property (GtkCssTransition *transition); |