2007-11-30 Emmanuele Bassi <ebassi@openedhand.com>
authorEmmanuele Bassi <ebassi@openedhand.com>
Fri, 30 Nov 2007 14:36:07 +0000 (14:36 +0000)
committerEmmanuele Bassi <ebassi@openedhand.com>
Fri, 30 Nov 2007 14:36:07 +0000 (14:36 +0000)
* 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
clutter/clutter-actor.c
clutter/clutter-script.c
tests/test-script.json

index f422bfc..e3f5a9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2007-11-30  Emmanuele Bassi  <ebassi@openedhand.com>
 
+       * 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  <ebassi@openedhand.com>
+
        * clutter/clutter-model.h: Complete the documentation of
        the ClutterModelClass structure members.
 
index 2779eeb..2a467ee 100644 (file)
@@ -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);
index 93e0374..3577693 100644 (file)
@@ -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,
+                                                           &params);
+
   /* 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,
-                                                           &params);
-
   /* consume all the properties we could translate in this pass */
   for (i = 0; i < params->len; i++)
     {
index 72039f9..ed4810a 100644 (file)
@@ -3,8 +3,6 @@
     "id" : "main-stage",
     "type" : "ClutterStage",
     "color" : "white",
-    "width" : 500,
-    "height" : "400px",
     "signals" : [
       { "name" : "key-press-event", "handler" : "clutter_main_quit" }
     ],