[animation] add varargs support for signal::completed
authorØyvind Kolås <pippin@linux.intel.com>
Mon, 30 Mar 2009 11:10:41 +0000 (12:10 +0100)
committerØyvind Kolås <pippin@linux.intel.com>
Mon, 30 Mar 2009 11:10:41 +0000 (12:10 +0100)
Added support for registering a handler for the completed signal
directly amongst the varargs making it easier to attach code
to be executed when animations complete.

clutter/clutter-animation.c

index 3b951c5..e401742 100644 (file)
@@ -1421,32 +1421,42 @@ clutter_animation_setup_valist (ClutterAnimation *animation,
       GValue final = { 0, };
       gchar *error = NULL;
 
-      if (g_str_has_prefix (property_name, "fixed::"))
-        property_name += 7; /* strlen("fixed::") */
-
-      pspec = g_object_class_find_property (klass, property_name);
-      if (!pspec)
+      if (G_UNLIKELY (g_str_equal (property_name, "signal::completed")))
         {
-          g_warning ("Cannot bind property '%s': objects of type '%s' do "
-                     "not have this property",
-                     property_name,
-                     g_type_name (G_OBJECT_TYPE (priv->object)));
-          break;
-        }
+          GCallback callback = va_arg (var_args, GCallback);
+          gpointer  userdata = va_arg (var_args, gpointer);
 
-      g_value_init (&final, G_PARAM_SPEC_VALUE_TYPE (pspec));
-      G_VALUE_COLLECT (&final, var_args, 0, &error);
-      if (error)
+          g_signal_connect (animation, "completed", callback, userdata);
+        }
+      else
         {
-          g_warning ("%s: %s", G_STRLOC, error);
-          g_free (error);
-          break;
+          if (g_str_has_prefix (property_name, "fixed::"))
+            property_name += 7; /* strlen("fixed::") */
+
+          pspec = g_object_class_find_property (klass, property_name);
+          if (!pspec)
+            {
+              g_warning ("Cannot bind property '%s': objects of type '%s' do "
+                         "not have this property",
+                         property_name,
+                         g_type_name (G_OBJECT_TYPE (priv->object)));
+              break;
+            }
+
+          g_value_init (&final, G_PARAM_SPEC_VALUE_TYPE (pspec));
+          G_VALUE_COLLECT (&final, var_args, 0, &error);
+          if (error)
+            {
+              g_warning ("%s: %s", G_STRLOC, error);
+              g_free (error);
+              break;
+            }
+
+          clutter_animation_setup_property (animation, property_name,
+                                            &final,
+                                            pspec);
         }
 
-      clutter_animation_setup_property (animation, property_name,
-                                        &final,
-                                        pspec);
-
       property_name = va_arg (var_args, gchar*);
     }
 }
@@ -1627,6 +1637,26 @@ clutter_actor_animate_with_timeline (ClutterActor    *actor,
  * to control the animation or to know when the animation has been
  * completed.
  *
+ * If a name argument starts with "signal::" the two following arguments are
+ * used as callback function and userdata for a signal handler installed on the
+ * #ClutterAnimation object, for instance:
+ *
+ * |[
+ *
+ *   static void
+ *   on_animation_completed (ClutterAnimation *animation,
+ *                           ClutterActor     *actor)
+ *   {
+ *     clutter_actor_hide (actor);
+ *   }
+ *
+ *   clutter_actor_animate (actor, CLUTTER_EASE_IN, 100,
+ *                          "opacity", 0,
+ *                          "signal::completed", on_animation_completed, actor,
+ *                          NULL);
+ * ]|
+ *
+ *
  * Calling this function on an actor that is already being animated
  * will cause the current animation to change with the new final values,
  * the new easing mode and the new duration - that is, this code: