[clutter/master-next: 7/43] script: Support ClutterPoint and ClutterSize
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/master-next: 7/43] script: Support ClutterPoint and ClutterSize
- Date: Fri, 20 Apr 2012 17:30:55 +0000 (UTC)
commit 4bc85f2c7d465a08333aa9217eba754b7212c177
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Sun Apr 1 17:54:11 2012 +0100
script: Support ClutterPoint and ClutterSize
Point and Size can be described both as an array of values or as an
object.
clutter/clutter-script-parser.c | 148 ++++++++++++++++++++++++++++++++++++++
clutter/clutter-script-private.h | 7 ++
tests/data/test-script.json | 12 +--
3 files changed, 159 insertions(+), 8 deletions(-)
---
diff --git a/clutter/clutter-script-parser.c b/clutter/clutter-script-parser.c
index 1cefae5..d31df41 100644
--- a/clutter/clutter-script-parser.c
+++ b/clutter/clutter-script-parser.c
@@ -492,6 +492,114 @@ _clutter_script_parse_color (ClutterScript *script,
return FALSE;
}
+static gboolean
+parse_point_from_array (JsonArray *array,
+ ClutterPoint *point)
+{
+ if (json_array_get_length (array) != 2)
+ return FALSE;
+
+ point->x = json_array_get_double_element (array, 0);
+ point->y = json_array_get_double_element (array, 1);
+
+ return TRUE;
+}
+
+static gboolean
+parse_point_from_object (JsonObject *object,
+ ClutterPoint *point)
+{
+ if (json_object_has_member (object, "x"))
+ point->x = json_object_get_double_member (object, "x");
+ else
+ point->x = 0.f;
+
+ if (json_object_has_member (object, "y"))
+ point->y = json_object_get_double_member (object, "y");
+ else
+ point->y = 0.f;
+
+ return TRUE;
+}
+
+gboolean
+_clutter_script_parse_point (ClutterScript *script,
+ JsonNode *node,
+ ClutterPoint *point)
+{
+ g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
+ g_return_val_if_fail (node != NULL, FALSE);
+ g_return_val_if_fail (point != NULL, FALSE);
+
+ switch (JSON_NODE_TYPE (node))
+ {
+ case JSON_NODE_ARRAY:
+ return parse_point_from_array (json_node_get_array (node), point);
+
+ case JSON_NODE_OBJECT:
+ return parse_point_from_object (json_node_get_object (node), point);
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+parse_size_from_array (JsonArray *array,
+ ClutterSize *size)
+{
+ if (json_array_get_length (array) != 2)
+ return FALSE;
+
+ size->width = json_array_get_double_element (array, 0);
+ size->height = json_array_get_double_element (array, 1);
+
+ return TRUE;
+}
+
+static gboolean
+parse_size_from_object (JsonObject *object,
+ ClutterSize *size)
+{
+ if (json_object_has_member (object, "width"))
+ size->width = json_object_get_double_member (object, "width");
+ else
+ size->width = 0.f;
+
+ if (json_object_has_member (object, "height"))
+ size->height = json_object_get_double_member (object, "height");
+ else
+ size->height = 0.f;
+
+ return TRUE;
+}
+
+gboolean
+_clutter_script_parse_size (ClutterScript *script,
+ JsonNode *node,
+ ClutterSize *size)
+{
+ g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
+ g_return_val_if_fail (node != NULL, FALSE);
+ g_return_val_if_fail (size != NULL, FALSE);
+
+ switch (JSON_NODE_TYPE (node))
+ {
+ case JSON_NODE_ARRAY:
+ return parse_size_from_array (json_node_get_array (node), size);
+
+ case JSON_NODE_OBJECT:
+ return parse_size_from_object (json_node_get_object (node), size);
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
const gchar *
_clutter_script_get_id_from_node (JsonNode *node)
{
@@ -1256,6 +1364,26 @@ _clutter_script_parse_node (ClutterScript *script,
return TRUE;
}
}
+ else if (p_type == CLUTTER_TYPE_POINT)
+ {
+ ClutterPoint point = CLUTTER_POINT_INIT_ZERO;
+
+ if (_clutter_script_parse_point (script, node, &point))
+ {
+ g_value_set_boxed (value, &point);
+ return TRUE;
+ }
+ }
+ else if (p_type == CLUTTER_TYPE_SIZE)
+ {
+ ClutterSize size = CLUTTER_SIZE_INIT_ZERO;
+
+ if (_clutter_script_parse_size (script, node, &size))
+ {
+ g_value_set_boxed (value, &size);
+ return TRUE;
+ }
+ }
else if (p_type == G_TYPE_STRING)
{
char *str = NULL;
@@ -1313,6 +1441,26 @@ _clutter_script_parse_node (ClutterScript *script,
return TRUE;
}
}
+ else if (G_VALUE_HOLDS (value, CLUTTER_TYPE_POINT))
+ {
+ ClutterPoint point = CLUTTER_POINT_INIT_ZERO;
+
+ if (_clutter_script_parse_point (script, node, &point))
+ {
+ g_value_set_boxed (value, &point);
+ return TRUE;
+ }
+ }
+ else if (G_VALUE_HOLDS (value, CLUTTER_TYPE_SIZE))
+ {
+ ClutterSize size = CLUTTER_SIZE_INIT_ZERO;
+
+ if (_clutter_script_parse_size (script, node, &size))
+ {
+ g_value_set_boxed (value, &size);
+ return TRUE;
+ }
+ }
else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
{
JsonArray *array = json_node_get_array (node);
diff --git a/clutter/clutter-script-private.h b/clutter/clutter-script-private.h
index 7452952..52a67bc 100644
--- a/clutter/clutter-script-private.h
+++ b/clutter/clutter-script-private.h
@@ -130,6 +130,13 @@ gboolean _clutter_script_parse_color (ClutterScript *script,
ClutterColor *color);
GObject *_clutter_script_parse_alpha (ClutterScript *script,
JsonNode *node);
+gboolean _clutter_script_parse_point (ClutterScript *script,
+ JsonNode *node,
+ ClutterPoint *point);
+gboolean _clutter_script_parse_size (ClutterScript *script,
+ JsonNode *node,
+ ClutterSize *size);
+
gboolean _clutter_script_parse_translatable_string (ClutterScript *script,
JsonNode *node,
char **str);
diff --git a/tests/data/test-script.json b/tests/data/test-script.json
index 1d66b25..54d4fb4 100644
--- a/tests/data/test-script.json
+++ b/tests/data/test-script.json
@@ -26,10 +26,8 @@
"color" : "#00ff00ff",
"border-width" : 5,
"border-color" : "#00cc00ff",
- "x" : 200,
- "y" : 50,
- "width" : 100,
- "height" : 100,
+ "position" : [ 200.0, 50.0 ],
+ "size" : { "width" : 100.0, "height" : 100.0 },
"depth" : -200.0,
"reactive" : true,
"signals" : [
@@ -40,8 +38,7 @@
"id" : "red-hand",
"type" : "ClutterTexture",
"filename" : "redhand.png",
- "x" : 100,
- "y" : 100,
+ "position" : { "x" : 100.0, "y" : 100.0 },
"width" : "20 mm",
"keep-aspect-ratio" : true,
"anchor-x" : "5 em",
@@ -53,8 +50,7 @@
"id" : "red-hand-clone",
"type" : "ClutterClone",
"source" : "red-hand",
- "x" : 250,
- "y" : 150,
+ "position" : [ 250.0, 150.0 ],
"opacity" : 100
},
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]