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".
This commit is contained in:
Emmanuele Bassi 2009-10-21 16:04:12 +01:00
parent 01bc3fa2c8
commit 7a52fddcd6
3 changed files with 43 additions and 4 deletions

View File

@ -82,7 +82,11 @@
* <programlisting> * <programlisting>
* { * {
* "id" : "sine-alpha", * "id" : "sine-alpha",
* "timeline" : "timeline-01", * "timeline" : {
* "id" : "sine-timeline",
* "duration" : 500,
* "loop" : true
* },
* "function" : "my_sine_alpha" * "function" : "my_sine_alpha"
* } * }
* </programlisting> * </programlisting>
@ -107,6 +111,7 @@
#include "clutter-marshal.h" #include "clutter-marshal.h"
#include "clutter-private.h" #include "clutter-private.h"
#include "clutter-scriptable.h" #include "clutter-scriptable.h"
#include "clutter-script-private.h"
static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
@ -288,6 +293,32 @@ clutter_alpha_parse_custom_node (ClutterScriptable *scriptable,
return TRUE; 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; return FALSE;
} }

View File

@ -87,6 +87,8 @@ GType clutter_script_get_type_from_class (const gchar *name);
GObject *clutter_script_construct_object (ClutterScript *script, GObject *clutter_script_construct_object (ClutterScript *script,
ObjectInfo *info); ObjectInfo *info);
gulong clutter_script_resolve_animation_mode (const gchar *namer);
gboolean clutter_script_enum_from_string (GType gtype, gboolean clutter_script_enum_from_string (GType gtype,
const gchar *string, const gchar *string,
gint *enum_value); gint *enum_value);

View File

@ -564,11 +564,17 @@ static const struct
static const gint n_animation_modes = G_N_ELEMENTS (animation_modes); static const gint n_animation_modes = G_N_ELEMENTS (animation_modes);
static ClutterAnimationMode gulong
resolve_animation_mode (const gchar *name) clutter_script_resolve_animation_mode (const gchar *name)
{ {
gint i, res = 0; 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++) for (i = 0; i < n_animation_modes; i++)
{ {
if (strcmp (animation_modes[i].name, name) == 0) 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"); val = json_object_get_member (object, "mode");
if (val && json_node_get_string (val) != NULL) 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) if (mode == CLUTTER_CUSTOM_MODE)
{ {