mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
script: Use a node when resolving an animation mode
Instead of taking a string and duplicating the "is it a string or an integer" check in both Alpha and Animation, the function in ClutterScript that resolves the animation mode values should take a JsonNode and do all the checks it needs.
This commit is contained in:
parent
4cc269a468
commit
09f91ff6ea
@ -302,26 +302,15 @@ clutter_alpha_parse_custom_node (ClutterScriptable *scriptable,
|
||||
*/
|
||||
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);
|
||||
mode = clutter_script_resolve_animation_mode (node);
|
||||
|
||||
g_value_init (value, G_TYPE_ULONG);
|
||||
g_value_set_ulong (value, mode);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -403,30 +403,15 @@ clutter_animation_parse_custom_node (ClutterScriptable *scriptable,
|
||||
{
|
||||
if (strncmp (name, "mode", 4) == 0)
|
||||
{
|
||||
if (json_node_get_node_type (node) != JSON_NODE_VALUE)
|
||||
return FALSE;
|
||||
gulong mode;
|
||||
|
||||
mode = clutter_script_resolve_animation_mode (node);
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -769,9 +769,19 @@ static const struct
|
||||
static const gint n_animation_modes = G_N_ELEMENTS (animation_modes);
|
||||
|
||||
gulong
|
||||
clutter_script_resolve_animation_mode (const gchar *name)
|
||||
clutter_script_resolve_animation_mode (JsonNode *node)
|
||||
{
|
||||
gint i, res = 0;
|
||||
gint i, res = CLUTTER_CUSTOM_MODE;
|
||||
|
||||
if (JSON_NODE_TYPE (node) != JSON_NODE_VALUE)
|
||||
return CLUTTER_CUSTOM_MODE;
|
||||
|
||||
if (json_node_get_value_type (node) == G_TYPE_INT64)
|
||||
return json_node_get_int (node);
|
||||
|
||||
if (json_node_get_value_type (node) == G_TYPE_STRING)
|
||||
{
|
||||
const gchar *name = json_node_get_string (node);
|
||||
|
||||
/* XXX - we might be able to optimize by changing the ordering
|
||||
* of the animation_modes array, e.g.
|
||||
@ -785,10 +795,13 @@ clutter_script_resolve_animation_mode (const gchar *name)
|
||||
return animation_modes[i].mode;
|
||||
}
|
||||
|
||||
if (clutter_script_enum_from_string (CLUTTER_TYPE_ANIMATION_MODE, name, &res))
|
||||
if (clutter_script_enum_from_string (CLUTTER_TYPE_ANIMATION_MODE,
|
||||
name,
|
||||
&res))
|
||||
return res;
|
||||
|
||||
g_warning ("Unable to find the animation mode '%s'", name);
|
||||
}
|
||||
|
||||
return CLUTTER_CUSTOM_MODE;
|
||||
}
|
||||
@ -850,8 +863,8 @@ _clutter_script_parse_alpha (ClutterScript *script,
|
||||
}
|
||||
|
||||
val = json_object_get_member (object, "mode");
|
||||
if (val && json_node_get_string (val) != NULL)
|
||||
mode = clutter_script_resolve_animation_mode (json_node_get_string (val));
|
||||
if (val)
|
||||
mode = clutter_script_resolve_animation_mode (val);
|
||||
|
||||
if (mode == CLUTTER_CUSTOM_MODE)
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ gboolean clutter_script_parse_node (ClutterScript *script,
|
||||
GType clutter_script_get_type_from_symbol (const gchar *symbol);
|
||||
GType clutter_script_get_type_from_class (const gchar *name);
|
||||
|
||||
gulong clutter_script_resolve_animation_mode (const gchar *namer);
|
||||
gulong clutter_script_resolve_animation_mode (JsonNode *node);
|
||||
|
||||
gboolean clutter_script_enum_from_string (GType gtype,
|
||||
const gchar *string,
|
||||
|
Loading…
Reference in New Issue
Block a user