animation: Override parsing :mode
authorEmmanuele Bassi <ebassi@linux.intel.com>
Fri, 13 Nov 2009 13:21:47 +0000 (13:21 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Fri, 13 Nov 2009 15:01:17 +0000 (15:01 +0000)
Like in ClutterAlpha, ClutterAnimation:mode must be overridden when
parsing a Script definition, as we accept both a numeric id and the
string id for easing modes.

clutter/clutter-animation.c

index b314456..01ba759 100644 (file)
@@ -85,6 +85,8 @@
 #include "clutter-enum-types.h"
 #include "clutter-interval.h"
 #include "clutter-private.h"
+#include "clutter-scriptable.h"
+#include "clutter-script-private.h"
 
 enum
 {
@@ -125,7 +127,11 @@ static guint animation_signals[LAST_SIGNAL] = { 0, };
 
 static GQuark quark_object_animation = 0;
 
-G_DEFINE_TYPE (ClutterAnimation, clutter_animation, G_TYPE_OBJECT);
+static void clutter_scriptable_init (ClutterScriptableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (ClutterAnimation, clutter_animation, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
+                                                clutter_scriptable_init));
 
 static void
 clutter_animation_real_completed (ClutterAnimation *self)
@@ -303,6 +309,49 @@ clutter_animation_get_property (GObject    *gobject,
     }
 }
 
+static gboolean
+clutter_animation_parse_custom_node (ClutterScriptable *scriptable,
+                                     ClutterScript     *script,
+                                     GValue            *value,
+                                     const gchar       *name,
+                                     JsonNode          *node)
+{
+  if (strncmp (name, "mode", 4) == 0)
+    {
+      if (json_node_get_node_type (node) != JSON_NODE_VALUE)
+        return FALSE;
+
+      g_value_init (value, G_TYPE_ULONG);
+
+      if (json_node_get_value_type (node) == G_TYPE_INT64)
+        {
+          g_value_set_ulong (value, json_node_get_int (node));
+          return TRUE;
+        }
+      else if (json_node_get_value_type (node) == G_TYPE_STRING)
+        {
+          const gchar *str = json_node_get_string (node);
+          gulong mode = CLUTTER_LINEAR;
+
+          mode = clutter_script_resolve_animation_mode (str);
+          g_value_set_ulong (value, mode);
+
+          return TRUE;
+        }
+      else
+        g_warning ("Expected an integer id or a string id for "
+                   "the ClutterAnimation mode property");
+    }
+
+  return FALSE;
+}
+
+static void
+clutter_scriptable_init (ClutterScriptableIface *iface)
+{
+  iface->parse_custom_node = clutter_animation_parse_custom_node;
+}
+
 static void
 clutter_animation_class_init (ClutterAnimationClass *klass)
 {