]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssanimation.c
GtkTextView: don't popdown a bubble if we don't have one
[~andy/gtk] / gtk / gtkcssanimation.c
index 48ef62bc4915a9a86b1cfefbd8f43da6528c77cb..2ebf5858cf1d123f1a0980ee43c3b7705a1fee82 100644 (file)
 
 G_DEFINE_TYPE (GtkCssAnimation, _gtk_css_animation, GTK_TYPE_STYLE_ANIMATION)
 
+/* NB: Return value can be negative (if animation hasn't started yet) */
+static gint64
+gtk_css_animation_get_elapsed (GtkCssAnimation *animation,
+                               gint64           for_time_us)
+{
+  if (animation->play_state == GTK_CSS_PLAY_STATE_PAUSED)
+    return animation->timestamp;
+  else
+    return for_time_us - animation->timestamp;
+}
 /* NB: Return value can be negative and +-Inf */
 static double
 gtk_css_animation_get_iteration (GtkCssAnimation *animation,
                                  gint64           for_time_us)
 {
-  gint64 elapsed;
-  double iterations;
-
-  elapsed = for_time_us - animation->timestamp;
-  iterations = (double) elapsed / animation->duration;
-
-  return iterations;
+  return (double) gtk_css_animation_get_elapsed (animation, for_time_us) / animation->duration;
 }
 
 static gboolean
@@ -97,9 +101,8 @@ gtk_css_animation_get_progress_from_iteration (GtkCssAnimation *animation,
     }
 }
 
-static GtkBitmask *
+static void
 gtk_css_animation_set_values (GtkStyleAnimation    *style_animation,
-                              GtkBitmask           *changed,
                               gint64                for_time_us,
                               GtkCssComputedValues *values)
 {
@@ -110,7 +113,7 @@ gtk_css_animation_set_values (GtkStyleAnimation    *style_animation,
   iteration = gtk_css_animation_get_iteration (animation, for_time_us);
 
   if (!gtk_css_animation_is_executing_at_iteration (animation, iteration))
-    return changed;
+    return;
 
   progress = gtk_css_animation_get_progress_from_iteration (animation, iteration);
   progress = _gtk_css_ease_value_transform (animation->ease, progress);
@@ -128,11 +131,7 @@ gtk_css_animation_set_values (GtkStyleAnimation    *style_animation,
                                             _gtk_css_computed_values_get_intrinsic_value (values, i));
       _gtk_css_computed_values_set_animated_value (values, property_id, value);
       _gtk_css_value_unref (value);
-      
-      changed = _gtk_bitmask_set (changed, property_id, TRUE);
     }
-
-  return changed;
 }
 
 static gboolean
@@ -149,6 +148,9 @@ gtk_css_animation_is_static (GtkStyleAnimation *style_animation,
   GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation);
   double iteration;
 
+  if (animation->play_state == GTK_CSS_PLAY_STATE_PAUSED)
+    return TRUE;
+
   iteration = gtk_css_animation_get_iteration (animation, at_time_us);
 
   return iteration >= animation->iteration_count;
@@ -187,7 +189,8 @@ _gtk_css_animation_init (GtkCssAnimation *animation)
 GtkStyleAnimation *
 _gtk_css_animation_new (const char      *name,
                         GtkCssKeyframes *keyframes,
-                        gint64           start_time_us,
+                        gint64           timestamp,
+                        gint64           delay_us,
                         gint64           duration_us,
                         GtkCssValue     *ease,
                         GtkCssDirection  direction,
@@ -206,7 +209,11 @@ _gtk_css_animation_new (const char      *name,
 
   animation->name = g_strdup (name);
   animation->keyframes = _gtk_css_keyframes_ref (keyframes);
-  animation->timestamp = start_time_us;
+  if (play_state == GTK_CSS_PLAY_STATE_PAUSED)
+    animation->timestamp = - delay_us;
+  else
+    animation->timestamp = timestamp + delay_us;
+
   animation->duration = duration_us;
   animation->ease = _gtk_css_value_ref (ease);
   animation->direction = direction;
@@ -224,3 +231,26 @@ _gtk_css_animation_get_name (GtkCssAnimation *animation)
 
   return animation->name;
 }
+
+GtkStyleAnimation *
+_gtk_css_animation_copy (GtkCssAnimation *animation,
+                         gint64           at_time_us,
+                         GtkCssPlayState  play_state)
+{
+  g_return_val_if_fail (GTK_IS_CSS_ANIMATION (animation), NULL);
+
+  if (animation->play_state == play_state)
+    return g_object_ref (animation);
+
+  return _gtk_css_animation_new (animation->name,
+                                 animation->keyframes,
+                                 at_time_us,
+                                 - gtk_css_animation_get_elapsed (animation, at_time_us),
+                                 animation->duration,
+                                 animation->ease,
+                                 animation->direction,
+                                 play_state,
+                                 animation->fill_mode,
+                                 animation->iteration_count);
+}
+