2007-10-25 Emmanuele Bassi <ebassi@openedhand.com>
authorEmmanuele Bassi <ebassi@openedhand.com>
Thu, 25 Oct 2007 15:05:19 +0000 (15:05 +0000)
committerEmmanuele Bassi <ebassi@openedhand.com>
Thu, 25 Oct 2007 15:05:19 +0000 (15:05 +0000)
* clutter/clutter-behaviour-bspline.c: Implement the
ClutterScriptableIface to parse the custom "knots" property.

ChangeLog
clutter/clutter-behaviour-bspline.c

index f291aee..b65f5aa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2007-10-25  Emmanuele Bassi  <ebassi@openedhand.com>
 
+       * clutter/clutter-behaviour-bspline.c: Implement the
+       ClutterScriptableIface to parse the custom "knots" property.
+
+2007-10-25  Emmanuele Bassi  <ebassi@openedhand.com>
+
        * tests/test-script.c:
        * tests/test-script.json: Rejig the test case and add a
        path behaviour to test the knot parsing code.
index fc4bd2c..70b0802 100644 (file)
  * Since: 0.4
  */
 
-#include "clutter-fixed.h"
-#include "clutter-marshal.h"
 #include "clutter-behaviour-bspline.h"
 #include "clutter-debug.h"
+#include "clutter-fixed.h"
+#include "clutter-marshal.h"
 #include "clutter-private.h"
+#include "clutter-scriptable.h"
+#include "clutter-script-private.h"
 
 #include <stdlib.h>
 #include <memory.h>
@@ -451,9 +453,13 @@ clutter_bezier_adjust (ClutterBezier * b, ClutterKnot * knot, guint indx)
  *                                                                          *
  ****************************************************************************/
 
-G_DEFINE_TYPE (ClutterBehaviourBspline, 
-               clutter_behaviour_bspline,
-              CLUTTER_TYPE_BEHAVIOUR);
+static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (ClutterBehaviourBspline, 
+                         clutter_behaviour_bspline,
+                        CLUTTER_TYPE_BEHAVIOUR,
+                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
+                                                clutter_scriptable_iface_init));
 
 #define CLUTTER_BEHAVIOUR_BSPLINE_GET_PRIVATE(obj)    \
               (G_TYPE_INSTANCE_GET_PRIVATE ((obj),    \
@@ -631,6 +637,83 @@ clutter_behaviour_bspline_init (ClutterBehaviourBspline * self)
   priv->length  = 0;
 }
 
+static void
+clutter_behaviour_bspline_set_custom_property (ClutterScriptable *scriptable,
+                                               ClutterScript     *script,
+                                               const gchar       *name,
+                                               const GValue      *value)
+{
+  if (strcmp (name, "knots") == 0)
+    {
+      ClutterBehaviourBspline *bspline;
+      GSList *knots, *l;
+
+      if (!G_VALUE_HOLDS (value, G_TYPE_POINTER))
+        return;
+
+      bspline = CLUTTER_BEHAVIOUR_BSPLINE (scriptable); 
+
+      knots = g_value_get_pointer (value);
+      for (l = knots; l != NULL; l = l->next)
+        {
+          ClutterKnot *knot = l->data;
+
+          clutter_behaviour_bspline_append_knot (bspline, knot);
+          clutter_knot_free (knot);
+        }
+
+      g_slist_free (knots);
+    }
+  else
+    g_object_set_property (G_OBJECT (scriptable), name, value);
+}
+
+static gboolean
+clutter_behaviour_bspline_parse_custom_node (ClutterScriptable *scriptable,
+                                             ClutterScript     *script,
+                                             GValue            *value,
+                                             const gchar       *name,
+                                             JsonNode          *node)
+{
+  if (strcmp (name, "knots") == 0)
+    {
+      JsonArray *array;
+      guint knots_len, i;
+      GSList *knots = NULL;
+
+      array = json_node_get_array (node);
+      knots_len = json_array_get_length (array);
+      
+      for (i = 0; i < knots_len; i++)
+        {
+          JsonNode *val = json_array_get_element (array, i);
+          ClutterKnot knot = { 0, };
+
+          if (clutter_script_parse_knot (script, val, &knot))
+            {
+              CLUTTER_NOTE (SCRIPT, "parsed knot [ x:%d, y:%d ]",
+                            knot.x, knot.y);
+
+              knots = g_slist_prepend (knots, clutter_knot_copy (&knot));
+            }
+        }
+
+      g_value_init (value, G_TYPE_POINTER);
+      g_value_set_pointer (value, knots);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+clutter_scriptable_iface_init (ClutterScriptableIface *iface)
+{
+  iface->parse_custom_node = clutter_behaviour_bspline_parse_custom_node;
+  iface->set_custom_property = clutter_behaviour_bspline_set_custom_property;
+}
+
 /**
  * clutter_behaviour_bspline_new:
  * @alpha: a #ClutterAlpha, or %NULL