[clutter] transition: Use current values if no interval is defined



commit 7660f5d0c60bf7de39f8ed0ea4ab07e1dc630a59
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Jun 8 14:24:57 2012 +0100

    transition: Use current values if no interval is defined
    
    Once a ClutterPropertyTransition is attached to a ClutterAnimatable, if
    no interval is set we can simply use the current state of the property
    to define the from and to values. This allows the creation of property
    transitions from the current state of the Animatable instance without
    excessive verbosity.

 clutter/clutter-property-transition.c |   33 +++++++++++++++++++++++++++++++--
 clutter/clutter-transition.c          |    5 ++---
 2 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/clutter/clutter-property-transition.c b/clutter/clutter-property-transition.c
index 302e165..90f9ac2 100644
--- a/clutter/clutter-property-transition.c
+++ b/clutter/clutter-property-transition.c
@@ -68,12 +68,41 @@ clutter_property_transition_attached (ClutterTransition *transition,
 {
   ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition);
   ClutterPropertyTransitionPrivate *priv = self->priv;
+  ClutterInterval *interval;
+  GValue *value;
 
   if (priv->property_name == NULL)
     return;
 
-  priv->pspec = clutter_animatable_find_property (animatable,
-                                                  priv->property_name);
+  priv->pspec =
+    clutter_animatable_find_property (animatable, priv->property_name);
+
+  if (priv->pspec == NULL)
+    return;
+
+  interval = clutter_transition_get_interval (transition);
+  if (interval == NULL)
+    return;
+
+  /* if no initial value has been set, use the current value */
+  value = clutter_interval_peek_initial_value (interval);
+  if (!G_IS_VALUE (value))
+    {
+      g_value_init (value, clutter_interval_get_value_type (interval));
+      clutter_animatable_get_initial_state (animatable,
+                                            priv->property_name,
+                                            value);
+    }
+
+  /* if no final value has been set, use the current value */
+  value = clutter_interval_peek_final_value (interval);
+  if (!G_IS_VALUE (value))
+    {
+      g_value_init (value, clutter_interval_get_value_type (interval));
+      clutter_animatable_get_initial_state (animatable,
+                                            priv->property_name,
+                                            value);
+    }
 }
 
 static void
diff --git a/clutter/clutter-transition.c b/clutter/clutter-transition.c
index 576d6b2..5407aa0 100644
--- a/clutter/clutter-transition.c
+++ b/clutter/clutter-transition.c
@@ -469,10 +469,9 @@ clutter_transition_set_value (ClutterTransition *transition,
   if (priv->interval == NULL)
     {
       priv->interval = clutter_interval_new_with_values (G_VALUE_TYPE (value),
-                                                         value,
-                                                         value);
+                                                         NULL,
+                                                         NULL);
       g_object_ref_sink (priv->interval);
-      return;
     }
 
   interval_type = clutter_interval_get_value_type (priv->interval);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]