From 97631bffd531928c84ef88d4480ec859ea8679f4 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 30 Nov 2007 14:36:07 +0000 Subject: [PATCH] 2007-11-30 Emmanuele Bassi * clutter/clutter-actor.c (parse_units), (clutter_actor_parse_custom_node): Do not allow using percentages of the stage on the stage itself, as it makes little to no sense. * clutter/clutter-script.c: (clutter_script_construct_object): Rearrange code. * tests/test-script.json: Do not set the size of the stage, to test for the stage size percentage. --- ChangeLog | 13 +++++++++++++ clutter/clutter-actor.c | 32 +++++++++++++++++++++++++++++--- clutter/clutter-script.c | 18 +++++++++--------- tests/test-script.json | 2 -- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index f422bfcbb..e3f5a9e75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-11-30 Emmanuele Bassi + + * clutter/clutter-actor.c (parse_units), + (clutter_actor_parse_custom_node): Do not allow using percentages + of the stage on the stage itself, as it makes little to no + sense. + + * clutter/clutter-script.c: + (clutter_script_construct_object): Rearrange code. + + * tests/test-script.json: Do not set the size of the stage, to + test for the stage size percentage. + 2007-11-30 Emmanuele Bassi * clutter/clutter-model.h: Complete the documentation of diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 2779eeb17..2a467ee5f 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -3774,7 +3774,8 @@ typedef enum } ParseDimension; static ClutterUnit -parse_units (ParseDimension dimension, +parse_units (ClutterActor *self, + ParseDimension dimension, JsonNode *node) { GValue value = { 0, }; @@ -3825,6 +3826,17 @@ parse_units (ParseDimension dimension, if (end[0] == '%' && end[1] == '\0') { + if (CLUTTER_PRIVATE_FLAGS (self) & CLUTTER_ACTOR_IS_TOPLEVEL) + { + g_warning ("Unable to set percentage of %s on a top-level " + "actor of type `%s'", + (dimension == PARSE_X || dimension == PARSE_WIDTH) ? "width" + : "height", + g_type_name (G_OBJECT_TYPE (self))); + retval = 0; + goto out; + } + if (dimension == PARSE_X || dimension == PARSE_WIDTH) retval = CLUTTER_UNITS_FROM_STAGE_WIDTH_PERCENTAGE (val); else @@ -3843,7 +3855,20 @@ parse_units (ParseDimension dimension, } else if (G_VALUE_HOLDS (&value, G_TYPE_DOUBLE)) { - gint val = CLAMP (g_value_get_double (&value) * 100, 0, 100); + gint val; + + if (CLUTTER_PRIVATE_FLAGS (self) & CLUTTER_ACTOR_IS_TOPLEVEL) + { + g_warning ("Unable to set percentage of %s on a top-level " + "actor of type `%s'", + (dimension == PARSE_X || dimension == PARSE_WIDTH) ? "width" + : "height", + g_type_name (G_OBJECT_TYPE (self))); + retval = 0; + goto out; + } + + val = CLAMP (g_value_get_double (&value) * 100, 0, 100); if (dimension == PARSE_X || dimension == PARSE_WIDTH) retval = CLUTTER_UNITS_FROM_STAGE_WIDTH_PERCENTAGE (val); @@ -3871,6 +3896,7 @@ clutter_actor_parse_custom_node (ClutterScriptable *scriptable, const gchar *name, JsonNode *node) { + ClutterActor *actor = CLUTTER_ACTOR (scriptable); gboolean retval = FALSE; if ((name[0] == 'x' && name[1] == '\0') || @@ -3890,7 +3916,7 @@ clutter_actor_parse_custom_node (ClutterScriptable *scriptable, else dimension = PARSE_HEIGHT; - units = parse_units (dimension, node); + units = parse_units (actor, dimension, node); /* convert back to pixels */ g_value_init (value, G_TYPE_INT); diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c index 93e037432..3577693ac 100644 --- a/clutter/clutter-script.c +++ b/clutter/clutter-script.c @@ -1244,6 +1244,15 @@ clutter_script_construct_object (ClutterScript *script, g_array_free (construct_params, TRUE); } + /* then we get the rest of the parameters, asking the object itself + * to translate them for us, if we cannot do that + */ + oinfo->properties = clutter_script_translate_parameters (script, + object, + oinfo->id, + oinfo->properties, + ¶ms); + /* shortcut, to avoid typechecking every time */ if (CLUTTER_IS_SCRIPTABLE (object)) { @@ -1254,15 +1263,6 @@ clutter_script_construct_object (ClutterScript *script, set_custom_property = TRUE; } - /* then we get the rest of the parameters, asking the object itself - * to translate them for us, if we cannot do that - */ - oinfo->properties = clutter_script_translate_parameters (script, - object, - oinfo->id, - oinfo->properties, - ¶ms); - /* consume all the properties we could translate in this pass */ for (i = 0; i < params->len; i++) { diff --git a/tests/test-script.json b/tests/test-script.json index 72039f988..ed4810a7a 100644 --- a/tests/test-script.json +++ b/tests/test-script.json @@ -3,8 +3,6 @@ "id" : "main-stage", "type" : "ClutterStage", "color" : "white", - "width" : 500, - "height" : "400px", "signals" : [ { "name" : "key-press-event", "handler" : "clutter_main_quit" } ],