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.
This commit is contained in:
Emmanuele Bassi 2007-11-30 14:36:07 +00:00
parent 640b9aa07b
commit 97631bffd5
4 changed files with 51 additions and 14 deletions

View File

@ -1,3 +1,16 @@
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

View 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);

View 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++)
{

View 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" }
],