From 7a52fddcd673c4aa14faf2396a0a74db644ba64d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 21 Oct 2009 16:04:12 +0100 Subject: [PATCH] alpha: Manually parse the :mode property in ClutterScript The :mode property for a ClutterAlpha can either be an integer, for an easing mode logical id, or a string for the easing mode "nickname". --- clutter/clutter-alpha.c | 33 +++++++++++++++++++++++++++++++- clutter/clutter-script-private.h | 2 ++ clutter/clutter-script.c | 12 +++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/clutter/clutter-alpha.c b/clutter/clutter-alpha.c index ae88454b7..05b554f3f 100644 --- a/clutter/clutter-alpha.c +++ b/clutter/clutter-alpha.c @@ -82,7 +82,11 @@ * * { * "id" : "sine-alpha", - * "timeline" : "timeline-01", + * "timeline" : { + * "id" : "sine-timeline", + * "duration" : 500, + * "loop" : true + * }, * "function" : "my_sine_alpha" * } * @@ -107,6 +111,7 @@ #include "clutter-marshal.h" #include "clutter-private.h" #include "clutter-scriptable.h" +#include "clutter-script-private.h" static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); @@ -288,6 +293,32 @@ clutter_alpha_parse_custom_node (ClutterScriptable *scriptable, return TRUE; } + /* we need to do this because we use gulong in place + * of ClutterAnimationMode for ClutterAlpha:mode + */ + if (strncmp (name, "mode", 4) == 0) + { + if (JSON_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; + + mode = clutter_script_resolve_animation_mode (str); + g_value_set_ulong (value, mode); + return TRUE; + } + } + return FALSE; } diff --git a/clutter/clutter-script-private.h b/clutter/clutter-script-private.h index 7fcbae7e6..75a0292f6 100644 --- a/clutter/clutter-script-private.h +++ b/clutter/clutter-script-private.h @@ -87,6 +87,8 @@ GType clutter_script_get_type_from_class (const gchar *name); GObject *clutter_script_construct_object (ClutterScript *script, ObjectInfo *info); +gulong clutter_script_resolve_animation_mode (const gchar *namer); + gboolean clutter_script_enum_from_string (GType gtype, const gchar *string, gint *enum_value); diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c index 79310ccb2..7c7df495f 100644 --- a/clutter/clutter-script.c +++ b/clutter/clutter-script.c @@ -564,11 +564,17 @@ static const struct static const gint n_animation_modes = G_N_ELEMENTS (animation_modes); -static ClutterAnimationMode -resolve_animation_mode (const gchar *name) +gulong +clutter_script_resolve_animation_mode (const gchar *name) { gint i, res = 0; + /* XXX - we might be able to optimize by changing the ordering + * of the animation_modes array, e.g. + * - special casing linear + * - tokenizing ('ease', 'In', 'Sine') and matching on token + * - binary searching? + */ for (i = 0; i < n_animation_modes; i++) { if (strcmp (animation_modes[i].name, name) == 0) @@ -642,7 +648,7 @@ clutter_script_parse_alpha (ClutterScript *script, val = json_object_get_member (object, "mode"); if (val && json_node_get_string (val) != NULL) - mode = resolve_animation_mode (json_node_get_string (val)); + mode = clutter_script_resolve_animation_mode (json_node_get_string (val)); if (mode == CLUTTER_CUSTOM_MODE) {