[gtk+/wip/watson/progress-tracker: 182/191] csstransition: port to progress tracker
- From: Matthew Watson <watson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/watson/progress-tracker: 182/191] csstransition: port to progress tracker
- Date: Fri, 25 Mar 2016 21:15:00 +0000 (UTC)
commit 1e0cc5e039ba5deb96bcf0a626aed71f59533e43
Author: Matt Watson <mattdangerw gmail com>
Date: Sun Mar 6 22:45:27 2016 -0800
csstransition: port to progress tracker
gtk/gtkcssanimatedstyle.c | 7 ++---
gtk/gtkcsstransition.c | 54 ++++++++++++++++++----------------------
gtk/gtkcsstransitionprivate.h | 14 +++++-----
3 files changed, 34 insertions(+), 41 deletions(-)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 2c92fa7..f7bcd6e 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -252,7 +252,6 @@ gtk_css_animated_style_find_transition (GtkCssAnimatedStyle *style,
static GSList *
gtk_css_animated_style_create_css_transitions (GSList *animations,
GtkCssStyle *base_style,
- gint64 timestamp,
GtkCssStyle *source)
{
TransitionInfo transitions[GTK_CSS_PROPERTY_N_PROPERTIES] = { { 0, } };
@@ -301,8 +300,8 @@ 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);
+ duration * G_USEC_PER_SEC,
+ delay * G_USEC_PER_SEC);
animations = g_slist_prepend (animations, animation);
}
@@ -436,7 +435,7 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
animations = NULL;
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_transitions (animations, base_style, previous_style);
animations = gtk_css_animated_style_create_css_animations (animations, base_style, parent_style,
timestamp, provider, previous_style);
if (animations == NULL)
diff --git a/gtk/gtkcsstransition.c b/gtk/gtkcsstransition.c
index 747bac1..a06ff23 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)
@@ -32,32 +33,27 @@ gtk_css_transition_set_values (GtkStyleAnimation *animation,
{
GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
GtkCssValue *value, *end;
- double progress;
+ double ease;
end = gtk_css_animated_style_get_intrinsic_value (style, transition->property);
- if (transition->start_time >= for_time_us)
- value = _gtk_css_value_ref (transition->start);
- else if (transition->end_time > for_time_us)
- {
- progress = (double) (for_time_us - transition->start_time) / (transition->end_time -
transition->start_time);
- 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;
-
- if (value)
- {
- gtk_css_animated_style_set_animated_value (style, transition->property, value);
- _gtk_css_value_unref (value);
- }
+ gtk_progress_tracker_next_frame (&transition->tracker, for_time_us);
+ if (gtk_progress_tracker_get_state (&transition->tracker) != GTK_PROGRESS_STATE_DURING)
+ return;
+
+ ease = gtk_progress_tracker_get_ease (&transition->tracker,
+ transition->ease,
+ FALSE);
+ value = _gtk_css_value_transition (transition->start,
+ end,
+ transition->property,
+ ease);
+
+ 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 +62,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 +71,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_iteration (&transition->tracker) == GTK_PROGRESS_STATE_AFTER;
}
static void
@@ -111,22 +107,20 @@ GtkStyleAnimation *
_gtk_css_transition_new (guint property,
GtkCssValue *start,
GtkCssValue *ease,
- gint64 start_time_us,
- gint64 end_time_us)
+ 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);
return GTK_STYLE_ANIMATION (transition);
}
diff --git a/gtk/gtkcsstransitionprivate.h b/gtk/gtkcsstransitionprivate.h
index 2d075b0..919e042 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,8 @@ 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 duration_us,
+ gint64 delay_us);
guint _gtk_css_transition_get_property (GtkCssTransition *transition);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]