From 8a3181f741207462c7bfe7deb939a19e5fb3e5c2 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Mon, 30 Oct 2023 12:42:50 +0100 Subject: [PATCH] clutter: Make json-glib a debug only dependency Currently, json-glib is used for two things: - For loading scripts, nothing seems to use that in real life other than some tests - For debugging paint nodes For now, the PR drops the first use case and only require json-glib if it is a debug build Part-of: --- clutter/clutter/clutter-actor.c | 511 ----- clutter/clutter/clutter-autocleanups.h | 2 - clutter/clutter/clutter-interval.c | 49 +- clutter/clutter/clutter-layout-manager.c | 41 - clutter/clutter/clutter-paint-node-private.h | 5 + clutter/clutter/clutter-paint-node.c | 5 +- clutter/clutter/clutter-paint-nodes.c | 33 + clutter/clutter/clutter-script-parser.c | 1903 ----------------- clutter/clutter/clutter-script-private.h | 164 -- clutter/clutter/clutter-script.c | 1339 ------------ clutter/clutter/clutter-script.h | 182 -- clutter/clutter/clutter-scriptable.c | 174 -- clutter/clutter/clutter-scriptable.h | 99 - clutter/clutter/clutter-text.c | 54 - clutter/clutter/clutter-timeline.c | 148 +- clutter/clutter/clutter.h | 2 - clutter/clutter/meson.build | 7 - clutter/meson.build | 7 +- meson.build | 2 +- src/compositor/plugins/meson.build | 1 - src/meson.build | 1 - src/tests/clutter/conform/interval.c | 46 - src/tests/clutter/conform/meson.build | 1 - src/tests/clutter/conform/script-parser.c | 194 -- .../conform/scripts/test-script-child.json | 20 - .../conform/scripts/test-script-interval.json | 16 - .../conform/scripts/test-script-margin.json | 22 - .../conform/scripts/test-script-model.json | 17 - .../scripts/test-script-named-object.json | 43 - .../scripts/test-script-object-property.json | 13 - .../conform/scripts/test-script-single.json | 10 - .../scripts/test-script-timeline-markers.json | 16 - src/tests/clutter/conform/timeline.c | 44 - src/tests/clutter/interactive/meson.build | 1 - src/tests/clutter/interactive/test-script.c | 154 -- .../clutter/interactive/test-script.json | 54 - .../clutter/interactive/test-state-script.c | 46 - src/tests/meson.build | 1 - 38 files changed, 51 insertions(+), 5376 deletions(-) delete mode 100644 clutter/clutter/clutter-script-parser.c delete mode 100644 clutter/clutter/clutter-script-private.h delete mode 100644 clutter/clutter/clutter-script.c delete mode 100644 clutter/clutter/clutter-script.h delete mode 100644 clutter/clutter/clutter-scriptable.c delete mode 100644 clutter/clutter/clutter-scriptable.h delete mode 100644 src/tests/clutter/conform/script-parser.c delete mode 100644 src/tests/clutter/conform/scripts/test-script-child.json delete mode 100644 src/tests/clutter/conform/scripts/test-script-interval.json delete mode 100644 src/tests/clutter/conform/scripts/test-script-margin.json delete mode 100644 src/tests/clutter/conform/scripts/test-script-model.json delete mode 100644 src/tests/clutter/conform/scripts/test-script-named-object.json delete mode 100644 src/tests/clutter/conform/scripts/test-script-object-property.json delete mode 100644 src/tests/clutter/conform/scripts/test-script-single.json delete mode 100644 src/tests/clutter/conform/scripts/test-script-timeline-markers.json delete mode 100644 src/tests/clutter/interactive/test-script.c delete mode 100644 src/tests/clutter/interactive/test-script.json delete mode 100644 src/tests/clutter/interactive/test-state-script.c diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index 832e0766e..4c05807a3 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -380,44 +380,6 @@ * In general, it is strongly encouraged to use delegation and composition * instead of direct subclassing. * - * ## ClutterActor custom properties for ClutterScript - * - * #ClutterActor defines a custom "rotation" property which allows a short-hand - * description of the rotations to be applied to an actor. - * - * The syntax of the "rotation" property is the following: - * - * ``` - * "rotation" : [ { "" : [ , [ ] ] } ] - * ``` - * - * where: - * - * - axis is the name of an enumeration value of type #ClutterRotateAxis - * - angle is a floating point value representing the rotation angle on the given axis in degrees - * - center-point is an optional array, and if present it must contain the center of rotation as described by two coordinates: - * - Y and Z for "x-axis" - * - X and Z for "y-axis" - * - X and Y for "z-axis". - * - * #ClutterActor also defines a scriptable "margin" property which follows the CSS "margin" shorthand. - * - * ``` - * // 4 values - * "margin" : [ top, right, bottom, left ] - * // 3 values - * "margin" : [ top, left/right, bottom ] - * // 2 values - * "margin" : [ top/bottom, left/right ] - * // 1 value - * "margin" : [ top/right/bottom/left ] - * ``` - * - * #ClutterActor will also parse every positional and dimensional - * property defined as a string through clutter_units_from_string(); you - * should read the documentation for the #ClutterUnits parser format for - * the valid units and syntax. - * * ## Custom animatable properties * * #ClutterActor allows accessing properties of #ClutterAction, @@ -555,8 +517,6 @@ #include "clutter/clutter-pick-context-private.h" #include "clutter/clutter-private.h" #include "clutter/clutter-property-transition.h" -#include "clutter/clutter-scriptable.h" -#include "clutter/clutter-script-private.h" #include "clutter/clutter-stage-private.h" #include "clutter/clutter-stage-view-private.h" #include "clutter/clutter-timeline.h" @@ -941,7 +901,6 @@ typedef struct _TransitionClosure gulong completed_id; } TransitionClosure; -static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); static void clutter_animatable_iface_init (ClutterAnimatableInterface *iface); static void atk_implementor_iface_init (AtkImplementorIface *iface); @@ -1026,8 +985,6 @@ G_DEFINE_TYPE_WITH_CODE (ClutterActor, clutter_actor, G_TYPE_INITIALLY_UNOWNED, G_ADD_PRIVATE (ClutterActor) - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE, - clutter_scriptable_iface_init) G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_ANIMATABLE, clutter_animatable_iface_init) G_IMPLEMENT_INTERFACE (ATK_TYPE_IMPLEMENTOR, @@ -11951,474 +11908,6 @@ clutter_actor_store_content_box (ClutterActor *self, g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CONTENT_BOX]); } -typedef enum -{ - PARSE_X, - PARSE_Y, - PARSE_WIDTH, - PARSE_HEIGHT, -} ParseDimension; - -static gfloat -parse_units (ClutterActor *self, - ParseDimension dimension, - JsonNode *node) -{ - GValue value = G_VALUE_INIT; - gfloat retval = 0; - - if (JSON_NODE_TYPE (node) != JSON_NODE_VALUE) - return 0; - - json_node_get_value (node, &value); - - if (G_VALUE_HOLDS (&value, G_TYPE_INT64)) - { - retval = (gfloat) g_value_get_int64 (&value); - } - else if (G_VALUE_HOLDS (&value, G_TYPE_DOUBLE)) - { - retval = g_value_get_double (&value); - } - else if (G_VALUE_HOLDS (&value, G_TYPE_STRING)) - { - ClutterUnits units; - gboolean res; - - res = clutter_units_from_string (&units, g_value_get_string (&value)); - if (res) - retval = clutter_units_to_pixels (&units); - else - { - g_warning ("Invalid value '%s': integers, strings or floating point " - "values can be used for the x, y, width and height " - "properties. Valid modifiers for strings are 'px', 'mm', " - "'pt' and 'em'.", - g_value_get_string (&value)); - retval = 0; - } - } - else - { - g_warning ("Invalid value of type '%s': integers, strings of floating " - "point values can be used for the x, y, width, and height " - "properties.", - g_type_name (G_VALUE_TYPE (&value))); - } - - g_value_unset (&value); - - return retval; -} - -typedef struct { - ClutterRotateAxis axis; - - gdouble angle; - - gfloat center_x; - gfloat center_y; - gfloat center_z; -} RotationInfo; - -static inline gboolean -parse_rotation_array (ClutterActor *actor, - JsonArray *array, - RotationInfo *info) -{ - JsonNode *element; - - if (json_array_get_length (array) != 2) - return FALSE; - - /* angle */ - element = json_array_get_element (array, 0); - if (JSON_NODE_TYPE (element) == JSON_NODE_VALUE) - info->angle = json_node_get_double (element); - else - return FALSE; - - /* center */ - element = json_array_get_element (array, 1); - if (JSON_NODE_TYPE (element) == JSON_NODE_ARRAY) - { - JsonArray *center = json_node_get_array (element); - - if (json_array_get_length (center) != 2) - return FALSE; - - switch (info->axis) - { - case CLUTTER_X_AXIS: - info->center_y = parse_units (actor, PARSE_Y, - json_array_get_element (center, 0)); - info->center_z = parse_units (actor, PARSE_Y, - json_array_get_element (center, 1)); - return TRUE; - - case CLUTTER_Y_AXIS: - info->center_x = parse_units (actor, PARSE_X, - json_array_get_element (center, 0)); - info->center_z = parse_units (actor, PARSE_X, - json_array_get_element (center, 1)); - return TRUE; - - case CLUTTER_Z_AXIS: - info->center_x = parse_units (actor, PARSE_X, - json_array_get_element (center, 0)); - info->center_y = parse_units (actor, PARSE_Y, - json_array_get_element (center, 1)); - return TRUE; - } - } - - return FALSE; -} - -static gboolean -parse_rotation (ClutterActor *actor, - JsonNode *node, - RotationInfo *info) -{ - JsonArray *array; - guint len, i; - gboolean retval = FALSE; - - if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY) - { - g_warning ("Invalid node of type '%s' found, expecting an array", - json_node_type_name (node)); - return FALSE; - } - - array = json_node_get_array (node); - len = json_array_get_length (array); - - for (i = 0; i < len; i++) - { - JsonNode *element = json_array_get_element (array, i); - JsonObject *object; - JsonNode *member; - - if (JSON_NODE_TYPE (element) != JSON_NODE_OBJECT) - { - g_warning ("Invalid node of type '%s' found, expecting an object", - json_node_type_name (element)); - return FALSE; - } - - object = json_node_get_object (element); - - if (json_object_has_member (object, "x-axis")) - { - member = json_object_get_member (object, "x-axis"); - - info->axis = CLUTTER_X_AXIS; - - if (JSON_NODE_TYPE (member) == JSON_NODE_VALUE) - { - info->angle = json_node_get_double (member); - retval = TRUE; - } - else if (JSON_NODE_TYPE (member) == JSON_NODE_ARRAY) - retval = parse_rotation_array (actor, - json_node_get_array (member), - info); - else - retval = FALSE; - } - else if (json_object_has_member (object, "y-axis")) - { - member = json_object_get_member (object, "y-axis"); - - info->axis = CLUTTER_Y_AXIS; - - if (JSON_NODE_TYPE (member) == JSON_NODE_VALUE) - { - info->angle = json_node_get_double (member); - retval = TRUE; - } - else if (JSON_NODE_TYPE (member) == JSON_NODE_ARRAY) - retval = parse_rotation_array (actor, - json_node_get_array (member), - info); - else - retval = FALSE; - } - else if (json_object_has_member (object, "z-axis")) - { - member = json_object_get_member (object, "z-axis"); - - info->axis = CLUTTER_Z_AXIS; - - if (JSON_NODE_TYPE (member) == JSON_NODE_VALUE) - { - info->angle = json_node_get_double (member); - retval = TRUE; - } - else if (JSON_NODE_TYPE (member) == JSON_NODE_ARRAY) - retval = parse_rotation_array (actor, - json_node_get_array (member), - info); - else - retval = FALSE; - } - } - - return retval; -} - -static GSList * -parse_actor_metas (ClutterScript *script, - ClutterActor *actor, - JsonNode *node) -{ - GList *elements, *l; - GSList *retval = NULL; - - if (!JSON_NODE_HOLDS_ARRAY (node)) - return NULL; - - elements = json_array_get_elements (json_node_get_array (node)); - - for (l = elements; l != NULL; l = l->next) - { - JsonNode *element = l->data; - const gchar *id_ = _clutter_script_get_id_from_node (element); - GObject *meta; - - if (id_ == NULL || *id_ == '\0') - continue; - - meta = clutter_script_get_object (script, id_); - if (meta == NULL) - continue; - - retval = g_slist_prepend (retval, meta); - } - - g_list_free (elements); - - return g_slist_reverse (retval); -} - -static ClutterMargin * -parse_margin (ClutterActor *self, - JsonNode *node) -{ - ClutterMargin *margin; - JsonArray *array; - - if (!JSON_NODE_HOLDS_ARRAY (node)) - { - g_warning ("The margin property must be an array of 1 to 4 elements"); - return NULL; - } - - margin = clutter_margin_new (); - array = json_node_get_array (node); - switch (json_array_get_length (array)) - { - case 1: - margin->top = margin->right = margin->bottom = margin->left = - parse_units (self, 0, json_array_get_element (array, 0)); - break; - - case 2: - margin->top = margin->bottom = - parse_units (self, 0, json_array_get_element (array, 0)); - margin->right = margin->left = - parse_units (self, 0, json_array_get_element (array, 1)); - break; - - case 3: - margin->top = - parse_units (self, 0, json_array_get_element (array, 0)); - margin->right = margin->left = - parse_units (self, 0, json_array_get_element (array, 1)); - margin->bottom = - parse_units (self, 0, json_array_get_element (array, 2)); - break; - - case 4: - margin->top = - parse_units (self, 0, json_array_get_element (array, 0)); - margin->right = - parse_units (self, 0, json_array_get_element (array, 1)); - margin->bottom = - parse_units (self, 0, json_array_get_element (array, 2)); - margin->left = - parse_units (self, 0, json_array_get_element (array, 3)); - break; - - default: - g_warning ("The margin property must be an array of 1 to 4 elements"); - clutter_margin_free (margin); - return NULL; - } - return margin; -} - -static gboolean -clutter_actor_parse_custom_node (ClutterScriptable *scriptable, - ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node) -{ - ClutterActor *actor = CLUTTER_ACTOR (scriptable); - gboolean retval = FALSE; - - if ((name[0] == 'x' && name[1] == '\0') || - (name[0] == 'y' && name[1] == '\0') || - (strcmp (name, "width") == 0) || - (strcmp (name, "height") == 0)) - { - ParseDimension dimension; - gfloat units; - - if (name[0] == 'x') - dimension = PARSE_X; - else if (name[0] == 'y') - dimension = PARSE_Y; - else if (name[0] == 'w') - dimension = PARSE_WIDTH; - else if (name[0] == 'h') - dimension = PARSE_HEIGHT; - else - return FALSE; - - units = parse_units (actor, dimension, node); - - /* convert back to pixels: all properties are pixel-based */ - g_value_init (value, G_TYPE_FLOAT); - g_value_set_float (value, units); - - retval = TRUE; - } - else if (strcmp (name, "rotation") == 0) - { - RotationInfo *info; - - info = g_new0 (RotationInfo, 1); - retval = parse_rotation (actor, node, info); - - if (retval) - { - g_value_init (value, G_TYPE_POINTER); - g_value_set_pointer (value, info); - } - else - g_free (info); - } - else if (strcmp (name, "actions") == 0 || - strcmp (name, "constraints") == 0 || - strcmp (name, "effects") == 0) - { - GSList *l; - - l = parse_actor_metas (script, actor, node); - - g_value_init (value, G_TYPE_POINTER); - g_value_set_pointer (value, l); - - retval = TRUE; - } - else if (strcmp (name, "margin") == 0) - { - ClutterMargin *margin = parse_margin (actor, node); - - if (margin) - { - g_value_init (value, CLUTTER_TYPE_MARGIN); - g_value_set_boxed (value, margin); - retval = TRUE; - } - } - - return retval; -} - -static void -clutter_actor_set_custom_property (ClutterScriptable *scriptable, - ClutterScript *script, - const gchar *name, - const GValue *value) -{ - ClutterActor *actor = CLUTTER_ACTOR (scriptable); - -#ifdef CLUTTER_ENABLE_DEBUG - if (G_UNLIKELY (CLUTTER_HAS_DEBUG (SCRIPT))) - { - gchar *tmp = g_strdup_value_contents (value); - - CLUTTER_NOTE (SCRIPT, - "in ClutterActor::set_custom_property('%s') = %s", - name, - tmp); - - g_free (tmp); - } -#endif /* CLUTTER_ENABLE_DEBUG */ - - if (strcmp (name, "rotation") == 0) - { - RotationInfo *info; - - if (!G_VALUE_HOLDS (value, G_TYPE_POINTER)) - return; - - info = g_value_get_pointer (value); - - clutter_actor_set_rotation_angle (actor, info->axis, info->angle); - - g_free (info); - - return; - } - - if (strcmp (name, "actions") == 0 || - strcmp (name, "constraints") == 0 || - strcmp (name, "effects") == 0) - { - GSList *metas, *l; - - if (!G_VALUE_HOLDS (value, G_TYPE_POINTER)) - return; - - metas = g_value_get_pointer (value); - for (l = metas; l != NULL; l = l->next) - { - if (name[0] == 'a') - clutter_actor_add_action (actor, l->data); - - if (name[0] == 'c') - clutter_actor_add_constraint (actor, l->data); - - if (name[0] == 'e') - clutter_actor_add_effect (actor, l->data); - } - - g_slist_free (metas); - - return; - } - if (strcmp (name, "margin") == 0) - { - clutter_actor_set_margin (actor, g_value_get_boxed (value)); - return; - } - - g_object_set_property (G_OBJECT (scriptable), name, value); -} - -static void -clutter_scriptable_iface_init (ClutterScriptableIface *iface) -{ - iface->parse_custom_node = clutter_actor_parse_custom_node; - iface->set_custom_property = clutter_actor_set_custom_property; -} - static gboolean get_layout_from_animation_property (ClutterActor *actor, const gchar *name, diff --git a/clutter/clutter/clutter-autocleanups.h b/clutter/clutter/clutter-autocleanups.h index cd65f17b5..8c2b141fb 100644 --- a/clutter/clutter/clutter-autocleanups.h +++ b/clutter/clutter/clutter-autocleanups.h @@ -57,8 +57,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPathConstraint, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPath, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPropertyTransition, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterRotateAction, g_object_unref) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScriptable, g_object_unref) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScript, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterSettings, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterShaderEffect, g_object_unref) diff --git a/clutter/clutter/clutter-interval.c b/clutter/clutter/clutter-interval.c index a748d6d16..7621e14c1 100644 --- a/clutter/clutter/clutter-interval.c +++ b/clutter/clutter/clutter-interval.c @@ -55,8 +55,6 @@ #include "clutter/clutter-interval.h" #include "clutter/clutter-private.h" #include "clutter/clutter-units.h" -#include "clutter/clutter-scriptable.h" -#include "clutter/clutter-script-private.h" enum { @@ -87,14 +85,10 @@ struct _ClutterIntervalPrivate GValue *values; }; -static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); - G_DEFINE_TYPE_WITH_CODE (ClutterInterval, clutter_interval, G_TYPE_INITIALLY_UNOWNED, - G_ADD_PRIVATE (ClutterInterval) - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE, - clutter_scriptable_iface_init)); + G_ADD_PRIVATE (ClutterInterval)); static gboolean @@ -466,47 +460,6 @@ clutter_interval_get_property (GObject *gobject, } } -static gboolean -clutter_interval_parse_custom_node (ClutterScriptable *scriptable, - ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node) -{ - ClutterIntervalPrivate *priv = CLUTTER_INTERVAL (scriptable)->priv; - - if ((strcmp (name, "initial") == 0) || (strcmp (name, "final") == 0)) - { - g_value_init (value, priv->value_type); - return _clutter_script_parse_node (script, value, name, node, NULL); - } - - return FALSE; -} - -static void -clutter_interval_set_custom_property (ClutterScriptable *scriptable, - ClutterScript *script, - const gchar *name, - const GValue *value) -{ - ClutterInterval *self = CLUTTER_INTERVAL (scriptable); - - if (strcmp (name, "initial") == 0) - clutter_interval_set_initial_value (self, value); - else if (strcmp (name, "final") == 0) - clutter_interval_set_final_value (self, value); - else - g_object_set_property (G_OBJECT (scriptable), name, value); -} - -static void -clutter_scriptable_iface_init (ClutterScriptableIface *iface) -{ - iface->parse_custom_node = clutter_interval_parse_custom_node; - iface->set_custom_property = clutter_interval_set_custom_property; -} - static void clutter_interval_class_init (ClutterIntervalClass *klass) { diff --git a/clutter/clutter/clutter-layout-manager.c b/clutter/clutter/clutter-layout-manager.c index 86f5f23de..f3618ddeb 100644 --- a/clutter/clutter/clutter-layout-manager.c +++ b/clutter/clutter/clutter-layout-manager.c @@ -86,47 +86,6 @@ * Where `manager` is the #ClutterLayoutManager, `container` is the * #ClutterActor using the #ClutterLayoutManager, and `actor` is * the #ClutterActor child of the #ClutterActor. - * - * ## Using ClutterLayoutManager with ClutterScript - * - * #ClutterLayoutManager instances can be created in the same way - * as other objects in #ClutterScript; properties can be set using the - * common syntax. - * - * Layout properties can be set on children of a container with - * a #ClutterLayoutManager using the `layout::` modifier on the property - * name, for instance: - * - * ```json - * { - * "type" : "ClutterActor", - * "layout-manager" : { "type" : "ClutterGridLayout" }, - * "children" : [ - * { - * "type" : "ClutterText", - * "text" : "Some text", - * - * "layout::row" : 0, - * "layout::column" : 0, - * "layout::x-align" : "left", - * "layout::y-align" : "center", - * "layout::x-expand" : true, - * "layout::y-expand" : true - * }, - * { - * "type" : "ClutterText", - * "text" : "Some more text", - * - * "layout::row" : 0, - * "layout::column" : 1, - * "layout::x-align" : "right", - * "layout::y-align" : "center", - * "layout::x-expand" : true, - * "layout::y-expand" : true - * } - * ] - * } - * ``` */ #include "clutter/clutter-build-config.h" diff --git a/clutter/clutter/clutter-paint-node-private.h b/clutter/clutter/clutter-paint-node-private.h index 8d282abc6..c185b5efa 100644 --- a/clutter/clutter/clutter-paint-node-private.h +++ b/clutter/clutter/clutter-paint-node-private.h @@ -25,7 +25,10 @@ #pragma once #include + +#ifdef CLUTTER_ENABLE_DEBUG #include +#endif #include "clutter/clutter-backend.h" #include "clutter/clutter-paint-context.h" @@ -72,7 +75,9 @@ struct _ClutterPaintNodeClass void (* post_draw) (ClutterPaintNode *node, ClutterPaintContext *paint_context); +#ifdef CLUTTER_ENABLE_DEBUG JsonNode*(* serialize) (ClutterPaintNode *node); +#endif CoglFramebuffer *(* get_framebuffer) (ClutterPaintNode *node); }; diff --git a/clutter/clutter/clutter-paint-node.c b/clutter/clutter/clutter-paint-node.c index aadeafa09..08e497b39 100644 --- a/clutter/clutter/clutter-paint-node.c +++ b/clutter/clutter/clutter-paint-node.c @@ -50,9 +50,12 @@ #include "clutter/clutter-build-config.h" #include -#include #include +#ifdef CLUTTER_ENABLE_DEBUG +#include +#endif + #include "cogl/cogl.h" #include "clutter/clutter-paint-node-private.h" #include "clutter/clutter-debug.h" diff --git a/clutter/clutter/clutter-paint-nodes.c b/clutter/clutter/clutter-paint-nodes.c index d7dd91e64..25ef795bc 100644 --- a/clutter/clutter/clutter-paint-nodes.c +++ b/clutter/clutter/clutter-paint-nodes.c @@ -280,6 +280,7 @@ clutter_dummy_node_pre_draw (ClutterPaintNode *node, return TRUE; } +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_dummy_node_serialize (ClutterPaintNode *node) { @@ -303,6 +304,7 @@ clutter_dummy_node_serialize (ClutterPaintNode *node) return res; } +#endif static CoglFramebuffer * clutter_dummy_node_get_framebuffer (ClutterPaintNode *node) @@ -328,7 +330,9 @@ clutter_dummy_node_class_init (ClutterDummyNodeClass *klass) ClutterPaintNodeClass *node_class = CLUTTER_PAINT_NODE_CLASS (klass); node_class->pre_draw = clutter_dummy_node_pre_draw; +#ifdef CLUTTER_ENABLE_DEBUG node_class->serialize = clutter_dummy_node_serialize; +#endif node_class->get_framebuffer = clutter_dummy_node_get_framebuffer; node_class->finalize = clutter_dummy_node_finalize; } @@ -488,6 +492,7 @@ clutter_pipeline_node_post_draw (ClutterPaintNode *node, { } +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_pipeline_node_serialize (ClutterPaintNode *node) { @@ -527,6 +532,7 @@ clutter_pipeline_node_serialize (ClutterPaintNode *node) return res; } +#endif static void clutter_pipeline_node_class_init (ClutterPipelineNodeClass *klass) @@ -538,7 +544,9 @@ clutter_pipeline_node_class_init (ClutterPipelineNodeClass *klass) node_class->draw = clutter_pipeline_node_draw; node_class->post_draw = clutter_pipeline_node_post_draw; node_class->finalize = clutter_pipeline_node_finalize; +#ifdef CLUTTER_ENABLE_DEBUG node_class->serialize = clutter_pipeline_node_serialize; +#endif } static void @@ -865,6 +873,7 @@ clutter_text_node_draw (ClutterPaintNode *node, } } +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_text_node_serialize (ClutterPaintNode *node) { @@ -905,6 +914,7 @@ clutter_text_node_serialize (ClutterPaintNode *node) return res; } +#endif static void clutter_text_node_class_init (ClutterTextNodeClass *klass) @@ -914,7 +924,9 @@ clutter_text_node_class_init (ClutterTextNodeClass *klass) node_class->pre_draw = clutter_text_node_pre_draw; node_class->draw = clutter_text_node_draw; node_class->finalize = clutter_text_node_finalize; +#ifdef CLUTTER_ENABLE_DEBUG node_class->serialize = clutter_text_node_serialize; +#endif } static void @@ -1151,6 +1163,7 @@ clutter_actor_node_post_draw (ClutterPaintNode *node, } } +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_actor_node_serialize (ClutterPaintNode *node) { @@ -1169,6 +1182,7 @@ clutter_actor_node_serialize (ClutterPaintNode *node) return json_builder_get_root (builder); } +#endif static void clutter_actor_node_class_init (ClutterActorNodeClass *klass) @@ -1179,7 +1193,9 @@ clutter_actor_node_class_init (ClutterActorNodeClass *klass) node_class->pre_draw = clutter_actor_node_pre_draw; node_class->draw = clutter_actor_node_draw; node_class->post_draw = clutter_actor_node_post_draw; +#ifdef CLUTTER_ENABLE_DEBUG node_class->serialize = clutter_actor_node_serialize; +#endif } static void @@ -1235,6 +1251,7 @@ struct _ClutterEffectNodeClass G_DEFINE_TYPE (ClutterEffectNode, clutter_effect_node, CLUTTER_TYPE_PAINT_NODE) +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_effect_node_serialize (ClutterPaintNode *node) { @@ -1264,14 +1281,18 @@ clutter_effect_node_serialize (ClutterPaintNode *node) return json_builder_get_root (builder); } +#endif static void clutter_effect_node_class_init (ClutterEffectNodeClass *klass) { +#ifdef CLUTTER_ENABLE_DEBUG + ClutterPaintNodeClass *node_class; node_class = CLUTTER_PAINT_NODE_CLASS (klass); node_class->serialize = clutter_effect_node_serialize; +#endif } static void @@ -1434,6 +1455,7 @@ clutter_layer_node_finalize (ClutterPaintNode *node) CLUTTER_PAINT_NODE_CLASS (clutter_layer_node_parent_class)->finalize (node); } +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_layer_node_serialize (ClutterPaintNode *node) { @@ -1452,6 +1474,7 @@ clutter_layer_node_serialize (ClutterPaintNode *node) return json_builder_get_root (builder); } +#endif static void clutter_layer_node_class_init (ClutterLayerNodeClass *klass) @@ -1462,7 +1485,9 @@ clutter_layer_node_class_init (ClutterLayerNodeClass *klass) node_class->pre_draw = clutter_layer_node_pre_draw; node_class->post_draw = clutter_layer_node_post_draw; node_class->finalize = clutter_layer_node_finalize; +#ifdef CLUTTER_ENABLE_DEBUG node_class->serialize = clutter_layer_node_serialize; +#endif } static void @@ -1591,6 +1616,7 @@ clutter_blit_node_finalize (ClutterPaintNode *node) CLUTTER_PAINT_NODE_CLASS (clutter_blit_node_parent_class)->finalize (node); } +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_blit_node_serialize (ClutterPaintNode *node) { @@ -1608,6 +1634,7 @@ clutter_blit_node_serialize (ClutterPaintNode *node) return json_builder_get_root (builder); } +#endif static void clutter_blit_node_class_init (ClutterBlitNodeClass *klass) @@ -1618,7 +1645,9 @@ clutter_blit_node_class_init (ClutterBlitNodeClass *klass) node_class->pre_draw = clutter_blit_node_pre_draw; node_class->draw = clutter_blit_node_draw; node_class->finalize = clutter_blit_node_finalize; +#ifdef CLUTTER_ENABLE_DEBUG node_class->serialize = clutter_blit_node_serialize; +#endif } static void @@ -1725,6 +1754,7 @@ clutter_blur_node_finalize (ClutterPaintNode *node) CLUTTER_PAINT_NODE_CLASS (clutter_blur_node_parent_class)->finalize (node); } +#ifdef CLUTTER_ENABLE_DEBUG static JsonNode * clutter_blur_node_serialize (ClutterPaintNode *node) { @@ -1742,6 +1772,7 @@ clutter_blur_node_serialize (ClutterPaintNode *node) return json_builder_get_root (builder); } +#endif static void clutter_blur_node_class_init (ClutterBlurNodeClass *klass) @@ -1751,7 +1782,9 @@ clutter_blur_node_class_init (ClutterBlurNodeClass *klass) node_class = CLUTTER_PAINT_NODE_CLASS (klass); node_class->post_draw = clutter_blur_node_post_draw; node_class->finalize = clutter_blur_node_finalize; +#ifdef CLUTTER_ENABLE_DEBUG node_class->serialize = clutter_blur_node_serialize; +#endif } static void diff --git a/clutter/clutter/clutter-script-parser.c b/clutter/clutter/clutter-script-parser.c deleted file mode 100644 index 7b42a84ce..000000000 --- a/clutter/clutter/clutter-script-parser.c +++ /dev/null @@ -1,1903 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd - * Copyright (C) 2009 Intel Corportation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Original author: - * - * Emmanuele Bassi - */ - -#include "clutter/clutter-build-config.h" - -#include -#include - -#include -#include - -#include "clutter/clutter-actor.h" -#include "clutter/clutter-debug.h" -#include "clutter/clutter-enum-types.h" - -#include "clutter/clutter-script.h" -#include "clutter/clutter-script-private.h" -#include "clutter/clutter-scriptable.h" - -#include "clutter/clutter-stage-manager.h" - -#include "clutter/clutter-private.h" - -static void clutter_script_parser_object_end (JsonParser *parser, - JsonObject *object); -static void clutter_script_parser_parse_end (JsonParser *parser); - -#define clutter_script_parser_get_type _clutter_script_parser_get_type - -G_DEFINE_TYPE (ClutterScriptParser, clutter_script_parser, JSON_TYPE_PARSER); - -static void -clutter_script_parser_class_init (ClutterScriptParserClass *klass) -{ - JsonParserClass *parser_class = JSON_PARSER_CLASS (klass); - - parser_class->object_end = clutter_script_parser_object_end; - parser_class->parse_end = clutter_script_parser_parse_end; -} - -static void -clutter_script_parser_init (ClutterScriptParser *parser) -{ -} - -GType -_clutter_script_get_type_from_symbol (const gchar *symbol) -{ - static GModule *module = NULL; - GTypeGetFunc func; - GType gtype = G_TYPE_INVALID; - - if (!module) - module = g_module_open (NULL, 0); - - if (g_module_symbol (module, symbol, (gpointer)&func)) - gtype = func (); - - return gtype; -} - -GType -_clutter_script_get_type_from_class (const gchar *name) -{ - static GModule *module = NULL; - GString *symbol_name = g_string_sized_new (64); - GType gtype = G_TYPE_INVALID; - GTypeGetFunc func; - gchar *symbol; - gint i; - - if (G_UNLIKELY (!module)) - module = g_module_open (NULL, 0); - - for (i = 0; name[i] != '\0'; i++) - { - gchar c = name[i]; - - /* the standard naming policy for GObject-based libraries - * is: - * - * NAME := INITIAL_WORD WORD+ - * INITIAL_WORD := [A-Z][a-z0-9]* - * WORD := [A-Z]{1,2}[a-z0-9]+ | [A-Z]{2,} - * - * for instance: - * - * GString -> g_string - * GtkCTree -> gtk_ctree - * ClutterX11TexturePixmap -> clutter_x11_texture_pixmap - * - * see: - * - * http://mail.gnome.org/archives/gtk-devel-list/2007-June/msg00022.html - * - * and: - * - * http://git.gnome.org/cgit/gtk+/plain/gtk/gtkbuilderparser.c - */ - - if ((c == g_ascii_toupper (c) && - i > 0 && name[i - 1] != g_ascii_toupper (name[i - 1])) || - (i > 2 && name[i] == g_ascii_toupper (name[i]) && - name[i - 1] == g_ascii_toupper (name[i - 1]) && - name[i - 2] == g_ascii_toupper (name[i - 2]))) - g_string_append_c (symbol_name, '_'); - - g_string_append_c (symbol_name, g_ascii_tolower (c)); - } - - g_string_append (symbol_name, "_get_type"); - - symbol = g_string_free (symbol_name, FALSE); - - if (g_module_symbol (module, symbol, (gpointer)&func)) - { - CLUTTER_NOTE (SCRIPT, "Type function: %s", symbol); - gtype = func (); - } - - g_free (symbol); - - return gtype; -} - -/* - * clutter_script_enum_from_string: - * @type: a #GType for an enumeration type - * @string: the enumeration value as a string - * @enum_value: (out): return location for the enumeration value as an integer - * - * Converts an enumeration value inside @string into a numeric - * value and places it into @enum_value. - * - * The enumeration value can be an integer, the enumeration nick - * or the enumeration name, as part of the #GEnumValue structure. - * - * Return value: %TRUE if the conversion was successful. - */ -gboolean -_clutter_script_enum_from_string (GType type, - const gchar *string, - gint *enum_value) -{ - GEnumClass *eclass; - GEnumValue *ev; - gchar *endptr; - gint value; - gboolean retval = TRUE; - - g_return_val_if_fail (G_TYPE_IS_ENUM (type), 0); - g_return_val_if_fail (string != NULL, 0); - - value = strtoul (string, &endptr, 0); - if (endptr != string) /* parsed a number */ - *enum_value = value; - else - { - eclass = g_type_class_ref (type); - ev = g_enum_get_value_by_name (eclass, string); - if (!ev) - ev = g_enum_get_value_by_nick (eclass, string); - - if (ev) - *enum_value = ev->value; - else - retval = FALSE; - - g_type_class_unref (eclass); - } - - return retval; -} - -gboolean -_clutter_script_flags_from_string (GType type, - const gchar *string, - gint *flags_value) -{ - gchar *endptr, *prevptr; - guint i, j, ret, value; - gchar *flagstr; - GFlagsValue *fv; - const gchar *flag; - - g_return_val_if_fail (G_TYPE_IS_FLAGS (type), 0); - g_return_val_if_fail (string != NULL, 0); - - ret = TRUE; - - value = strtoul (string, &endptr, 0); - if (endptr != string) /* parsed a number */ - *flags_value = value; - else - { - GFlagsClass *fclass; - - fclass = g_type_class_ref (type); - - flagstr = g_strdup (string); - for (value = i = j = 0; ; i++) - { - gboolean eos = (flagstr[i] == '\0') ? TRUE : FALSE; - - if (!eos && flagstr[i] != '|') - continue; - - flag = &flagstr[j]; - endptr = &flagstr[i]; - - if (!eos) - { - flagstr[i++] = '\0'; - j = i; - } - - /* trim spaces */ - for (;;) - { - gunichar ch = g_utf8_get_char (flag); - if (!g_unichar_isspace (ch)) - break; - - flag = g_utf8_next_char (flag); - } - - while (endptr > flag) - { - gunichar ch; - - prevptr = g_utf8_prev_char (endptr); - - ch = g_utf8_get_char (prevptr); - if (!g_unichar_isspace (ch)) - break; - - endptr = prevptr; - } - - if (endptr > flag) - { - *endptr = '\0'; - - fv = g_flags_get_value_by_name (fclass, flag); - - if (!fv) - fv = g_flags_get_value_by_nick (fclass, flag); - - if (fv) - value |= fv->value; - else - { - ret = FALSE; - break; - } - } - - if (eos) - { - *flags_value = value; - break; - } - } - - g_free (flagstr); - - g_type_class_unref (fclass); - } - - return ret; -} - -static gboolean -parse_knot_from_array (JsonArray *array, - ClutterKnot *knot) -{ - if (json_array_get_length (array) != 2) - return FALSE; - - knot->x = json_array_get_int_element (array, 0); - knot->y = json_array_get_int_element (array, 1); - - return TRUE; -} - -static gboolean -parse_knot_from_object (JsonObject *object, - ClutterKnot *knot) -{ - if (json_object_has_member (object, "x")) - knot->x = json_object_get_int_member (object, "x"); - else - knot->x = 0; - - if (json_object_has_member (object, "y")) - knot->y = json_object_get_int_member (object, "y"); - else - knot->y = 0; - - return TRUE; -} - -gboolean -_clutter_script_parse_knot (ClutterScript *script, - JsonNode *node, - ClutterKnot *knot) -{ - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE); - g_return_val_if_fail (node != NULL, FALSE); - g_return_val_if_fail (knot != NULL, FALSE); - - switch (JSON_NODE_TYPE (node)) - { - case JSON_NODE_ARRAY: - return parse_knot_from_array (json_node_get_array (node), knot); - - case JSON_NODE_OBJECT: - return parse_knot_from_object (json_node_get_object (node), knot); - - default: - break; - } - - return FALSE; -} - -static gboolean -parse_rect_from_array (JsonArray *array, - graphene_rect_t *rect) -{ - if (json_array_get_length (array) != 4) - return FALSE; - - graphene_rect_init (rect, - json_array_get_int_element (array, 0), - json_array_get_int_element (array, 1), - json_array_get_int_element (array, 2), - json_array_get_int_element (array, 3)); - - return TRUE; -} - -static gboolean -parse_rect_from_object (JsonObject *object, - graphene_rect_t *rect) -{ - if (json_object_has_member (object, "x")) - rect->origin.x = json_object_get_int_member (object, "x"); - else - rect->origin.x = 0; - - if (json_object_has_member (object, "y")) - rect->origin.y = json_object_get_int_member (object, "y"); - else - rect->origin.y = 0; - - if (json_object_has_member (object, "width")) - rect->size.width = json_object_get_int_member (object, "width"); - else - rect->size.width = 0; - - if (json_object_has_member (object, "height")) - rect->size.height = json_object_get_int_member (object, "height"); - else - rect->size.height = 0; - - return TRUE; -} - -gboolean -_clutter_script_parse_rect (ClutterScript *script, - JsonNode *node, - graphene_rect_t *rect) -{ - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE); - g_return_val_if_fail (node != NULL, FALSE); - g_return_val_if_fail (rect != NULL, FALSE); - - switch (JSON_NODE_TYPE (node)) - { - case JSON_NODE_ARRAY: - return parse_rect_from_array (json_node_get_array (node), rect); - - case JSON_NODE_OBJECT: - return parse_rect_from_object (json_node_get_object (node), rect); - - default: - break; - } - - return FALSE; -} - -static gboolean -parse_color_from_array (JsonArray *array, - ClutterColor *color) -{ - if (json_array_get_length (array) != 3 || - json_array_get_length (array) != 4) - return FALSE; - - color->red = CLAMP (json_array_get_int_element (array, 0), 0, 255); - color->green = CLAMP (json_array_get_int_element (array, 1), 0, 255); - color->blue = CLAMP (json_array_get_int_element (array, 2), 0, 255); - - if (json_array_get_length (array) == 4) - color->alpha = CLAMP (json_array_get_int_element (array, 3), 0, 255); - else - color->alpha = 255; - - return TRUE; -} - -static gboolean -parse_color_from_object (JsonObject *object, - ClutterColor *color) -{ - if (json_object_has_member (object, "red")) - color->red = CLAMP (json_object_get_int_member (object, "red"), 0, 255); - else - color->red = 0; - - if (json_object_has_member (object, "green")) - color->green = CLAMP (json_object_get_int_member (object, "green"), 0, 255); - else - color->green = 0; - - if (json_object_has_member (object, "blue")) - color->blue = CLAMP (json_object_get_int_member (object, "blue"), 0, 255); - else - color->blue = 0; - - if (json_object_has_member (object, "alpha")) - color->alpha = CLAMP (json_object_get_int_member (object, "alpha"), 0, 255); - else - color->alpha = 255; - - return TRUE; -} - -gboolean -_clutter_script_parse_color (ClutterScript *script, - JsonNode *node, - ClutterColor *color) -{ - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE); - g_return_val_if_fail (node != NULL, FALSE); - g_return_val_if_fail (color != NULL, FALSE); - - switch (JSON_NODE_TYPE (node)) - { - case JSON_NODE_ARRAY: - return parse_color_from_array (json_node_get_array (node), color); - - case JSON_NODE_OBJECT: - return parse_color_from_object (json_node_get_object (node), color); - - case JSON_NODE_VALUE: - return clutter_color_from_string (color, json_node_get_string (node)); - - default: - break; - } - - return FALSE; -} - -static gboolean -parse_point_from_array (JsonArray *array, - graphene_point_t *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, - graphene_point_t *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, - graphene_point_t *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, - graphene_size_t *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, - graphene_size_t *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, - graphene_size_t *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) -{ - JsonObject *object; - - switch (JSON_NODE_TYPE (node)) - { - case JSON_NODE_OBJECT: - object = json_node_get_object (node); - if (json_object_has_member (object, "id")) - return json_object_get_string_member (object, "id"); - break; - - case JSON_NODE_VALUE: - return json_node_get_string (node); - - default: - break; - } - - return NULL; -} - -static GList * -parse_children (ObjectInfo *oinfo, - JsonNode *node) -{ - JsonArray *array; - GList *retval; - guint array_len, i; - - if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY) - return NULL; - - retval = oinfo->children; - - array = json_node_get_array (node); - array_len = json_array_get_length (array); - - for (i = 0; i < array_len; i++) - { - JsonNode *child = json_array_get_element (array, i); - const gchar *id_; - - id_ = _clutter_script_get_id_from_node (child); - if (id_ != NULL) - retval = g_list_prepend (retval, g_strdup (id_)); - } - - return g_list_reverse (retval); -} - -static GList * -parse_signals (ClutterScript *script, - ObjectInfo *oinfo, - JsonNode *node) -{ - JsonArray *array; - GList *retval; - guint array_len, i; - - if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY) - { - _clutter_script_warn_invalid_value (script, "signals", "Array", node); - return NULL; - } - - retval = oinfo->signals; - array = json_node_get_array (node); - array_len = json_array_get_length (array); - - for (i = 0; i < array_len; i++) - { - JsonNode *val = json_array_get_element (array, i); - SignalInfo *sinfo = NULL; - JsonObject *object; - const gchar *name; - - if (JSON_NODE_TYPE (val) != JSON_NODE_OBJECT) - { - _clutter_script_warn_invalid_value (script, - "signals array", "Object", - node); - continue; - } - - object = json_node_get_object (val); - - /* mandatory: "name" */ - if (!json_object_has_member (object, "name")) - { - _clutter_script_warn_missing_attribute (script, NULL, "name"); - continue; - } - else - { - name = json_object_get_string_member (object, "name"); - if (!name) - { - _clutter_script_warn_invalid_value (script, - "name", "string", - val); - continue; - } - } - - /* mandatory: "target-state" or "handler" */ - if (json_object_has_member (object, "target-state")) - { - const gchar *state = NULL; - const gchar *target = NULL; - gboolean warp_to = FALSE; - - target = json_object_get_string_member (object, "target-state"); - if (target == NULL) - { - _clutter_script_warn_invalid_value (script, - "target-state", "string", - val); - continue; - } - - if (json_object_has_member (object, "states")) - state = json_object_get_string_member (object, "states"); - - if (json_object_has_member (object, "warp")) - warp_to = json_object_get_boolean_member (object, "warp"); - - CLUTTER_NOTE (SCRIPT, - "Added signal '%s' (states:%s, target-state:%s, warp:%s)", - name, - state != NULL ? state : "", target, - warp_to ? "true" : "false"); - - sinfo = g_new0 (SignalInfo, 1); - sinfo->is_handler = FALSE; - sinfo->name = g_strdup (name); - sinfo->state = g_strdup (state); - sinfo->target = g_strdup (target); - sinfo->warp_to = warp_to; - } - else if (json_object_has_member (object, "handler")) - { - const gchar *handler; - const gchar *connect; - GConnectFlags flags = 0; - - handler = json_object_get_string_member (object, "handler"); - if (handler == NULL) - { - _clutter_script_warn_invalid_value (script, - "handler", "string", - val); - continue; - } - - /* optional: "object" */ - if (json_object_has_member (object, "object")) - connect = json_object_get_string_member (object, "object"); - else - connect = NULL; - - /* optional: "after" */ - if (json_object_has_member (object, "after")) - { - if (json_object_get_boolean_member (object, "after")) - flags |= G_CONNECT_AFTER; - } - - /* optional: "swapped" */ - if (json_object_has_member (object, "swapped")) - { - if (json_object_get_boolean_member (object, "swapped")) - flags |= G_CONNECT_SWAPPED; - } - - CLUTTER_NOTE (SCRIPT, - "Added signal '%s' (handler:%s, object:%s, flags:%d)", - name, - handler, connect, flags); - - sinfo = g_new0 (SignalInfo, 1); - sinfo->is_handler = TRUE; - sinfo->name = g_strdup (name); - sinfo->handler = g_strdup (handler); - sinfo->object = g_strdup (connect); - sinfo->flags = flags; - } - else - _clutter_script_warn_missing_attribute (script, - NULL, - "handler or state"); - if (sinfo != NULL) - retval = g_list_prepend (retval, sinfo); - } - - return retval; -} - -static void -clutter_script_parser_object_end (JsonParser *json_parser, - JsonObject *object) -{ - ClutterScriptParser *parser = CLUTTER_SCRIPT_PARSER (json_parser); - ClutterScript *script = parser->script; - ObjectInfo *oinfo; - JsonNode *val; - const gchar *id_; - GList *members, *l; - - /* if the object definition does not have an 'id' field we'll - * fake one for it... - */ - if (!json_object_has_member (object, "id")) - { - gchar *fake; - - /* ... unless it doesn't even have a type - in which case - * it is an internal object definition and we're not - * supposed to touch it - */ - if (!json_object_has_member (object, "type")) - return; - - fake = _clutter_script_generate_fake_id (script); - json_object_set_string_member (object, "id", fake); - - CLUTTER_NOTE (SCRIPT, - "Adding fake id '%s' to object of type '%s'", - json_object_get_string_member (object, "id"), - json_object_get_string_member (object, "type")); - - g_free (fake); - } - - if (!json_object_has_member (object, "type")) - { - val = json_object_get_member (object, "id"); - - _clutter_script_warn_missing_attribute (script, - json_node_get_string (val), - "type"); - return; - } - - id_ = json_object_get_string_member (object, "id"); - CLUTTER_NOTE (SCRIPT, "Getting object info for object '%s'", id_); - - oinfo = _clutter_script_get_object_info (script, id_); - if (oinfo == NULL) - { - const gchar *class_name; - - oinfo = g_new0 (ObjectInfo, 1); - oinfo->merge_id = _clutter_script_get_last_merge_id (script); - oinfo->id = g_strdup (id_); - oinfo->has_unresolved = TRUE; - - class_name = json_object_get_string_member (object, "type"); - oinfo->class_name = g_strdup (class_name); - - if (json_object_has_member (object, "type_func")) - { - const gchar *type_func; - - type_func = json_object_get_string_member (object, "type_func"); - oinfo->type_func = g_strdup (type_func); - - /* remove the type_func member; we don't want it to - * pollute the object members - */ - json_object_remove_member (object, "type_func"); - } - } - - if (json_object_has_member (object, "children")) - { - val = json_object_get_member (object, "children"); - oinfo->children = parse_children (oinfo, val); - - json_object_remove_member (object, "children"); - - oinfo->has_unresolved = TRUE; - } - - if (json_object_has_member (object, "signals")) - { - val = json_object_get_member (object, "signals"); - oinfo->signals = parse_signals (script, oinfo, val); - - json_object_remove_member (object, "signals"); - - oinfo->has_unresolved = TRUE; - } - - if (strcmp (oinfo->class_name, "ClutterStage") == 0 && - json_object_has_member (object, "is-default")) - { - oinfo->is_actor = TRUE; - oinfo->is_stage = TRUE; - oinfo->is_stage_default = - json_object_get_boolean_member (object, "is-default"); - - json_object_remove_member (object, "is-default"); - } - else - oinfo->is_stage_default = FALSE; - - members = json_object_get_members (object); - for (l = members; l; l = l->next) - { - const gchar *name = l->data; - PropertyInfo *pinfo; - JsonNode *node; - - CLUTTER_NOTE (SCRIPT, "Object '%s' member '%s'", - oinfo->id, - name); - - /* we have already parsed these */ - if (strcmp (name, "id") == 0 || strcmp (name, "type") == 0) - continue; - - node = json_object_get_member (object, name); - - /* this should not really happen; we're getting a list of - * member names, and if one does not map a real member - * value then it's likely that something has gone wrong - */ - if (G_UNLIKELY (node == NULL)) - { - CLUTTER_NOTE (SCRIPT, - "Empty node for member '%s' of object '%s' (type: %s)", - name, - oinfo->id, - oinfo->class_name); - continue; - } - - pinfo = g_new0 (PropertyInfo, 1); - - pinfo->name = g_strdup (name); - pinfo->node = json_node_copy (node); - pinfo->pspec = NULL; - pinfo->is_layout = g_str_has_prefix (name, "layout::") ? TRUE : FALSE; - - oinfo->properties = g_list_prepend (oinfo->properties, pinfo); - oinfo->has_unresolved = TRUE; - } - - g_list_free (members); - - CLUTTER_NOTE (SCRIPT, - "Added object '%s' (type:%s, id:%d, props:%d, signals:%d)", - oinfo->id, - oinfo->class_name, - oinfo->merge_id, - g_list_length (oinfo->properties), - g_list_length (oinfo->signals)); - - _clutter_script_add_object_info (script, oinfo); - _clutter_script_construct_object (script, oinfo); -} - -static void -clutter_script_parser_parse_end (JsonParser *parser) -{ - clutter_script_ensure_objects (CLUTTER_SCRIPT_PARSER (parser)->script); -} - -gboolean -_clutter_script_parse_translatable_string (ClutterScript *script, - JsonNode *node, - char **str) -{ - JsonObject *obj; - const char *string, *domain, *context; - const char *res; - gboolean translatable; - - if (!JSON_NODE_HOLDS_OBJECT (node)) - return FALSE; - - obj = json_node_get_object (node); - if (!(json_object_has_member (obj, "translatable") && - json_object_has_member (obj, "string"))) - return FALSE; - - translatable = json_object_get_boolean_member (obj, "translatable"); - - string = json_object_get_string_member (obj, "string"); - if (string == NULL || *string == '\0') - return FALSE; - - if (json_object_has_member (obj, "context")) - context = json_object_get_string_member (obj, "context"); - else - context = NULL; - - if (json_object_has_member (obj, "domain")) - domain = json_object_get_string_member (obj, "domain"); - else - domain = NULL; - - if (domain == NULL || *domain == '\0') - domain = clutter_script_get_translation_domain (script); - - if (translatable) - { - if (context != NULL && *context != '\0') - res = g_dpgettext2 (domain, context, string); - else - res = g_dgettext (domain, string); - } - else - res = string; - - if (str != NULL) - *str = g_strdup (res); - - return TRUE; -} - -gboolean -_clutter_script_parse_node (ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node, - GParamSpec *pspec) -{ - GValue node_value = G_VALUE_INIT; - gboolean retval = FALSE; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE); - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (node != NULL, FALSE); - - switch (JSON_NODE_TYPE (node)) - { - case JSON_NODE_OBJECT: - /* if we don't have a GParamSpec we can't infer the type - * of the property; this usually means that this property - * is a custom member that will be parsed by the Scriptable - * interface implementantion - */ - if (pspec == NULL && !G_IS_VALUE (value)) - return FALSE; - else - { - GType p_type; - ObjectInfo *oinfo; - const gchar *id_; - - if (G_IS_VALUE (value)) - p_type = G_VALUE_TYPE (value); - else - { - p_type = G_PARAM_SPEC_VALUE_TYPE (pspec); - g_value_init (value, p_type); - } - - if (g_type_is_a (p_type, G_TYPE_OBJECT)) - { - /* default GObject handling: we get the id and - * retrieve the ObjectInfo for it; since the object - * definitions are parsed leaf-first we are guaranteed - * to have a defined object at this point - */ - id_ = _clutter_script_get_id_from_node (node); - if (id_ == NULL || *id_ == '\0') - return FALSE; - - oinfo = _clutter_script_get_object_info (script, id_); - if (oinfo == NULL || oinfo->gtype == G_TYPE_INVALID ) - return FALSE; - - if (g_type_is_a (oinfo->gtype, p_type)) - { - /* force construction, even though it should - * not be necessary; we don't need the properties - * to be applied as well: they will when the - * ScriptParser finishes - */ - _clutter_script_construct_object (script, oinfo); - - g_value_set_object (value, oinfo->object); - - return TRUE; - } - } - else if (p_type == CLUTTER_TYPE_KNOT) - { - ClutterKnot knot = { 0, }; - - /* knot := { "x" : (int), "y" : (int) } */ - - if (_clutter_script_parse_knot (script, node, &knot)) - { - g_value_set_boxed (value, &knot); - return TRUE; - } - } - else if (p_type == GRAPHENE_TYPE_RECT) - { - graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO; - - /* rect := { - * "x" : (int), - * "y" : (int), - * "width" : (int), - * "height" : (int) - * } - */ - - if (_clutter_script_parse_rect (script, node, &rect)) - { - g_value_set_boxed (value, &rect); - return TRUE; - } - } - else if (p_type == CLUTTER_TYPE_COLOR) - { - ClutterColor color = { 0, }; - - /* color := { - * "red" : (int), - * "green" : (int), - * "blue" : (int), - * "alpha" : (int) - * } - */ - - if (_clutter_script_parse_color (script, node, &color)) - { - g_value_set_boxed (value, &color); - return TRUE; - } - } - else if (p_type == GRAPHENE_TYPE_POINT) - { - graphene_point_t point = GRAPHENE_POINT_INIT_ZERO; - - if (_clutter_script_parse_point (script, node, &point)) - { - g_value_set_boxed (value, &point); - return TRUE; - } - } - else if (p_type == GRAPHENE_TYPE_SIZE) - { - graphene_size_t size = GRAPHENE_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; - - if (_clutter_script_parse_translatable_string (script, node, &str)) - { - g_value_take_string (value, str); - return TRUE; - } - } - } - return FALSE; - - case JSON_NODE_ARRAY: - if (!pspec && !G_IS_VALUE (value)) - return FALSE; - else - { - if (!G_IS_VALUE (value)) - g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - - if (G_VALUE_HOLDS (value, CLUTTER_TYPE_KNOT)) - { - ClutterKnot knot = { 0, }; - - /* knot := [ (int), (int) ] */ - - if (_clutter_script_parse_knot (script, node, &knot)) - { - g_value_set_boxed (value, &knot); - return TRUE; - } - } - else if (G_VALUE_HOLDS (value, GRAPHENE_TYPE_RECT)) - { - graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO; - - /* rect := [ (int), (int), (int), (int) ] */ - - if (_clutter_script_parse_rect (script, node, &rect)) - { - g_value_set_boxed (value, &rect); - return TRUE; - } - } - else if (CLUTTER_VALUE_HOLDS_COLOR (value)) - { - ClutterColor color = { 0, }; - - /* color := [ (int), (int), (int), (int) ] */ - - if (_clutter_script_parse_color (script, node, &color)) - { - g_value_set_boxed (value, &color); - return TRUE; - } - } - else if (G_VALUE_HOLDS (value, GRAPHENE_TYPE_POINT)) - { - graphene_point_t point = GRAPHENE_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, GRAPHENE_TYPE_SIZE)) - { - graphene_size_t size = GRAPHENE_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); - guint i, array_len = json_array_get_length (array); - GPtrArray *str_array = g_ptr_array_sized_new (array_len); - - /* strv := [ (str), (str), ... ] */ - - for (i = 0; i < array_len; i++) - { - JsonNode *val = json_array_get_element (array, i); - - if (JSON_NODE_TYPE (val) != JSON_NODE_VALUE && - json_node_get_string (val) == NULL) - continue; - - g_ptr_array_add (str_array, - (gpointer) json_node_get_string (val)); - } - - g_value_set_boxed (value, str_array->pdata); - g_ptr_array_free (str_array, TRUE); - - return TRUE; - } - } - return FALSE; - - case JSON_NODE_NULL: - return FALSE; - - case JSON_NODE_VALUE: - json_node_get_value (node, &node_value); - - if (!pspec && !G_IS_VALUE (value)) - g_value_init (value, G_VALUE_TYPE (&node_value)); - else if (pspec) - g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - - switch (G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (value))) - { - /* fundamental JSON types */ - case G_TYPE_INT64: - case G_TYPE_DOUBLE: - case G_TYPE_STRING: - case G_TYPE_BOOLEAN: - g_value_copy (&node_value, value); - retval = TRUE; - break; - - case G_TYPE_INT: - g_value_set_int (value, g_value_get_int64 (&node_value)); - retval = TRUE; - break; - - case G_TYPE_UINT: - g_value_set_uint (value, (guint) g_value_get_int64 (&node_value)); - retval = TRUE; - break; - - case G_TYPE_ULONG: - g_value_set_ulong (value, (gulong) g_value_get_int64 (&node_value)); - retval = TRUE; - break; - - case G_TYPE_UCHAR: - g_value_set_uchar (value, (guchar) g_value_get_int64 (&node_value)); - retval = TRUE; - break; - - case G_TYPE_FLOAT: - if (G_VALUE_HOLDS (&node_value, G_TYPE_DOUBLE)) - { - g_value_set_float (value, g_value_get_double (&node_value)); - retval = TRUE; - } - else if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64)) - { - g_value_set_float (value, g_value_get_int64 (&node_value)); - retval = TRUE; - } - break; - - case G_TYPE_ENUM: - if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64)) - { - g_value_set_enum (value, g_value_get_int64 (&node_value)); - retval = TRUE; - } - else if (G_VALUE_HOLDS (&node_value, G_TYPE_STRING)) - { - gint enum_value; - - retval = _clutter_script_enum_from_string (G_VALUE_TYPE (value), - g_value_get_string (&node_value), - &enum_value); - if (retval) - g_value_set_enum (value, enum_value); - } - break; - - case G_TYPE_FLAGS: - if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64)) - { - g_value_set_flags (value, g_value_get_int64 (&node_value)); - retval = TRUE; - } - else if (G_VALUE_HOLDS (&node_value, G_TYPE_STRING)) - { - gint flags_value; - - retval = _clutter_script_flags_from_string (G_VALUE_TYPE (value), - g_value_get_string (&node_value), - &flags_value); - if (retval) - g_value_set_flags (value, flags_value); - } - break; - - case G_TYPE_BOXED: - if (G_VALUE_HOLDS (value, CLUTTER_TYPE_COLOR)) - { - ClutterColor color = { 0, }; - - retval = _clutter_script_parse_color (script, node, &color); - if (retval) - clutter_value_set_color (value, &color); - } - break; - - case G_TYPE_OBJECT: - if (G_VALUE_HOLDS (&node_value, G_TYPE_STRING)) - { - const gchar *str = g_value_get_string (&node_value); - GObject *object = clutter_script_get_object (script, str); - if (object) - { - CLUTTER_NOTE (SCRIPT, - "Assigning '%s' (%s) to property '%s'", - str, - G_OBJECT_TYPE_NAME (object), - name); - - g_value_set_object (value, object); - retval = TRUE; - } - } - break; - - default: - retval = FALSE; - break; - } - - if (G_VALUE_TYPE (value) == G_TYPE_GTYPE && - G_VALUE_HOLDS (&node_value, G_TYPE_STRING)) - { - const gchar *str = g_value_get_string (&node_value); - GType type = clutter_script_get_type_from_name (script, str); - g_value_set_gtype (value, type); - retval = TRUE; - } - - g_value_unset (&node_value); - break; - } - - return retval; -} - -static GList * -clutter_script_translate_parameters (ClutterScript *script, - GObject *object, - const gchar *name, - GList *properties, - GPtrArray **param_names, - GArray **param_values) -{ - ClutterScriptable *scriptable = NULL; - ClutterScriptableIface *iface = NULL; - GList *l, *unparsed; - gboolean parse_custom = FALSE; - - *param_names = g_ptr_array_new_with_free_func (g_free); - *param_values = g_array_new (FALSE, FALSE, sizeof (GValue)); - g_array_set_clear_func (*param_values, (GDestroyNotify) g_value_unset); - - if (CLUTTER_IS_SCRIPTABLE (object)) - { - scriptable = CLUTTER_SCRIPTABLE (object); - iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); - - if (iface->parse_custom_node) - parse_custom = TRUE; - } - - unparsed = NULL; - - for (l = properties; l != NULL; l = l->next) - { - PropertyInfo *pinfo = l->data; - GValue value = G_VALUE_INIT; - gboolean res = FALSE; - - if (pinfo->is_layout) - { - CLUTTER_NOTE (SCRIPT, "Skipping layout property '%s'", - pinfo->name); - unparsed = g_list_prepend (unparsed, pinfo); - continue; - } - - CLUTTER_NOTE (SCRIPT, "Parsing %s property (id:%s)", - pinfo->pspec ? "regular" : "custom", - pinfo->name); - - if (parse_custom) - res = iface->parse_custom_node (scriptable, script, &value, - pinfo->name, - pinfo->node); - - if (!res) - res = _clutter_script_parse_node (script, &value, - pinfo->name, - pinfo->node, - pinfo->pspec); - - if (!res) - { - CLUTTER_NOTE (SCRIPT, "Property '%s' ignored", pinfo->name); - unparsed = g_list_prepend (unparsed, pinfo); - continue; - } - - g_ptr_array_add (*param_names, g_strdup (pinfo->name)); - g_array_append_val (*param_values, value); - - property_info_free (pinfo); - } - - g_list_free (properties); - - return unparsed; -} - -static GList * -clutter_script_construct_parameters (ClutterScript *script, - GType gtype, - const gchar *name, - GList *properties, - GPtrArray **construct_param_names, - GArray **construct_param_values) -{ - GObjectClass *klass; - GList *l, *unparsed; - - klass = g_type_class_ref (gtype); - g_assert (klass != NULL); - - *construct_param_names = g_ptr_array_new_with_free_func (g_free); - *construct_param_values = g_array_new (FALSE, FALSE, sizeof (GValue)); - g_array_set_clear_func (*construct_param_values, - (GDestroyNotify) g_value_unset); - - unparsed = NULL; - - for (l = properties; l != NULL; l = l->next) - { - PropertyInfo *pinfo = l->data; - GValue value = G_VALUE_INIT; - GParamSpec *pspec = NULL; - - /* we allow custom property names for classes, so if we - * don't find a corresponding GObject property for this - * class we just skip it and let the class itself deal - * with it later on - */ - pspec = g_object_class_find_property (klass, pinfo->name); - if (pspec) - pinfo->pspec = g_param_spec_ref (pspec); - else - { - pinfo->pspec = NULL; - unparsed = g_list_prepend (unparsed, pinfo); - continue; - } - - if (!(pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))) - { - unparsed = g_list_prepend (unparsed, pinfo); - continue; - } - - if (!_clutter_script_parse_node (script, &value, - pinfo->name, - pinfo->node, - pinfo->pspec)) - { - unparsed = g_list_prepend (unparsed, pinfo); - continue; - } - - g_ptr_array_add (*construct_param_names, g_strdup (pinfo->name)); - g_array_append_val (*construct_param_values, value); - - property_info_free (pinfo); - } - - g_list_free (properties); - - g_type_class_unref (klass); - - return unparsed; -} - -static void -apply_layout_properties (ClutterScript *script, - ClutterActor *container, - ClutterActor *actor, - ObjectInfo *oinfo) -{ - ClutterScriptable *scriptable = NULL; - ClutterScriptableIface *iface = NULL; - gboolean parse_custom_node = FALSE; - GList *l, *unresolved, *properties; - ClutterLayoutManager *manager; - GType meta_type; - - manager = g_object_get_data (G_OBJECT (container), "clutter-layout-manager"); - if (manager == NULL) - return; - - meta_type = _clutter_layout_manager_get_child_meta_type (manager); - if (meta_type == G_TYPE_INVALID) - return; - - CLUTTER_NOTE (SCRIPT, "Layout manager of type '%s' with meta type '%s'", - G_OBJECT_TYPE_NAME (manager), - g_type_name (meta_type)); - - /* shortcut, to avoid typechecking every time */ - if (CLUTTER_IS_SCRIPTABLE (manager)) - { - scriptable = CLUTTER_SCRIPTABLE (manager); - iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); - - parse_custom_node = iface->parse_custom_node != NULL ? TRUE : FALSE; - } - - properties = oinfo->properties; - oinfo->properties = NULL; - - unresolved = NULL; - for (l = properties; l != NULL; l = l->next) - { - PropertyInfo *pinfo = l->data; - GValue value = G_VALUE_INIT; - gboolean res = FALSE; - const gchar *name; - - if (!pinfo->is_layout) - { - unresolved = g_list_prepend (unresolved, pinfo); - continue; - } - - name = pinfo->name + strlen ("layout::"); - - pinfo->pspec = - clutter_layout_manager_find_child_property (manager, name); - - if (pinfo->pspec != NULL) - g_param_spec_ref (pinfo->pspec); - - CLUTTER_NOTE (SCRIPT, "Parsing %s layout property (id:%s)", - pinfo->pspec != NULL ? "regular" : "custom", - name); - - if (parse_custom_node) - res = iface->parse_custom_node (scriptable, script, &value, - name, - pinfo->node); - - if (!res) - res = _clutter_script_parse_node (script, &value, - name, - pinfo->node, - pinfo->pspec); - - if (!res) - { - CLUTTER_NOTE (SCRIPT, "Layout property '%s' ignored", name); - unresolved = g_list_prepend (unresolved, pinfo); - continue; - } - - CLUTTER_NOTE (SCRIPT, - "Setting %s layout property '%s' (type:%s) to " - "object '%s' (id:%s)", - iface->set_custom_property != NULL ? "custom" : "regular", - name, - g_type_name (G_VALUE_TYPE (&value)), - g_type_name (oinfo->gtype), - oinfo->id); - - clutter_layout_manager_child_set_property (manager, container, actor, - name, - &value); - - g_value_unset (&value); - - property_info_free (pinfo); - } - - g_list_free (properties); - - oinfo->properties = unresolved; -} - -static void -add_children (ClutterScript *script, - ObjectInfo *oinfo) -{ - ClutterActor *container = CLUTTER_ACTOR (oinfo->object); - GList *l, *unresolved; - - unresolved = NULL; - for (l = oinfo->children; l != NULL; l = l->next) - { - const gchar *name = l->data; - GObject *object = NULL; - ObjectInfo *child_info; - - child_info = _clutter_script_get_object_info (script, name); - if (child_info != NULL) - { - _clutter_script_construct_object (script, child_info); - object = child_info->object; - } - - if (object == NULL) - { - unresolved = g_list_prepend (unresolved, g_strdup (name)); - continue; - } - - if (!CLUTTER_IS_ACTOR (object)) - { - g_warning ("The object definition '%s' (type: %s) is not " - "an actor, but it is referenced in the 'children' " - "member of the container '%s' (type: %s); skipping.", - child_info->id, - g_type_name (child_info->gtype), - oinfo->id, - g_type_name (oinfo->gtype)); - continue; - } - - CLUTTER_NOTE (SCRIPT, "Adding children '%s' to actor of type '%s'", - name, - g_type_name (G_OBJECT_TYPE (container))); - - clutter_actor_add_child (container, CLUTTER_ACTOR (object)); - } - - g_list_free_full (oinfo->children, g_free); - - oinfo->children = unresolved; -} - -static inline void -_clutter_script_check_unresolved (ClutterScript *script, - ObjectInfo *oinfo) -{ - if (oinfo->children != NULL && CLUTTER_IS_ACTOR (oinfo->object)) - add_children (script, oinfo); - - /* this is a bit *eugh*, but it allows us to effectively make sure - * that child and layout properties are parsed and applied to the - * right child - */ - if (oinfo->properties != NULL && CLUTTER_IS_ACTOR (oinfo->object)) - { - ClutterActor *parent; - - parent = clutter_actor_get_parent (CLUTTER_ACTOR (oinfo->object)); - if (parent != NULL) - { - ClutterActor *child; - - for (child = clutter_actor_get_first_child (parent); - child != NULL; - child = clutter_actor_get_next_sibling (child)) - { - ObjectInfo *child_info; - const gchar *id_; - - id_ = clutter_get_script_id (G_OBJECT (child)); - if (id_ == NULL || *id_ == '\0') - continue; - - child_info = _clutter_script_get_object_info (script, id_); - if (child_info == NULL) - continue; - - apply_layout_properties (script, parent, - child, - child_info); - } - } - } - - if (oinfo->properties || oinfo->children) - oinfo->has_unresolved = TRUE; - else - oinfo->has_unresolved = FALSE; -} - -void -_clutter_script_apply_properties (ClutterScript *script, - ObjectInfo *oinfo) -{ - ClutterScriptable *scriptable = NULL; - ClutterScriptableIface *iface = NULL; - gboolean set_custom_property = FALSE; - GObject *object = oinfo->object; - GList *properties; - g_autoptr (GPtrArray) param_names = NULL; - g_autoptr (GArray) param_values = NULL; - guint i; - - if (!oinfo->has_unresolved) - return; - - /* shortcut, to avoid typechecking every time */ - if (CLUTTER_IS_SCRIPTABLE (object)) - { - scriptable = CLUTTER_SCRIPTABLE (object); - iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); - - if (iface->set_custom_property) - 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 - */ - properties = oinfo->properties; - oinfo->properties = clutter_script_translate_parameters (script, - object, - oinfo->id, - properties, - ¶m_names, - ¶m_values); - - /* consume all the properties we could translate in this pass */ - for (i = 0; i < param_names->len; i++) - { - char *name = g_ptr_array_index (param_names, i); - GValue *value = &g_array_index (param_values, GValue, i); - - CLUTTER_NOTE (SCRIPT, - "Setting %s property '%s' (type:%s) to object '%s' (id:%s)", - set_custom_property ? "custom" : "regular", - name, - g_type_name (G_VALUE_TYPE (value)), - g_type_name (oinfo->gtype), - oinfo->id); - - if (set_custom_property) - iface->set_custom_property (scriptable, script, - name, - value); - else - g_object_set_property (object, name, value); - } - - _clutter_script_check_unresolved (script, oinfo); -} - -void -_clutter_script_construct_object (ClutterScript *script, - ObjectInfo *oinfo) -{ - g_autoptr (GPtrArray) param_names = NULL; - g_autoptr (GArray) param_values = NULL; - - /* we have completely updated the object */ - if (oinfo->object != NULL) - { - if (oinfo->has_unresolved) - _clutter_script_check_unresolved (script, oinfo); - - return; - } - - if (oinfo->gtype == G_TYPE_INVALID) - { - if (G_UNLIKELY (oinfo->type_func)) - oinfo->gtype = _clutter_script_get_type_from_symbol (oinfo->type_func); - else - oinfo->gtype = clutter_script_get_type_from_name (script, oinfo->class_name); - - if (G_UNLIKELY (oinfo->gtype == G_TYPE_INVALID)) - return; - } - - oinfo->is_actor = g_type_is_a (oinfo->gtype, CLUTTER_TYPE_ACTOR); - if (oinfo->is_actor) - oinfo->is_stage = g_type_is_a (oinfo->gtype, CLUTTER_TYPE_STAGE); - - if (oinfo->is_stage && oinfo->is_stage_default) - { - ClutterStageManager *manager = clutter_stage_manager_get_default (); - GList *properties = oinfo->properties; - ClutterStage *default_stage; - - /* the default stage is a complex beast: we cannot create it using - * g_object_newv() but we need clutter_script_construct_parameters() - * to add the GParamSpec to the PropertyInfo pspec member, so - * that we don't have to implement every complex property (like - * the "color" one) directly inside the ClutterStage class. - */ - oinfo->properties = - clutter_script_construct_parameters (script, - oinfo->gtype, - oinfo->id, - properties, - ¶m_names, - ¶m_values); - - default_stage = clutter_stage_manager_get_default_stage (manager); - oinfo->object = G_OBJECT (default_stage); - } - else - { - GList *properties = oinfo->properties; - - /* every other object: first, we get the construction parameters */ - oinfo->properties = - clutter_script_construct_parameters (script, - oinfo->gtype, - oinfo->id, - properties, - ¶m_names, - ¶m_values); - - oinfo->object = g_object_new_with_properties (oinfo->gtype, - param_names->len, - (const gchar **) param_names->pdata, - (const GValue *) param_values->data); - - /* by sinking the floating reference, we make sure that the reference - * count is correct whether the object is referenced from somewhere - * else too or only by this ClutterScript object. - */ - g_object_ref_sink (oinfo->object); - } - - g_assert (oinfo->object != NULL); - - if (CLUTTER_IS_SCRIPTABLE (oinfo->object)) - clutter_scriptable_set_id (CLUTTER_SCRIPTABLE (oinfo->object), oinfo->id); - else - g_object_set_data_full (oinfo->object, "clutter-script-id", - g_strdup (oinfo->id), - g_free); - - _clutter_script_check_unresolved (script, oinfo); -} diff --git a/clutter/clutter/clutter-script-private.h b/clutter/clutter/clutter-script-private.h deleted file mode 100644 index 7e58b9159..000000000 --- a/clutter/clutter/clutter-script-private.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * - */ - -#pragma once - -#include -#include - -#include "clutter/clutter-color.h" -#include "clutter/clutter-types.h" -#include "clutter/clutter-script.h" - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_SCRIPT_PARSER (_clutter_script_parser_get_type ()) -#define CLUTTER_SCRIPT_PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_SCRIPT_PARSER, ClutterScriptParser)) -#define CLUTTER_IS_SCRIPT_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_SCRIPT_PARSER)) - -typedef struct _ClutterScriptParser ClutterScriptParser; -typedef struct _JsonParserClass ClutterScriptParserClass; - -struct _ClutterScriptParser -{ - JsonParser parent_instance; - - /* back reference */ - ClutterScript *script; -}; - -typedef GType (* GTypeGetFunc) (void); - -typedef struct { - gchar *id; - gchar *class_name; - gchar *type_func; - - GList *properties; - GList *children; - GList *signals; - - GType gtype; - GObject *object; - - guint merge_id; - - guint is_actor : 1; - guint is_stage : 1; - guint is_stage_default : 1; - guint has_unresolved : 1; - guint is_unmerged : 1; -} ObjectInfo; - -void object_info_free (gpointer data); - -typedef struct { - gchar *name; - JsonNode *node; - GParamSpec *pspec; - - guint is_layout : 1; -} PropertyInfo; - -typedef struct { - gchar *name; - gchar *handler; - gchar *object; - gchar *state; - gchar *target; - - GConnectFlags flags; - - guint is_handler : 1; - guint warp_to : 1; -} SignalInfo; - -void property_info_free (gpointer data); - -GType _clutter_script_parser_get_type (void) G_GNUC_CONST; - -gboolean _clutter_script_parse_node (ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node, - GParamSpec *pspec); - -GType _clutter_script_get_type_from_symbol (const gchar *symbol); -GType _clutter_script_get_type_from_class (const gchar *name); - -gboolean _clutter_script_enum_from_string (GType gtype, - const gchar *string, - gint *enum_value); -gboolean _clutter_script_flags_from_string (GType gtype, - const gchar *string, - gint *flags_value); - -gboolean _clutter_script_parse_knot (ClutterScript *script, - JsonNode *node, - ClutterKnot *knot); -gboolean _clutter_script_parse_rect (ClutterScript *script, - JsonNode *node, - graphene_rect_t *rect); -gboolean _clutter_script_parse_color (ClutterScript *script, - JsonNode *node, - ClutterColor *color); -gboolean _clutter_script_parse_point (ClutterScript *script, - JsonNode *node, - graphene_point_t *point); -gboolean _clutter_script_parse_size (ClutterScript *script, - JsonNode *node, - graphene_size_t *size); - -gboolean _clutter_script_parse_translatable_string (ClutterScript *script, - JsonNode *node, - char **str); - -void _clutter_script_construct_object (ClutterScript *script, - ObjectInfo *oinfo); -void _clutter_script_apply_properties (ClutterScript *script, - ObjectInfo *oinfo); - -gchar *_clutter_script_generate_fake_id (ClutterScript *script); - -void _clutter_script_warn_missing_attribute (ClutterScript *script, - const gchar *id, - const gchar *attribute); - -void _clutter_script_warn_invalid_value (ClutterScript *script, - const gchar *attribute, - const gchar *expected, - JsonNode *node); - -ObjectInfo *_clutter_script_get_object_info (ClutterScript *script, - const gchar *script_id); - -guint _clutter_script_get_last_merge_id (ClutterScript *script); - -void _clutter_script_add_object_info (ClutterScript *script, - ObjectInfo *oinfo); - -const gchar *_clutter_script_get_id_from_node (JsonNode *node); - -G_END_DECLS diff --git a/clutter/clutter/clutter-script.c b/clutter/clutter/clutter-script.c deleted file mode 100644 index 0c3b3b123..000000000 --- a/clutter/clutter/clutter-script.c +++ /dev/null @@ -1,1339 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * - */ - -/** - * ClutterScript: - * - * Loads a scene from UI definition data - * - * #ClutterScript is an object used for loading and building parts or a - * complete scenegraph from external definition data in forms of string - * buffers or files. - * - * The UI definition format is JSON, the JavaScript Object Notation as - * described by RFC 4627. #ClutterScript can load a JSON data stream, - * parse it and build all the objects defined into it. Each object must - * have an "id" and a "type" properties defining the name to be used - * to retrieve it from #ClutterScript with clutter_script_get_object(), - * and the class type to be instantiated. Every other attribute will - * be mapped to the class properties. - * - * A #ClutterScript holds a reference on every object it creates from - * the definition data, except for the stage. Every non-actor object - * will be finalized when the #ClutterScript instance holding it will - * be finalized, so they need to be referenced using g_object_ref() in - * order for them to survive. - * - * A simple object might be defined as: - * - * ```json - * { - * "id" : "red-button", - * "type" : "ClutterActor", - * "width" : 100, - * "height" : 100, - * "background-color" : "#ff0000ff" - * } - * ``` - * - * This will produce a red [class@Actor], 100x100 pixels wide, and - * with a ClutterScript id of "red-button"; it can be retrieved by calling: - * - * ```c - * ClutterActor *red_button; - * - * red_button = CLUTTER_ACTOR (clutter_script_get_object (script, "red-button")); - * ``` - * - * and then manipulated with the Clutter API. For every object created - * using ClutterScript it is possible to check the id by calling - * [method@Scriptable.get_id]. - * - * Packing can be represented using the "children" member, and passing an - * array of objects or ids of objects already defined (but not packed: the - * packing rules of Clutter still apply, and an actor cannot be packed - * in multiple containers without unparenting it in between). - * - * Signal handlers can be defined inside a Clutter UI definition file and - * then autoconnected to their respective signals using the - * [method@Script.connect_signals] function: - * - * ```json - * ... - * "signals" : [ - * { "name" : "button-press-event", "handler" : "on_button_press" }, - * { - * "name" : "foo-signal", - * "handler" : "after_foo", - * "after" : true - * }, - * ], - * ... - * ``` - * - * Signal handler definitions must have a "name" and a "handler" members; - * they can also have the "after" and "swapped" boolean members (for the - * signal connection flags %G_CONNECT_AFTER and %G_CONNECT_SWAPPED - * respectively) and the "object" string member for calling - * g_signal_connect_object() instead of g_signal_connect(). - * - * Clutter reserves the following names, so classes defining properties - * through the usual GObject registration process should avoid using these - * names to avoid collisions: - * - * ``` - * "id" := the unique name of a ClutterScript object - * "type" := the class literal name, also used to infer the type - * function - * "type_func" := the GType function name, for non-standard classes - * "children" := an array of names or objects to add as children - * "signals" := an array of signal definitions to connect to an object - * "is-default" := a boolean flag used when defining the #ClutterStage; - * if set to "true" the default stage will be used instead - * of creating a new #ClutterStage instance - * ``` - */ - -#include "clutter/clutter-build-config.h" - -#include -#include -#include -#include - -#include -#include -#include - -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS - -#include "clutter/clutter-actor.h" -#include "clutter/clutter-stage.h" - -#include "clutter/clutter-script.h" -#include "clutter/clutter-script-private.h" -#include "clutter/clutter-scriptable.h" - -#include "clutter/clutter-enum-types.h" -#include "clutter/clutter-private.h" -#include "clutter/clutter-debug.h" - -enum -{ - PROP_0, - - PROP_FILENAME_SET, - PROP_FILENAME, - PROP_TRANSLATION_DOMAIN, - - PROP_LAST -}; - -static GParamSpec *obj_props[PROP_LAST]; - -struct _ClutterScriptPrivate -{ - GHashTable *objects; - - guint last_merge_id; - guint last_unknown; - - ClutterScriptParser *parser; - - gchar **search_paths; - - gchar *translation_domain; - - gchar *filename; - guint is_filename : 1; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (ClutterScript, clutter_script, G_TYPE_OBJECT) - -static GType -clutter_script_real_get_type_from_name (ClutterScript *script, - const gchar *type_name) -{ - GType gtype; - - gtype = g_type_from_name (type_name); - if (gtype != G_TYPE_INVALID) - return gtype; - - return _clutter_script_get_type_from_class (type_name); -} - -void -property_info_free (gpointer data) -{ - if (G_LIKELY (data)) - { - PropertyInfo *pinfo = data; - - if (pinfo->node) - json_node_free (pinfo->node); - - if (pinfo->pspec) - g_param_spec_unref (pinfo->pspec); - - g_free (pinfo->name); - - g_free (pinfo); - } -} - -static void -signal_info_free (gpointer data) -{ - if (G_LIKELY (data)) - { - SignalInfo *sinfo = data; - - g_free (sinfo->name); - g_free (sinfo->handler); - g_free (sinfo->object); - g_free (sinfo->target); - - g_free (sinfo); - } -} - -void -object_info_free (gpointer data) -{ - if (G_LIKELY (data)) - { - ObjectInfo *oinfo = data; - - g_free (oinfo->id); - g_free (oinfo->class_name); - g_free (oinfo->type_func); - - g_list_free_full (oinfo->properties, property_info_free); - - g_list_free_full (oinfo->signals, signal_info_free); - - /* these are ids */ - g_list_free_full (oinfo->children, g_free); - - /* we unref top-level objects and leave the actors alone, - * unless we are unmerging in which case we have to destroy - * the actor to unparent them - */ - if (oinfo->object != NULL) - { - if (oinfo->is_unmerged) - { - if (oinfo->is_actor && !oinfo->is_stage) - clutter_actor_destroy (CLUTTER_ACTOR (oinfo->object)); - } - - g_object_unref (oinfo->object); - - oinfo->object = NULL; - } - - g_free (oinfo); - } -} - -static void -clutter_script_finalize (GObject *gobject) -{ - ClutterScriptPrivate *priv = CLUTTER_SCRIPT (gobject)->priv; - - g_object_unref (priv->parser); - g_hash_table_destroy (priv->objects); - g_strfreev (priv->search_paths); - g_free (priv->filename); - g_free (priv->translation_domain); - - G_OBJECT_CLASS (clutter_script_parent_class)->finalize (gobject); -} - -static void -clutter_script_set_property (GObject *gobject, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - ClutterScript *script = CLUTTER_SCRIPT (gobject); - - switch (prop_id) - { - case PROP_TRANSLATION_DOMAIN: - clutter_script_set_translation_domain (script, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -clutter_script_get_property (GObject *gobject, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - ClutterScript *script = CLUTTER_SCRIPT (gobject); - - switch (prop_id) - { - case PROP_FILENAME_SET: - g_value_set_boolean (value, script->priv->is_filename); - break; - - case PROP_FILENAME: - g_value_set_string (value, script->priv->filename); - break; - - case PROP_TRANSLATION_DOMAIN: - g_value_set_string (value, script->priv->translation_domain); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -clutter_script_class_init (ClutterScriptClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - klass->get_type_from_name = clutter_script_real_get_type_from_name; - - /** - * ClutterScript:filename-set: - * - * Whether the [property@Script:filename] property is set. If this property - * is %TRUE then the currently parsed data comes from a file, and the - * file name is stored inside the [property@Script:filename] property. - */ - obj_props[PROP_FILENAME_SET] = - g_param_spec_boolean ("filename-set", NULL, NULL, - FALSE, - CLUTTER_PARAM_READABLE); - - /** - * ClutterScript:filename: - * - * The path of the currently parsed file. If [property@Script:filename-set] - * is %FALSE then the value of this property is undefined. - */ - obj_props[PROP_FILENAME] = - g_param_spec_string ("filename", NULL, NULL, - NULL, - CLUTTER_PARAM_READABLE); - - /** - * ClutterScript:translation-domain: - * - * The translation domain, used to localize strings marked as translatable - * inside a UI definition. - * - * If [property@Script:translation-domain] is set to %NULL, #ClutterScript - * will use gettext(), otherwise g_dgettext() will be used. - */ - obj_props[PROP_TRANSLATION_DOMAIN] = - g_param_spec_string ("translation-domain", NULL, NULL, - NULL, - CLUTTER_PARAM_READWRITE); - - gobject_class->set_property = clutter_script_set_property; - gobject_class->get_property = clutter_script_get_property; - gobject_class->finalize = clutter_script_finalize; - - g_object_class_install_properties (gobject_class, - PROP_LAST, - obj_props); -} - -static void -clutter_script_init (ClutterScript *script) -{ - ClutterScriptPrivate *priv; - - script->priv = priv = clutter_script_get_instance_private (script); - - priv->parser = g_object_new (CLUTTER_TYPE_SCRIPT_PARSER, NULL); - priv->parser->script = script; - - priv->is_filename = FALSE; - priv->last_merge_id = 0; - - priv->objects = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, - object_info_free); -} - -/** - * clutter_script_new: - * - * Creates a new #ClutterScript instance. #ClutterScript can be used to load - * objects definitions for scenegraph elements, like actors, or behavioural - * elements, like timelines. The definitions must be encoded using the - * JavaScript Object Notation (JSON) language. - * - * Return value: the newly created #ClutterScript instance. Use - * g_object_unref() when done. - */ -ClutterScript * -clutter_script_new (void) -{ - return g_object_new (CLUTTER_TYPE_SCRIPT, NULL); -} - -/** - * clutter_script_load_from_file: - * @script: a #ClutterScript - * @filename: the full path to the definition file - * @error: return location for a #GError, or %NULL - * - * Loads the definitions from @filename into @script and merges with - * the currently loaded ones, if any. - * - * Return value: on error, zero is returned and @error is set - * accordingly. On success, the merge id for the UI definitions is - * returned. You can use the merge id with [method@Script.unmerge_objects]. - */ -guint -clutter_script_load_from_file (ClutterScript *script, - const gchar *filename, - GError **error) -{ - ClutterScriptPrivate *priv; - GError *internal_error; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), 0); - g_return_val_if_fail (filename != NULL, 0); - - priv = script->priv; - - g_free (priv->filename); - priv->filename = g_strdup (filename); - priv->is_filename = TRUE; - priv->last_merge_id += 1; - - internal_error = NULL; - json_parser_load_from_file (JSON_PARSER (priv->parser), - filename, - &internal_error); - if (internal_error) - { - g_propagate_error (error, internal_error); - priv->last_merge_id -= 1; - return 0; - } - - return priv->last_merge_id; -} - -/** - * clutter_script_load_from_data: - * @script: a #ClutterScript - * @data: a buffer containing the definitions - * @length: the length of the buffer, or -1 if @data is a NUL-terminated - * buffer - * @error: return location for a #GError, or %NULL - * - * Loads the definitions from @data into @script and merges with - * the currently loaded ones, if any. - * - * Return value: on error, zero is returned and @error is set - * accordingly. On success, the merge id for the UI definitions is - * returned. You can use the merge id with [method@Script.unmerge_objects]. - */ -guint -clutter_script_load_from_data (ClutterScript *script, - const gchar *data, - gssize length, - GError **error) -{ - ClutterScriptPrivate *priv; - GError *internal_error; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), 0); - g_return_val_if_fail (data != NULL, 0); - - if (length < 0) - length = strlen (data); - - priv = script->priv; - - g_free (priv->filename); - priv->filename = NULL; - priv->is_filename = FALSE; - priv->last_merge_id += 1; - - internal_error = NULL; - json_parser_load_from_data (JSON_PARSER (priv->parser), - data, length, - &internal_error); - if (internal_error) - { - g_propagate_error (error, internal_error); - priv->last_merge_id -= 1; - return 0; - } - - return priv->last_merge_id; -} - -/** - * clutter_script_load_from_resource: - * @script: a #ClutterScript - * @resource_path: the resource path of the file to parse - * @error: return location for a #GError, or %NULL - * - * Loads the definitions from a resource file into @script and merges with - * the currently loaded ones, if any. - * - * Return value: on error, zero is returned and @error is set - * accordingly. On success, the merge id for the UI definitions is - * returned. You can use the merge id with [method@Script.unmerge_objects]. - */ -guint -clutter_script_load_from_resource (ClutterScript *script, - const gchar *resource_path, - GError **error) -{ - GBytes *data; - guint res; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), 0); - - data = g_resources_lookup_data (resource_path, 0, error); - if (data == NULL) - return 0; - - res = clutter_script_load_from_data (script, - g_bytes_get_data (data, NULL), - g_bytes_get_size (data), - error); - - g_bytes_unref (data); - - return res; -} - -/** - * clutter_script_get_object: - * @script: a #ClutterScript - * @name: the name of the object to retrieve - * - * Retrieves the object bound to @name. This function does not increment - * the reference count of the returned object. - * - * Return value: (transfer none): the named object, or %NULL if no object - * with the given name was available - */ -GObject * -clutter_script_get_object (ClutterScript *script, - const gchar *name) -{ - ObjectInfo *oinfo; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL); - g_return_val_if_fail (name != NULL, NULL); - - oinfo = g_hash_table_lookup (script->priv->objects, name); - if (!oinfo) - return NULL; - - _clutter_script_construct_object (script, oinfo); - _clutter_script_apply_properties (script, oinfo); - - return oinfo->object; -} - -static gint -clutter_script_get_objects_valist (ClutterScript *script, - const gchar *first_name, - va_list args) -{ - gint retval = 0; - const gchar *name; - - name = first_name; - while (name) - { - GObject **obj = NULL; - - obj = va_arg (args, GObject**); - - *obj = clutter_script_get_object (script, name); - if (*obj) - retval += 1; - - name = va_arg (args, gchar*); - } - - return retval; -} - -/** - * clutter_script_get_objects: - * @script: a #ClutterScript - * @first_name: the name of the first object to retrieve - * @...: return location for a #GObject, then additional names, ending - * with %NULL - * - * Retrieves a list of objects for the given names. After @script, object - * names/return location pairs should be listed, with a %NULL pointer - * ending the list, like: - * - * ```c - * GObject *my_label, *a_button, *main_timeline; - * - * clutter_script_get_objects (script, - * "my-label", &my_label, - * "a-button", &a_button, - * "main-timeline", &main_timeline, - * NULL); - * ``` - * - * Note: This function does not increment the reference count of the - * returned objects. - * - * Return value: the number of objects returned. - */ -gint -clutter_script_get_objects (ClutterScript *script, - const gchar *first_name, - ...) -{ - gint retval; - va_list var_args; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), 0); - g_return_val_if_fail (first_name != NULL, 0); - - va_start (var_args, first_name); - retval = clutter_script_get_objects_valist (script, first_name, var_args); - va_end (var_args); - - return retval; -} - -typedef struct { - ClutterScript *script; - guint merge_id; - GSList *ids; -} UnmergeData; - -static void -remove_by_merge_id (gpointer key, - gpointer value, - gpointer data) -{ - gchar *name = key; - ObjectInfo *oinfo = value; - UnmergeData *unmerge_data = data; - - if (oinfo->merge_id == unmerge_data->merge_id) - { - CLUTTER_NOTE (SCRIPT, - "Unmerging object (id:%s, type:%s, merge-id:%d)", - oinfo->id, - oinfo->class_name, - oinfo->merge_id); - - unmerge_data->ids = g_slist_prepend (unmerge_data->ids, g_strdup (name)); - oinfo->is_unmerged = TRUE; - } -} - -/** - * clutter_script_unmerge_objects: - * @script: a #ClutterScript - * @merge_id: merge id returned when loading a UI definition - * - * Unmerges the objects identified by @merge_id. - */ -void -clutter_script_unmerge_objects (ClutterScript *script, - guint merge_id) -{ - ClutterScriptPrivate *priv; - UnmergeData data; - GSList *l; - - g_return_if_fail (CLUTTER_IS_SCRIPT (script)); - g_return_if_fail (merge_id > 0); - - priv = script->priv; - - data.script = script; - data.merge_id = merge_id; - data.ids = NULL; - g_hash_table_foreach (priv->objects, remove_by_merge_id, &data); - - for (l = data.ids; l != NULL; l = l->next) - g_hash_table_remove (priv->objects, l->data); - - g_slist_free_full (data.ids, g_free); - - clutter_script_ensure_objects (script); -} - -static void -construct_each_objects (gpointer key, - gpointer value, - gpointer user_data) -{ - ClutterScript *script = user_data; - ObjectInfo *oinfo = value; - - /* we have unfinished business */ - if (oinfo->has_unresolved) - { - /* this should not happen, but resilience is - * a good thing in a parser - */ - if (oinfo->object == NULL) - _clutter_script_construct_object (script, oinfo); - - /* this will take care of setting up properties and adding children */ - _clutter_script_apply_properties (script, oinfo); - } -} - -/** - * clutter_script_ensure_objects: - * @script: a #ClutterScript - * - * Ensure that every object defined inside @script is correctly - * constructed. You should rarely need to use this function. - */ -void -clutter_script_ensure_objects (ClutterScript *script) -{ - ClutterScriptPrivate *priv; - - g_return_if_fail (CLUTTER_IS_SCRIPT (script)); - - priv = script->priv; - g_hash_table_foreach (priv->objects, construct_each_objects, script); -} - -/** - * clutter_script_get_type_from_name: - * @script: a #ClutterScript - * @type_name: name of the type to look up - * - * Looks up a type by name, using the virtual function that - * #ClutterScript has for that purpose. This function should - * rarely be used. - * - * Return value: the type for the requested type name, or - * %G_TYPE_INVALID if not corresponding type was found. - */ -GType -clutter_script_get_type_from_name (ClutterScript *script, - const gchar *type_name) -{ - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), G_TYPE_INVALID); - g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID); - - return CLUTTER_SCRIPT_GET_CLASS (script)->get_type_from_name (script, type_name); -} - -/** - * clutter_get_script_id: - * @gobject: a #GObject - * - * Retrieves the Clutter script id, if any. - * - * Return value: the script id, or %NULL if @object was not defined inside - * a UI definition file. The returned string is owned by the object and - * should never be modified or freed. - */ -const gchar * -clutter_get_script_id (GObject *gobject) -{ - g_return_val_if_fail (G_IS_OBJECT (gobject), NULL); - - if (CLUTTER_IS_SCRIPTABLE (gobject)) - return clutter_scriptable_get_id (CLUTTER_SCRIPTABLE (gobject)); - else - return g_object_get_data (gobject, "clutter-script-id"); -} - -typedef struct { - GModule *module; - gpointer data; -} ConnectData; - -/* default signal connection code */ -static void -clutter_script_default_connect (ClutterScript *script, - GObject *gobject, - const gchar *signal_name, - const gchar *signal_handler, - GObject *connect_gobject, - GConnectFlags flags, - gpointer user_data) -{ - ConnectData *data = user_data; - GCallback function; - - if (!data->module) - return; - - if (!g_module_symbol (data->module, signal_handler, (gpointer) &function)) - { - g_warning ("Could not find a signal handler '%s' for signal '%s::%s'", - signal_handler, - connect_gobject ? G_OBJECT_TYPE_NAME (connect_gobject) - : G_OBJECT_TYPE_NAME (gobject), - signal_name); - return; - } - - CLUTTER_NOTE (SCRIPT, - "connecting %s::%s to %s (after:%s, swapped:%s, object:%s)", - (connect_gobject ? G_OBJECT_TYPE_NAME (connect_gobject) - : G_OBJECT_TYPE_NAME (gobject)), - signal_name, - signal_handler, - (flags & G_CONNECT_AFTER) ? "true" : "false", - (flags & G_CONNECT_SWAPPED) ? "true" : "false", - (connect_gobject ? G_OBJECT_TYPE_NAME (connect_gobject) - : "")); - - if (connect_gobject != NULL) - g_signal_connect_object (gobject, - signal_name, function, - connect_gobject, - flags); - else - g_signal_connect_data (gobject, - signal_name, function, - data->data, - NULL, - flags); -} - -/** - * clutter_script_connect_signals: - * @script: a #ClutterScript - * @user_data: data to be passed to the signal handlers, or %NULL - * - * Connects all the signals defined into a UI definition file to their - * handlers. - * - * This method invokes [method@Script.connect_signals_full] internally - * and uses #GModule's introspective features (by opening the current - * module's scope) to look at the application's symbol table. - * - * Note that this function will not work if #GModule is not supported by - * the platform Clutter is running on. - */ -void -clutter_script_connect_signals (ClutterScript *script, - gpointer user_data) -{ - ConnectData *cd; - - g_return_if_fail (CLUTTER_IS_SCRIPT (script)); - - if (!g_module_supported ()) - { - g_critical ("clutter_script_connect_signals() requires a working " - "GModule support from GLib"); - return; - } - - cd = g_new (ConnectData, 1); - cd->module = g_module_open (NULL, 0); - cd->data = user_data; - - clutter_script_connect_signals_full (script, - clutter_script_default_connect, - cd); - - g_module_close (cd->module); - - g_free (cd); -} - -typedef struct { - ClutterScript *script; - ClutterScriptConnectFunc func; - gpointer user_data; -} SignalConnectData; - -static void -connect_each_object (gpointer key, - gpointer value, - gpointer data) -{ - SignalConnectData *connect_data = data; - ClutterScript *script = connect_data->script; - ObjectInfo *oinfo = value; - GObject *object = oinfo->object; - GList *unresolved, *l; - - _clutter_script_construct_object (script, oinfo); - - unresolved = NULL; - for (l = oinfo->signals; l != NULL; l = l->next) - { - SignalInfo *sinfo = l->data; - - if (sinfo->is_handler) - { - GObject *connect_object = NULL; - - if (sinfo->object) - connect_object = clutter_script_get_object (script, sinfo->object); - - if (sinfo->object && !connect_object) - unresolved = g_list_prepend (unresolved, sinfo); - else - { - connect_data->func (script, object, - sinfo->name, - sinfo->handler, - connect_object, - sinfo->flags, - connect_data->user_data); - } - } - else - { - g_warn_if_reached (); - } - - signal_info_free (sinfo); - } - - /* keep the unresolved signal handlers around, in case - * clutter_script_connect_signals() is called multiple - * times (e.g. after a UI definition merge) - */ - g_list_free (oinfo->signals); - oinfo->signals = unresolved; -} - -/** - * clutter_script_connect_signals_full: - * @script: a #ClutterScript - * @func: (scope call): signal connection function - * @user_data: data to be passed to the signal handlers, or %NULL - * - * Connects all the signals defined into a UI definition file to their - * handlers. - * - * This function allows to control how the signal handlers are - * going to be connected to their respective signals. It is meant - * primarily for language bindings to allow resolving the function - * names using the native API, but it can also be used on platforms - * that do not support GModule. - * - * Applications should use [method@Script.connect_signals]. - */ -void -clutter_script_connect_signals_full (ClutterScript *script, - ClutterScriptConnectFunc func, - gpointer user_data) -{ - SignalConnectData data; - - g_return_if_fail (CLUTTER_IS_SCRIPT (script)); - g_return_if_fail (func != NULL); - - data.script = script; - data.func = func; - data.user_data = user_data; - - g_hash_table_foreach (script->priv->objects, connect_each_object, &data); -} - -GQuark -clutter_script_error_quark (void) -{ - return g_quark_from_static_string ("clutter-script-error"); -} - -/** - * clutter_script_add_search_paths: - * @script: a #ClutterScript - * @paths: (array length=n_paths): an array of strings containing - * different search paths - * @n_paths: the length of the passed array - * - * Adds @paths to the list of search paths held by @script. - * - * The search paths are used by [method@Script.lookup_filename], which - * can be used to define search paths for the textures source file name - * or other custom, file-based properties. - */ -void -clutter_script_add_search_paths (ClutterScript *script, - const gchar * const paths[], - gsize n_paths) -{ - ClutterScriptPrivate *priv; - gchar **old_paths, **new_paths; - gsize old_paths_len, i; - gsize iter = 0; - - g_return_if_fail (CLUTTER_IS_SCRIPT (script)); - g_return_if_fail (paths != NULL); - g_return_if_fail (n_paths > 0); - - priv = script->priv; - - if (priv->search_paths) - { - old_paths = priv->search_paths; - old_paths_len = g_strv_length (old_paths); - } - else - { - old_paths = NULL; - old_paths_len = 0; - } - - new_paths = g_new0 (gchar*, old_paths_len + n_paths + 1); - - for (i = 0, iter = 0; i < old_paths_len; i++, iter++) - new_paths[iter] = g_strdup (old_paths[i]); - - for (i = 0; i < n_paths; i++, iter++) - new_paths[iter] = g_strdup (paths[i]); - - CLUTTER_NOTE (SCRIPT, - "Added %" G_GSIZE_FORMAT " new search paths (new size: %d)", - n_paths, - g_strv_length (new_paths)); - - priv->search_paths = new_paths; - - if (old_paths) - g_strfreev (old_paths); -} - -/** - * clutter_script_lookup_filename: - * @script: a #ClutterScript - * @filename: the name of the file to lookup - * - * Looks up @filename inside the search paths of @script. If @filename - * is found, its full path will be returned . - * - * Return value: the full path of @filename or %NULL if no path was - * found. - */ -gchar * -clutter_script_lookup_filename (ClutterScript *script, - const gchar *filename) -{ - ClutterScriptPrivate *priv; - gchar *dirname; - gchar *retval; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL); - g_return_val_if_fail (filename != NULL, NULL); - - if (g_path_is_absolute (filename)) - return g_strdup (filename); - - priv = script->priv; - - if (priv->search_paths) - { - gsize paths_len, i; - - paths_len = g_strv_length (priv->search_paths); - for (i = 0; i < paths_len; i++) - { - retval = g_build_filename (priv->search_paths[i], filename, NULL); - if (g_file_test (retval, G_FILE_TEST_EXISTS)) - return retval; - else - { - g_free (retval); - retval = NULL; - } - } - } - - /* Fall back to assuming relative to our script */ - if (priv->is_filename) - dirname = g_path_get_dirname (script->priv->filename); - else - dirname = g_get_current_dir (); - - retval = g_build_filename (dirname, filename, NULL); - if (!g_file_test (retval, G_FILE_TEST_EXISTS)) - { - g_free (retval); - retval = NULL; - } - - g_free (dirname); - - return retval; -} - -/** - * clutter_script_list_objects: - * @script: a #ClutterScript - * - * Retrieves all the objects created by @script. - * - * Note: this function does not increment the reference count of the - * objects it returns. - * - * Return value: (transfer container) (element-type GObject.Object): a list - * of `GObject`s, or %NULL. The objects are owned by the - * #ClutterScript instance. Use g_list_free() on the returned list when - * done. - */ -GList * -clutter_script_list_objects (ClutterScript *script) -{ - GList *objects, *l; - GList *retval; - - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL); - - clutter_script_ensure_objects (script); - if (!script->priv->objects) - return NULL; - - retval = NULL; - objects = g_hash_table_get_values (script->priv->objects); - for (l = objects; l != NULL; l = l->next) - { - ObjectInfo *oinfo = l->data; - - if (oinfo->object) - retval = g_list_prepend (retval, oinfo->object); - } - - g_list_free (objects); - - return retval; -} - -/** - * clutter_script_set_translation_domain: - * @script: a #ClutterScript - * @domain: (allow-none): the translation domain, or %NULL - * - * Sets the translation domain for @script. - */ -void -clutter_script_set_translation_domain (ClutterScript *script, - const gchar *domain) -{ - g_return_if_fail (CLUTTER_IS_SCRIPT (script)); - - if (g_strcmp0 (domain, script->priv->translation_domain) == 0) - return; - - g_free (script->priv->translation_domain); - script->priv->translation_domain = g_strdup (domain); - - g_object_notify_by_pspec (G_OBJECT (script), obj_props[PROP_TRANSLATION_DOMAIN]); -} - -/** - * clutter_script_get_translation_domain: - * @script: a #ClutterScript - * - * Retrieves the translation domain set using - * [method@Script.set_translation_domain]. - * - * Return value: (transfer none): the translation domain, if any is set, - * or %NULL - */ -const gchar * -clutter_script_get_translation_domain (ClutterScript *script) -{ - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL); - - return script->priv->translation_domain; -} - -/* - * _clutter_script_generate_fake_id: - * @script: a #ClutterScript - * - * Generates a fake id string for object definitions without - * an "id" member - * - * Return value: a newly-allocated string containing the fake - * id. Use g_free() to free the resources allocated by the - * returned value - * - */ -gchar * -_clutter_script_generate_fake_id (ClutterScript *script) -{ - ClutterScriptPrivate *priv = script->priv; - - return g_strdup_printf ("script-%d-%d", - priv->last_merge_id, - priv->last_unknown++); -} - -/* - * _clutter_script_warn_missing_attribute: - * @script: a #ClutterScript - * @id_: the id of an object definition, or %NULL - * @attribute: the expected attribute - * - * Emits a warning, using GLib's log facilities, for a missing - * @attribute in an object definition, pointing to the current - * location of the #ClutterScriptParser - */ -void -_clutter_script_warn_missing_attribute (ClutterScript *script, - const gchar *id_, - const gchar *attribute) -{ - ClutterScriptPrivate *priv = script->priv; - JsonParser *parser = JSON_PARSER (priv->parser); - gint current_line = json_parser_get_current_line (parser); - - if (id_ != NULL && *id_ != '\0') - { - g_warning ("%s:%d: object '%s' has no '%s' attribute", - priv->is_filename ? priv->filename : "", - current_line, - id_, - attribute); - } - else - { - g_warning ("%s:%d: object has no '%s' attribute", - priv->is_filename ? priv->filename : "", - current_line, - attribute); - } -} - -/* - * _clutter_script_warn_invalid_value: - * @script: a #ClutterScript - * @attribute: the attribute with the invalid value - * @expected: a string with the expected value - * @node: a #JsonNode containing the value - * - * Emits a warning, using GLib's log facilities, for an invalid - * value found when parsing @attribute, pointing to the current - * location of the #ClutterScriptParser - */ -void -_clutter_script_warn_invalid_value (ClutterScript *script, - const gchar *attribute, - const gchar *expected, - JsonNode *node) -{ - ClutterScriptPrivate *priv = script->priv; - JsonParser *parser = JSON_PARSER (priv->parser); - gint current_line = json_parser_get_current_line (parser); - - if (node != NULL) - { - g_warning ("%s:%d: invalid value of type '%s' for attribute '%s':" - "a value of type '%s' is expected", - priv->is_filename ? priv->filename : "", - current_line, - json_node_type_name (node), - attribute, - expected); - } - else - { - g_warning ("%s:%d: invalid value for attribute '%s':" - "a value of type '%s' is expected", - priv->is_filename ? priv->filename : "", - current_line, - attribute, - expected); - } -} - -/* - * _clutter_script_get_object_info: - * @script: a #ClutterScript - * @script_id: the id of the object definition - * - * Retrieves the #ObjectInfo for the given @script_id - * - * Return value: a #ObjectInfo or %NULL - */ -ObjectInfo * -_clutter_script_get_object_info (ClutterScript *script, - const gchar *script_id) -{ - ClutterScriptPrivate *priv = script->priv; - - return g_hash_table_lookup (priv->objects, script_id); -} - -/* - * _clutter_script_get_last_merge_id: - * @script: a #ClutterScript - * - * Retrieves the last merge id of @script. The merge id - * should be stored inside an #ObjectInfo. If you need - * a unique fake id for object definitions with an "id" - * member, consider using _clutter_script_generate_fake_id() - * instead - * - * Return value: the last merge id - */ -guint -_clutter_script_get_last_merge_id (ClutterScript *script) -{ - return script->priv->last_merge_id; -} - -/* - * _clutter_script_add_object_info: - * @script: a #ClutterScript - * @oinfo: a #ObjectInfo - * - * Adds @oinfo inside the objects list held by @script - */ -void -_clutter_script_add_object_info (ClutterScript *script, - ObjectInfo *oinfo) -{ - ClutterScriptPrivate *priv = script->priv; - - g_hash_table_steal (priv->objects, oinfo->id); - g_hash_table_insert (priv->objects, oinfo->id, oinfo); -} diff --git a/clutter/clutter/clutter-script.h b/clutter/clutter/clutter-script.h deleted file mode 100644 index bc0b6366c..000000000 --- a/clutter/clutter/clutter-script.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#pragma once - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only can be included directly." -#endif - -#include "clutter/clutter-types.h" - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_SCRIPT (clutter_script_get_type ()) -#define CLUTTER_SCRIPT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_SCRIPT, ClutterScript)) -#define CLUTTER_IS_SCRIPT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_SCRIPT)) -#define CLUTTER_SCRIPT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_SCRIPT, ClutterScriptClass)) -#define CLUTTER_IS_SCRIPT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_SCRIPT)) -#define CLUTTER_SCRIPT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_SCRIPT, ClutterScriptClass)) - -typedef struct _ClutterScript ClutterScript; -typedef struct _ClutterScriptPrivate ClutterScriptPrivate; -typedef struct _ClutterScriptClass ClutterScriptClass; - -/** - * ClutterScriptConnectFunc: - * @script: a #ClutterScript - * @object: the object to connect - * @signal_name: the name of the signal - * @handler_name: the name of the signal handler - * @connect_object: the object to connect the signal to, or %NULL - * @flags: signal connection flags - * @user_data: user data to pass to the signal handler - * - * This is the signature of a function used to connect signals. It is used - * by the clutter_script_connect_signals_full() function. It is mainly - * intended for interpreted language bindings, but could be useful where the - * programmer wants more control over the signal connection process. - */ -typedef void (* ClutterScriptConnectFunc) (ClutterScript *script, - GObject *object, - const gchar *signal_name, - const gchar *handler_name, - GObject *connect_object, - GConnectFlags flags, - gpointer user_data); - -/** - * ClutterScriptError: - * @CLUTTER_SCRIPT_ERROR_INVALID_TYPE_FUNCTION: Type function not found - * or invalid - * @CLUTTER_SCRIPT_ERROR_INVALID_PROPERTY: Property not found or invalid - * @CLUTTER_SCRIPT_ERROR_INVALID_VALUE: Invalid value - * - * #ClutterScript error enumeration. - */ -typedef enum -{ - CLUTTER_SCRIPT_ERROR_INVALID_TYPE_FUNCTION, - CLUTTER_SCRIPT_ERROR_INVALID_PROPERTY, - CLUTTER_SCRIPT_ERROR_INVALID_VALUE -} ClutterScriptError; - -/** - * CLUTTER_SCRIPT_ERROR: - * - * Error domain for the #ClutterScript errors - */ -#define CLUTTER_SCRIPT_ERROR (clutter_script_error_quark ()) -CLUTTER_EXPORT -GQuark clutter_script_error_quark (void); - -struct _ClutterScript -{ - /*< private >*/ - GObject parent_instance; - - ClutterScriptPrivate *priv; -}; - -/** - * ClutterScriptClass: - * @get_type_from_name: virtual function used to map a type name - * to a #GType. This function should only be overridden by - * language bindings in order to map native types to #GType. - * The default implementation is equivalent to g_type_from_name() - * - * The #ClutterScriptClass structure contains only private data - */ -struct _ClutterScriptClass -{ - /*< private >*/ - GObjectClass parent_class; - - /*< public >*/ - GType (* get_type_from_name) (ClutterScript *script, - const gchar *type_name); -}; - -CLUTTER_EXPORT -GType clutter_script_get_type (void) G_GNUC_CONST; - -CLUTTER_EXPORT -ClutterScript * clutter_script_new (void); -CLUTTER_EXPORT -guint clutter_script_load_from_file (ClutterScript *script, - const gchar *filename, - GError **error); -CLUTTER_EXPORT -guint clutter_script_load_from_data (ClutterScript *script, - const gchar *data, - gssize length, - GError **error); -CLUTTER_EXPORT -guint clutter_script_load_from_resource (ClutterScript *script, - const gchar *resource_path, - GError **error); - -CLUTTER_EXPORT -GObject * clutter_script_get_object (ClutterScript *script, - const gchar *name); -CLUTTER_EXPORT -gint clutter_script_get_objects (ClutterScript *script, - const gchar *first_name, - ...) G_GNUC_NULL_TERMINATED; -CLUTTER_EXPORT -GList * clutter_script_list_objects (ClutterScript *script); -CLUTTER_EXPORT -void clutter_script_unmerge_objects (ClutterScript *script, - guint merge_id); -CLUTTER_EXPORT -void clutter_script_ensure_objects (ClutterScript *script); - -CLUTTER_EXPORT -void clutter_script_connect_signals (ClutterScript *script, - gpointer user_data); -CLUTTER_EXPORT -void clutter_script_connect_signals_full (ClutterScript *script, - ClutterScriptConnectFunc func, - gpointer user_data); - -CLUTTER_EXPORT -void clutter_script_add_search_paths (ClutterScript *script, - const gchar * const paths[], - gsize n_paths); -CLUTTER_EXPORT -gchar * clutter_script_lookup_filename (ClutterScript *script, - const gchar *filename) G_GNUC_MALLOC; -CLUTTER_EXPORT -GType clutter_script_get_type_from_name (ClutterScript *script, - const gchar *type_name); - -CLUTTER_EXPORT -void clutter_script_set_translation_domain (ClutterScript *script, - const gchar *domain); -CLUTTER_EXPORT -const gchar * clutter_script_get_translation_domain (ClutterScript *script); - -CLUTTER_EXPORT -const gchar * clutter_get_script_id (GObject *gobject); - -G_END_DECLS diff --git a/clutter/clutter/clutter-scriptable.c b/clutter/clutter/clutter-scriptable.c deleted file mode 100644 index fe6c7b310..000000000 --- a/clutter/clutter/clutter-scriptable.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * Emmanuele Bassi - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * - */ - -/** - * ClutterScriptable: - * - * Override the UI definition parsing - * - * The #ClutterScriptable interface exposes the UI definition parsing - * process to external classes. By implementing this interface, a class can - * override the UI definition parsing and transform complex data types into - * [class@GObject.Object] properties, or allow custom properties. - */ - -#include "clutter/clutter-build-config.h" - -#include -#include - -#include - -#include "clutter/clutter-scriptable.h" -#include "clutter/clutter-script-private.h" - -#include "clutter/clutter-private.h" -#include "clutter/clutter-debug.h" - -typedef ClutterScriptableIface ClutterScriptableInterface; - -G_DEFINE_INTERFACE (ClutterScriptable, clutter_scriptable, G_TYPE_OBJECT); - -static void -clutter_scriptable_default_init (ClutterScriptableInterface *iface) -{ -} - -/** - * clutter_scriptable_set_id: - * @scriptable: a #ClutterScriptable - * @id_: the #ClutterScript id of the object - * - * Sets @id_ as the unique Clutter script it for this instance of - * #ClutterScriptableIface. - * - * This name can be used by user interface designer applications to - * define a unique name for an object constructable using the UI - * definition language parsed by [class@Script]. - */ -void -clutter_scriptable_set_id (ClutterScriptable *scriptable, - const gchar *id_) -{ - ClutterScriptableIface *iface; - - g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable)); - g_return_if_fail (id_ != NULL); - - iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); - if (iface->set_id) - iface->set_id (scriptable, id_); - else - g_object_set_data_full (G_OBJECT (scriptable), - "clutter-script-id", - g_strdup (id_), - g_free); -} - -/** - * clutter_scriptable_get_id: - * @scriptable: a #ClutterScriptable - * - * Retrieves the id of @scriptable set using [method@Clutter.Scriptable.set_id]. - * - * Return value: the id of the object. The returned string is owned by - * the scriptable object and should never be modified of freed - */ -const gchar * -clutter_scriptable_get_id (ClutterScriptable *scriptable) -{ - ClutterScriptableIface *iface; - - g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), NULL); - - iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); - if (iface->get_id) - return iface->get_id (scriptable); - else - return g_object_get_data (G_OBJECT (scriptable), "clutter-script-id"); -} - -/** - * clutter_scriptable_parse_custom_node: - * @scriptable: a #ClutterScriptable - * @script: the #ClutterScript creating the scriptable instance - * @value: the generic value to be set - * @name: the name of the node - * @node: the JSON node to be parsed - * - * Parses the passed JSON node. The implementation must set the type - * of the passed [struct@GObject.Value] pointer using g_value_init(). - * - * Return value: %TRUE if the node was successfully parsed, %FALSE otherwise. - */ -gboolean -clutter_scriptable_parse_custom_node (ClutterScriptable *scriptable, - ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node) -{ - ClutterScriptableIface *iface; - - g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), FALSE); - g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE); - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (node != NULL, FALSE); - - iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); - if (iface->parse_custom_node) - return iface->parse_custom_node (scriptable, script, value, name, node); - - return FALSE; -} - -/** - * clutter_scriptable_set_custom_property: - * @scriptable: a #ClutterScriptable - * @script: the #ClutterScript creating the scriptable instance - * @name: the name of the property - * @value: the value of the property - * - * Overrides the common properties setting. The underlying virtual - * function should be used when implementing custom properties. - */ -void -clutter_scriptable_set_custom_property (ClutterScriptable *scriptable, - ClutterScript *script, - const gchar *name, - const GValue *value) -{ - ClutterScriptableIface *iface; - - g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable)); - g_return_if_fail (CLUTTER_IS_SCRIPT (script)); - g_return_if_fail (name != NULL); - g_return_if_fail (value != NULL); - - iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); - if (iface->set_custom_property) - iface->set_custom_property (scriptable, script, name, value); -} diff --git a/clutter/clutter/clutter-scriptable.h b/clutter/clutter/clutter-scriptable.h deleted file mode 100644 index 2e0ad8b77..000000000 --- a/clutter/clutter/clutter-scriptable.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * Emmanuele Bassi - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#pragma once - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only can be included directly." -#endif - -#include -#include - -#include "clutter/clutter-script.h" - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_SCRIPTABLE (clutter_scriptable_get_type ()) -#define CLUTTER_SCRIPTABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_SCRIPTABLE, ClutterScriptable)) -#define CLUTTER_IS_SCRIPTABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_SCRIPTABLE)) -#define CLUTTER_SCRIPTABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CLUTTER_TYPE_SCRIPTABLE, ClutterScriptableIface)) - -typedef struct _ClutterScriptable ClutterScriptable; -typedef struct _ClutterScriptableIface ClutterScriptableIface; - -/** - * ClutterScriptableIface: - * @set_id: virtual function for setting the id of a scriptable object - * @get_id: virtual function for getting the id of a scriptable object - * @parse_custom_node: virtual function for parsing complex data containers - * into GObject properties - * @set_custom_property: virtual function for setting a custom property - * - * Interface for implementing "scriptable" objects. An object implementing - * this interface can override the parsing and properties setting sequence - * when loading a UI definition data with #ClutterScript - */ -struct _ClutterScriptableIface -{ - /*< private >*/ - GTypeInterface g_iface; - - /*< public >*/ - void (* set_id) (ClutterScriptable *scriptable, - const gchar *id_); - const gchar *(* get_id) (ClutterScriptable *scriptable); - - gboolean (* parse_custom_node) (ClutterScriptable *scriptable, - ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node); - void (* set_custom_property) (ClutterScriptable *scriptable, - ClutterScript *script, - const gchar *name, - const GValue *value); -}; - -CLUTTER_EXPORT -GType clutter_scriptable_get_type (void) G_GNUC_CONST; - -CLUTTER_EXPORT -void clutter_scriptable_set_id (ClutterScriptable *scriptable, - const gchar *id_); -CLUTTER_EXPORT -const gchar * clutter_scriptable_get_id (ClutterScriptable *scriptable); -CLUTTER_EXPORT -gboolean clutter_scriptable_parse_custom_node (ClutterScriptable *scriptable, - ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node); -CLUTTER_EXPORT -void clutter_scriptable_set_custom_property (ClutterScriptable *scriptable, - ClutterScript *script, - const gchar *name, - const GValue *value); - -G_END_DECLS diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index 02653950d..14da9a3c4 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -59,7 +59,6 @@ #include "clutter/clutter-text-buffer.h" #include "clutter/clutter-units.h" #include "clutter/clutter-paint-volume-private.h" -#include "clutter/clutter-scriptable.h" #include "clutter/clutter-input-focus.h" /* cursor width in pixels */ @@ -282,7 +281,6 @@ static const ClutterColor default_text_color = { 0, 0, 0, 255 }; static const ClutterColor default_selected_text_color = { 0, 0, 0, 255 }; static ClutterAnimatableInterface *parent_animatable_iface = NULL; -static ClutterScriptableIface *parent_scriptable_iface = NULL; /* ClutterTextInputFocus */ #define CLUTTER_TYPE_TEXT_INPUT_FOCUS (clutter_text_input_focus_get_type ()) @@ -437,15 +435,12 @@ clutter_text_input_focus_new (ClutterText *text) } /* ClutterText */ -static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); static void clutter_animatable_iface_init (ClutterAnimatableInterface *iface); G_DEFINE_TYPE_WITH_CODE (ClutterText, clutter_text, CLUTTER_TYPE_ACTOR, G_ADD_PRIVATE (ClutterText) - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE, - clutter_scriptable_iface_init) G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_ANIMATABLE, clutter_animatable_iface_init)); @@ -3566,27 +3561,6 @@ clutter_text_add_move_binding (ClutterBindingPool *pool, } } -static gboolean -clutter_text_parse_custom_node (ClutterScriptable *scriptable, - ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node) -{ - if (strncmp (name, "font-description", 16) == 0) - { - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, json_node_get_string (node)); - - return TRUE; - } - - return parent_scriptable_iface->parse_custom_node (scriptable, script, - value, - name, - node); -} - static void clutter_text_set_color_internal (ClutterText *self, GParamSpec *pspec, @@ -3737,34 +3711,6 @@ clutter_text_set_color_animated (ClutterText *self, clutter_timeline_start (CLUTTER_TIMELINE (transition)); } -static void -clutter_text_set_custom_property (ClutterScriptable *scriptable, - ClutterScript *script, - const gchar *name, - const GValue *value) -{ - if (strncmp (name, "font-description", 16) == 0) - { - g_assert (G_VALUE_HOLDS (value, G_TYPE_STRING)); - if (g_value_get_string (value) != NULL) - clutter_text_set_font_name (CLUTTER_TEXT (scriptable), - g_value_get_string (value)); - } - else - parent_scriptable_iface->set_custom_property (scriptable, script, - name, - value); -} - -static void -clutter_scriptable_iface_init (ClutterScriptableIface *iface) -{ - parent_scriptable_iface = g_type_interface_peek_parent (iface); - - iface->parse_custom_node = clutter_text_parse_custom_node; - iface->set_custom_property = clutter_text_set_custom_property; -} - static void clutter_text_set_final_state (ClutterAnimatable *animatable, const char *property_name, diff --git a/clutter/clutter/clutter-timeline.c b/clutter/clutter/clutter-timeline.c index dd828528d..7ddbe9df7 100644 --- a/clutter/clutter/clutter-timeline.c +++ b/clutter/clutter/clutter-timeline.c @@ -72,25 +72,6 @@ * * Timelines are used in the Clutter animation framework by classes like * [class@Transition]. - * - * ## Defining Timelines in ClutterScript - * - * A #ClutterTimeline can be described in [class@Script] like any - * other object. Additionally, it is possible to define markers directly - * inside the JSON definition by using the `markers` JSON object member, - * such as: - * - * ```json - * { - * "type" : "ClutterTimeline", - * "duration" : 1000, - * "markers" : [ - * { "name" : "quarter", "time" : 250 }, - * { "name" : "half-time", "time" : 500 }, - * { "name" : "three-quarters", "time" : 750 } - * ] - * } - * ``` */ #include "clutter/clutter-build-config.h" @@ -106,7 +87,6 @@ #include "clutter/clutter-marshal.h" #include "clutter/clutter-mutter.h" #include "clutter/clutter-private.h" -#include "clutter/clutter-scriptable.h" #include "clutter/clutter-timeline-private.h" struct _ClutterTimelinePrivate @@ -215,12 +195,9 @@ static guint timeline_signals[LAST_SIGNAL] = { 0, }; static void update_frame_clock (ClutterTimeline *timeline); -static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); G_DEFINE_TYPE_WITH_CODE (ClutterTimeline, clutter_timeline, G_TYPE_OBJECT, - G_ADD_PRIVATE (ClutterTimeline) - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE, - clutter_scriptable_iface_init)) + G_ADD_PRIVATE (ClutterTimeline)) static TimelineMarker * timeline_marker_new_time (const gchar *name, @@ -497,135 +474,12 @@ clutter_timeline_set_actor (ClutterTimeline *timeline, update_frame_clock (timeline); } -/* Scriptable */ -typedef struct _ParseClosure { - ClutterTimeline *timeline; - ClutterScript *script; - GValue *value; - gboolean result; -} ParseClosure; - -static void -parse_timeline_markers (JsonArray *array, - guint index_, - JsonNode *element, - gpointer data) -{ - ParseClosure *clos = data; - JsonObject *object; - TimelineMarker *marker; - GList *markers; - - if (JSON_NODE_TYPE (element) != JSON_NODE_OBJECT) - { - g_warning ("The 'markers' member of a ClutterTimeline description " - "should be an array of objects, but the element %d of the " - "array is of type '%s'. The element will be ignored.", - index_, - json_node_type_name (element)); - return; - } - - object = json_node_get_object (element); - - if (!(json_object_has_member (object, "name") && - (json_object_has_member (object, "time") || - json_object_has_member (object, "progress")))) - { - g_warning ("The marker definition in a ClutterTimeline description " - "must be an object with the 'name' and either the 'time' " - "or the 'progress' members, but the element %d of the " - "'markers' array does not have any of them.", - index_); - return; - } - - if (G_IS_VALUE (clos->value)) - markers = g_value_get_pointer (clos->value); - else - { - g_value_init (clos->value, G_TYPE_POINTER); - markers = NULL; - } - - if (json_object_has_member (object, "time")) - marker = timeline_marker_new_time (json_object_get_string_member (object, "name"), - json_object_get_int_member (object, "time")); - else - marker = timeline_marker_new_progress (json_object_get_string_member (object, "name"), - json_object_get_double_member (object, "progress")); - - markers = g_list_prepend (markers, marker); - - g_value_set_pointer (clos->value, markers); - - clos->result = TRUE; -} - -static gboolean -clutter_timeline_parse_custom_node (ClutterScriptable *scriptable, - ClutterScript *script, - GValue *value, - const gchar *name, - JsonNode *node) -{ - ParseClosure clos; - - if (strcmp (name, "markers") != 0) - return FALSE; - - if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY) - return FALSE; - - clos.timeline = CLUTTER_TIMELINE (scriptable); - clos.script = script; - clos.value = value; - clos.result = FALSE; - - json_array_foreach_element (json_node_get_array (node), - parse_timeline_markers, - &clos); - - return clos.result; -} - -static void -clutter_timeline_set_custom_property (ClutterScriptable *scriptable, - ClutterScript *script, - const gchar *name, - const GValue *value) -{ - if (strcmp (name, "markers") == 0) - { - ClutterTimeline *timeline = CLUTTER_TIMELINE (scriptable); - GList *markers = g_value_get_pointer (value); - GList *m; - - /* the list was created through prepend() */ - markers = g_list_reverse (markers); - - for (m = markers; m != NULL; m = m->next) - clutter_timeline_add_marker_internal (timeline, m->data); - - g_list_free (markers); - } - else - g_object_set_property (G_OBJECT (scriptable), name, value); -} - void clutter_timeline_cancel_delay (ClutterTimeline *timeline) { g_clear_handle_id (&timeline->priv->delay_id, g_source_remove); } -static void -clutter_scriptable_iface_init (ClutterScriptableIface *iface) -{ - iface->parse_custom_node = clutter_timeline_parse_custom_node; - iface->set_custom_property = clutter_timeline_set_custom_property; -} - /* Object */ static void diff --git a/clutter/clutter/clutter.h b/clutter/clutter/clutter.h index 4a3303147..353d3d377 100644 --- a/clutter/clutter/clutter.h +++ b/clutter/clutter/clutter.h @@ -86,8 +86,6 @@ #include "clutter/clutter-path.h" #include "clutter/clutter-property-transition.h" #include "clutter/clutter-rotate-action.h" -#include "clutter/clutter-scriptable.h" -#include "clutter/clutter-script.h" #include "clutter/clutter-scroll-actor.h" #include "clutter/clutter-settings.h" #include "clutter/clutter-shader-effect.h" diff --git a/clutter/clutter/meson.build b/clutter/clutter/meson.build index baad0c918..d95466119 100644 --- a/clutter/clutter/meson.build +++ b/clutter/clutter/meson.build @@ -64,8 +64,6 @@ clutter_headers = [ 'clutter-pick-context.h', 'clutter-property-transition.h', 'clutter-rotate-action.h', - 'clutter-script.h', - 'clutter-scriptable.h', 'clutter-scroll-actor.h', 'clutter-seat.h', 'clutter-settings.h', @@ -155,9 +153,6 @@ clutter_sources = [ 'clutter-pick-stack.c', 'clutter-property-transition.c', 'clutter-rotate-action.c', - 'clutter-script.c', - 'clutter-script-parser.c', - 'clutter-scriptable.c', 'clutter-scroll-actor.c', 'clutter-seat.c', 'clutter-settings.c', @@ -209,7 +204,6 @@ clutter_private_headers = [ 'clutter-paint-node-private.h', 'clutter-paint-volume-private.h', 'clutter-private.h', - 'clutter-script-private.h', 'clutter-settings-private.h', 'clutter-stage-manager-private.h', 'clutter-stage-private.h', @@ -348,7 +342,6 @@ if have_introspection 'GObject-2.0', 'cairo-1.0', 'Atk-1.0', - 'Json-1.0', ], dependencies: [cogl_deps], extra_args: clutter_introspection_args + ['--c-include=clutter/clutter.h'], diff --git a/clutter/meson.build b/clutter/meson.build index 95e76a948..cdb4bb4d2 100644 --- a/clutter/meson.build +++ b/clutter/meson.build @@ -33,7 +33,6 @@ clutter_pkg_deps = [ glib_dep, gobject_dep, gio_dep, - json_glib_dep, pango_dep, harfbuzz_dep, ] @@ -45,6 +44,12 @@ clutter_pkg_private_deps = [ pangocairo_dep, ] +if get_option('debug') + clutter_pkg_private_deps += [ + json_glib_dep, + ] +endif + if have_pango_ft2 clutter_pkg_private_deps += [ pangoft2_dep, diff --git a/meson.build b/meson.build index 02df4302c..d6be91e8b 100644 --- a/meson.build +++ b/meson.build @@ -123,7 +123,7 @@ gobject_dep = dependency('gobject-2.0', version: glib_req) gthread_dep = dependency('gobject-2.0', version: glib_req) gmodule_no_export_dep = dependency('gmodule-no-export-2.0', version: glib_req) gnome_settings_daemon_dep = dependency('gnome-settings-daemon', required: false) -json_glib_dep = dependency('json-glib-1.0', version: json_glib_req) +json_glib_dep = dependency('json-glib-1.0', version: json_glib_req, required: get_option('debug')) xkbcommon_dep = dependency('xkbcommon', version: xkbcommon_req) ice_dep = dependency('ice') atk_dep = dependency('atk', version: atk_req) diff --git a/src/compositor/plugins/meson.build b/src/compositor/plugins/meson.build index 814c3d272..519e998ad 100644 --- a/src/compositor/plugins/meson.build +++ b/src/compositor/plugins/meson.build @@ -10,7 +10,6 @@ default_plugin = shared_module('default', c_args: default_plugin_c_args, dependencies: [ glib_dep, - json_glib_dep, gsettings_desktop_schemas_dep, libmutter_clutter_dep, ], diff --git a/src/meson.build b/src/meson.build index 666400962..f0de5df1f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -25,7 +25,6 @@ mutter_pkg_private_deps = [ lcms2_dep, gmodule_no_export_dep, gnome_settings_daemon_dep, - json_glib_dep, xkbcommon_dep, gdk_pixbuf_dep, libeis_dep, diff --git a/src/tests/clutter/conform/interval.c b/src/tests/clutter/conform/interval.c index 263a25b37..ca06d2054 100644 --- a/src/tests/clutter/conform/interval.c +++ b/src/tests/clutter/conform/interval.c @@ -67,53 +67,7 @@ interval_transform (void) g_object_unref (interval); } -static void -interval_from_script (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterInterval *interval; - gchar *test_file; - GError *error = NULL; - GValue *initial, *final; - - test_file = g_test_build_filename (G_TEST_DIST, - "scripts", - "test-script-interval.json", - NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_printerr ("\tError: %s", error->message); - - g_assert_no_error (error); - - interval = CLUTTER_INTERVAL (clutter_script_get_object (script, "int-1")); - initial = clutter_interval_peek_initial_value (interval); - if (!g_test_quiet ()) - g_test_message ("\tinitial ['%s'] = '%.2f'", - g_type_name (G_VALUE_TYPE (initial)), - g_value_get_float (initial)); - g_assert (G_VALUE_HOLDS (initial, G_TYPE_FLOAT)); - g_assert_cmpfloat (g_value_get_float (initial), ==, 23.3f); - final = clutter_interval_peek_final_value (interval); - if (!g_test_quiet ()) - g_test_message ("\tfinal ['%s'] = '%.2f'", - g_type_name (G_VALUE_TYPE (final)), - g_value_get_float (final)); - g_assert (G_VALUE_HOLDS (final, G_TYPE_FLOAT)); - g_assert_cmpfloat (g_value_get_float (final), ==, 42.2f); - - interval = CLUTTER_INTERVAL (clutter_script_get_object (script, "int-2")); - initial = clutter_interval_peek_initial_value (interval); - g_assert (G_VALUE_HOLDS (initial, CLUTTER_TYPE_COLOR)); - final = clutter_interval_peek_final_value (interval); - g_assert (G_VALUE_HOLDS (final, CLUTTER_TYPE_COLOR)); - - g_object_unref (script); - g_free (test_file); -} - CLUTTER_TEST_SUITE ( CLUTTER_TEST_UNIT ("/interval/initial-state", interval_initial_state) CLUTTER_TEST_UNIT ("/interval/transform", interval_transform) - CLUTTER_TEST_UNIT ("/interval/from-script", interval_from_script) ) diff --git a/src/tests/clutter/conform/meson.build b/src/tests/clutter/conform/meson.build index 9c89cce6d..ada162305 100644 --- a/src/tests/clutter/conform/meson.build +++ b/src/tests/clutter/conform/meson.build @@ -39,7 +39,6 @@ clutter_conform_tests_general_tests = [ 'frame-clock-timeline', 'grab', 'interval', - 'script-parser', 'timeline', 'timeline-interpolate', 'timeline-progress', diff --git a/src/tests/clutter/conform/script-parser.c b/src/tests/clutter/conform/script-parser.c deleted file mode 100644 index 9c686711b..000000000 --- a/src/tests/clutter/conform/script-parser.c +++ /dev/null @@ -1,194 +0,0 @@ -#include -#include - -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include - -#include "tests/clutter-test-utils.h" - -#define TEST_TYPE_GROUP (test_group_get_type ()) -G_DECLARE_FINAL_TYPE (TestGroup, test_group, TEST, GROUP, ClutterActor) - -struct _TestGroup -{ - ClutterActor parent; -}; - -G_DEFINE_TYPE (TestGroup, test_group, CLUTTER_TYPE_ACTOR) - -static void -test_group_class_init (TestGroupClass *klass) -{ -} - -static void -test_group_init (TestGroup *self) -{ -} - -static void -script_child (void) -{ - ClutterScript *script = clutter_script_new (); - GObject *container, *actor; - GError *error = NULL; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-child.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - container = actor = NULL; - clutter_script_get_objects (script, - "test-group", &container, - "test-rect-1", &actor, - NULL); - g_assert (TEST_IS_GROUP (container)); - g_assert (CLUTTER_IS_ACTOR (actor)); - - actor = clutter_script_get_object (script, "test-rect-2"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_single (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterColor color = { 0, }; - GObject *actor = NULL; - GError *error = NULL; - ClutterActor *rect; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-single.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = clutter_script_get_object (script, "test"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - rect = CLUTTER_ACTOR (actor); - g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 50.0); - g_assert_cmpfloat (clutter_actor_get_y (rect), ==, 100.0); - - clutter_actor_get_background_color (rect, &color); - g_assert_cmpint (color.red, ==, 255); - g_assert_cmpint (color.green, ==, 0xcc); - g_assert_cmpint (color.alpha, ==, 0xff); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_object_property (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterLayoutManager *manager; - GObject *actor = NULL; - GError *error = NULL; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-object-property.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = clutter_script_get_object (script, "test"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - manager = clutter_actor_get_layout_manager (CLUTTER_ACTOR (actor)); - g_assert (CLUTTER_IS_BIN_LAYOUT (manager)); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_named_object (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterLayoutManager *manager; - GObject *actor = NULL; - GError *error = NULL; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-named-object.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = clutter_script_get_object (script, "test"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - manager = clutter_actor_get_layout_manager (CLUTTER_ACTOR (actor)); - g_assert (CLUTTER_IS_BOX_LAYOUT (manager)); - g_assert (clutter_box_layout_get_orientation (CLUTTER_BOX_LAYOUT (manager)) == CLUTTER_ORIENTATION_VERTICAL); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_margin (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterActor *actor; - gchar *test_file; - GError *error = NULL; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-margin.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-1")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 10.0f); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-2")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 20.0f); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-3")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 30.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 20.0f); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-4")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 30.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 40.0f); - - g_object_unref (script); - g_free (test_file); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/script/single-object", script_single) - CLUTTER_TEST_UNIT ("/script/container-child", script_child) - CLUTTER_TEST_UNIT ("/script/named-object", script_named_object) - CLUTTER_TEST_UNIT ("/script/object-property", script_object_property) - CLUTTER_TEST_UNIT ("/script/actor-margin", script_margin) -) diff --git a/src/tests/clutter/conform/scripts/test-script-child.json b/src/tests/clutter/conform/scripts/test-script-child.json deleted file mode 100644 index bc3a25970..000000000 --- a/src/tests/clutter/conform/scripts/test-script-child.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "type" : "TestGroup", - "id" : "test-group", - "children" : [ - { - "type" : "ClutterActor", - "id" : "test-rect-1", - "width" : 100.0, - "height" : 100.0, - "background-color" : [ 255, 0, 0, 255 ] - }, - { - "type" : "ClutterActor", - "id" : "test-rect-2", - "width" : 100.0, - "height" : 100.0, - "background-color" : [ 0, 255, 0, 255 ] - } - ] -} diff --git a/src/tests/clutter/conform/scripts/test-script-interval.json b/src/tests/clutter/conform/scripts/test-script-interval.json deleted file mode 100644 index 35fe5c22c..000000000 --- a/src/tests/clutter/conform/scripts/test-script-interval.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "id" : "int-1", - "type" : "ClutterInterval", - "value-type" : "gfloat", - "initial" : 23.3, - "final" : 42.2 - }, - { - "id" : "int-2", - "type" : "ClutterInterval", - "value-type" : "ClutterColor", - "initial" : "red", - "final" : "blue" - } -] diff --git a/src/tests/clutter/conform/scripts/test-script-margin.json b/src/tests/clutter/conform/scripts/test-script-margin.json deleted file mode 100644 index 1f5289fa6..000000000 --- a/src/tests/clutter/conform/scripts/test-script-margin.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "id" : "actor-1", - "type" : "ClutterActor", - "margin" : [ 10 ] - }, - { - "id" : "actor-2", - "type" : "ClutterActor", - "margin" : [ 10, 20 ] - }, - { - "id" : "actor-3", - "type" : "ClutterActor", - "margin" : [ 10, 20, 30 ] - }, - { - "id" : "actor-4", - "type" : "ClutterActor", - "margin" : [ 10, 20, 30, 40] - } -] diff --git a/src/tests/clutter/conform/scripts/test-script-model.json b/src/tests/clutter/conform/scripts/test-script-model.json deleted file mode 100644 index dc4a62dc0..000000000 --- a/src/tests/clutter/conform/scripts/test-script-model.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "id" : "test-model", - "type" : "ClutterListModel", - "columns" : [ - [ "text-column", "gchararray" ], - [ "int-column", "gint" ], - [ "actor-column", "ClutterActor" ] - ], - "rows" : [ - [ "text-row-1", 1, null ], - [ "text-row-2", 2, { "type" : "ClutterActor", "background-color" : "blue" } ], - { - "int-column" : 3, - "actor-column" : { "type" : "ClutterActor", "name" : "actor-row-3" } - } - ] -} diff --git a/src/tests/clutter/conform/scripts/test-script-named-object.json b/src/tests/clutter/conform/scripts/test-script-named-object.json deleted file mode 100644 index 347583275..000000000 --- a/src/tests/clutter/conform/scripts/test-script-named-object.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "id" : "layout", - "type" : "ClutterBoxLayout", - "orientation" : "vertical", - "spacing" : 12 - }, - { - "type" : "ClutterStage", - "id" : "main-stage", - "children" : [ - { - "id" : "test", - "type" : "ClutterActor", - "layout-manager" : "layout", - "children" : [ - { - "id" : "child-1", - "type" : "ClutterActor", - "width" : "3 em", - "height" : "3 em" - } - ], - "constraints" : [ - { - "type" : "ClutterAlignConstraint", - "name" : "x-align", - "factor" : 0.5, - "align-axis" : "x-axis", - "source" : "main-stage" - }, - { - "type" : "ClutterAlignConstraint", - "name" : "y-align", - "factor" : 0.5, - "align-axis" : "y-axis", - "source" : "main-stage" - } - ] - } - ] - } -] diff --git a/src/tests/clutter/conform/scripts/test-script-object-property.json b/src/tests/clutter/conform/scripts/test-script-object-property.json deleted file mode 100644 index 58187bbb6..000000000 --- a/src/tests/clutter/conform/scripts/test-script-object-property.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "id" : "test", - "type" : "ClutterActor", - "layout-manager" : { "id" : "layout", "type" : "ClutterBinLayout" }, - "children" : [ - { - "id" : "child-1", - "type" : "ClutterActor", - "width" : "3 em", - "height" : "3 em" - } - ] -} diff --git a/src/tests/clutter/conform/scripts/test-script-single.json b/src/tests/clutter/conform/scripts/test-script-single.json deleted file mode 100644 index cb09d696a..000000000 --- a/src/tests/clutter/conform/scripts/test-script-single.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "type" : "ClutterActor", - "id" : "test", - "width" : 50.0, - "height" : 100.0, - "x" : 100.0, - "y" : 100.0, - "background-color" : "#ffccdd", - "name" : "Test Rectangle" -} diff --git a/src/tests/clutter/conform/scripts/test-script-timeline-markers.json b/src/tests/clutter/conform/scripts/test-script-timeline-markers.json deleted file mode 100644 index e26ba5f01..000000000 --- a/src/tests/clutter/conform/scripts/test-script-timeline-markers.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { "id" : "actor0", "type" : "ClutterActor" }, - { - "id" : "timeline0", - "type" : "ClutterTimeline", - "duration" : 1000, - "actor" : "actor0", - - "markers" : [ - { "name" : "marker0", "time" : 250 }, - { "name" : "marker1", "time" : 500 }, - { "name" : "marker2", "time" : 750 }, - { "name" : "marker3", "progress" : 0.5 } - ] - } -] diff --git a/src/tests/clutter/conform/timeline.c b/src/tests/clutter/conform/timeline.c index 6bd8f32bb..369127c40 100644 --- a/src/tests/clutter/conform/timeline.c +++ b/src/tests/clutter/conform/timeline.c @@ -316,50 +316,6 @@ timeline_base (void) g_clear_handle_id (&delay_tag, g_source_remove); } -static void -timeline_markers_from_script (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterTimeline *timeline; - GError *error = NULL; - gchar *test_file; - gchar **markers; - gsize n_markers; - - test_file = g_test_build_filename (G_TEST_DIST, - "scripts", - "test-script-timeline-markers.json", - NULL); - if (!clutter_script_load_from_file (script, test_file, &error)) - g_printerr ("Error: %s", error->message); - - g_assert_no_error (error); - - timeline = CLUTTER_TIMELINE (clutter_script_get_object (script, "timeline0")); - - g_assert (clutter_timeline_has_marker (timeline, "marker0")); - g_assert (clutter_timeline_has_marker (timeline, "marker1")); - g_assert (!clutter_timeline_has_marker (timeline, "foo")); - g_assert (clutter_timeline_has_marker (timeline, "marker2")); - g_assert (clutter_timeline_has_marker (timeline, "marker3")); - - markers = clutter_timeline_list_markers (timeline, -1, &n_markers); - g_assert_cmpint (n_markers, ==, 4); - g_strfreev (markers); - - markers = clutter_timeline_list_markers (timeline, 500, &n_markers); - g_assert_cmpint (n_markers, ==, 2); - g_assert (markers != NULL); - g_assert (g_strv_contains ((const char * const *) markers, "marker1")); - g_assert (g_strv_contains ((const char * const *) markers, "marker3")); - g_strfreev (markers); - - g_object_unref (script); - - g_free (test_file); -} - CLUTTER_TEST_SUITE ( CLUTTER_TEST_UNIT ("/timeline/base", timeline_base); - CLUTTER_TEST_UNIT ("/timeline/markers-from-script", timeline_markers_from_script) ) diff --git a/src/tests/clutter/interactive/meson.build b/src/tests/clutter/interactive/meson.build index f5e04500a..69fd6a9be 100644 --- a/src/tests/clutter/interactive/meson.build +++ b/src/tests/clutter/interactive/meson.build @@ -18,7 +18,6 @@ clutter_tests_interactive_link_args = [ clutter_tests_interactive_test_sources = [ 'test-events.c', 'test-actors.c', - 'test-script.c', 'test-grab.c', 'test-cogl-shader-glsl.c', 'test-cogl-tex-tile.c', diff --git a/src/tests/clutter/interactive/test-script.c b/src/tests/clutter/interactive/test-script.c deleted file mode 100644 index e15ff32b4..000000000 --- a/src/tests/clutter/interactive/test-script.c +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include - -#include - -#include -#include -#include - -#include "tests/clutter-test-utils.h" - -static ClutterScript *script = NULL; -static guint merge_id = 0; - -int -test_script_main (int argc, char *argv[]); - -static const gchar *test_unmerge = -"[" -" {" -" \"id\" : \"main-stage\"," -" \"type\" : \"ClutterStage\"," -" \"children\" : [ \"blue-button\" ]" -" }," -" {" -" \"id\" : \"blue-button\"," -" \"type\" : \"ClutterActor\"," -" \"background-color\" : \"#0000ffff\"," -" \"x\" : 350," -" \"y\" : 50," -" \"width\" : 100," -" \"height\" : 100," -" \"visible\" : true," -" \"reactive\" : true" -" }" -"]"; - -static const gchar *test_behaviour = -"[" -" {" -" \"id\" : \"main-timeline\"," -" \"type\" : \"ClutterTimeline\"," -" \"duration\" : 5000," -" \"loop\" : true" -" }" -"]"; - -static gboolean -blue_button_press (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - g_print ("[*] Pressed '%s'\n", clutter_get_script_id (G_OBJECT (actor))); - g_print ("[*] Unmerging objects with merge id: %d\n", merge_id); - - clutter_script_unmerge_objects (script, merge_id); - - return TRUE; -} - -static gboolean -red_button_press (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - GObject *timeline; - - g_print ("[*] Pressed '%s'\n", clutter_get_script_id (G_OBJECT (actor))); - - timeline = clutter_script_get_object (script, "main-timeline"); - g_assert (CLUTTER_IS_TIMELINE (timeline)); - - if (!clutter_timeline_is_playing (CLUTTER_TIMELINE (timeline))) - clutter_timeline_start (CLUTTER_TIMELINE (timeline)); - else - clutter_timeline_pause (CLUTTER_TIMELINE (timeline)); - - return TRUE; -} - -G_MODULE_EXPORT int -test_script_main (int argc, char *argv[]) -{ - GObject *stage, *blue_button, *red_button; - GError *error = NULL; - gchar *file; - gint res; - - clutter_test_init (&argc, &argv); - - script = clutter_script_new (); - g_assert (CLUTTER_IS_SCRIPT (script)); - - clutter_script_load_from_data (script, test_behaviour, -1, &error); - if (error) - { - g_print ("*** Error:\n" - "*** %s\n", error->message); - g_error_free (error); - g_object_unref (script); - return EXIT_FAILURE; - } - - file = g_build_filename (TESTS_DATADIR, "test-script.json", NULL); - clutter_script_load_from_file (script, file, &error); - if (error) - { - g_print ("*** Error:\n" - "*** %s\n", error->message); - g_error_free (error); - g_object_unref (script); - g_free (file); - return EXIT_FAILURE; - } - - g_free (file); - - merge_id = clutter_script_load_from_data (script, test_unmerge, -1, &error); - if (error) - { - g_print ("*** Error:\n" - "*** %s\n", error->message); - g_error_free (error); - g_object_unref (script); - return EXIT_FAILURE; - } - - clutter_script_connect_signals (script, NULL); - - res = clutter_script_get_objects (script, - "main-stage", &stage, - "red-button", &red_button, - "blue-button", &blue_button, - NULL); - g_assert (res == 3); - - clutter_actor_show (CLUTTER_ACTOR (stage)); - - g_signal_connect (red_button, - "button-press-event", - G_CALLBACK (red_button_press), - NULL); - - g_signal_connect (blue_button, - "button-press-event", - G_CALLBACK (blue_button_press), - NULL); - - clutter_test_main (); - - g_object_unref (script); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-script.json b/src/tests/clutter/interactive/test-script.json deleted file mode 100644 index b958315ae..000000000 --- a/src/tests/clutter/interactive/test-script.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "My Scene" : { - "id" : "main-stage", - "type" : "ClutterStage", - "title" : { "translatable" : true, "string" : "ClutterScript test" }, - "color" : "white", - "signals" : [ - { "name" : "key-press-event", "handler" : "clutter_test_quit" }, - { "name" : "destroy", "handler" : "clutter_test_quit" } - ], - "children" : [ - { - "id" : "red-button", - "type" : "ClutterActor", - "background-color" : "#ff0000ff", - "x" : 50, "y" : 50, "width" : 100, "height" : 100, - "reactive" : true, - "rotation" : [ - { "z-axis" : [ 45.0, [ 75, 75 ] ] } - ] - }, - { - "id" : "green-button", - "type" : "ClutterActor", - "background-color" : "#00ff00ff", - "border-width" : 5, - "border-color" : "#00cc00ff", - "position" : [ 200.0, 50.0 ], - "size" : { "width" : 100.0, "height" : 100.0 }, - "depth" : -200.0, - "reactive" : true, - "signals" : [ - { "name" : "button-press-event", "handler" : "clutter_test_quit" } - ] - }, - { - "id" : "label", - "type" : "ClutterText", - "x" : 50, - "y" : 200, - "text" : { "translatable" : true, "string" : "Clutter Script" }, - "font-name" : "Sans 24px", - "color" : "black", - "line-alignment" : "center", - "line-wrap" : false, - "ellipsize" : "none", - "rotation" : [ - { "y-axis" : [ 60.0, [ 275, 100 ] ] }, - { "z-axis" : [ 45.0, [ 75, 75 ] ] } - ] - } - ] - } -} diff --git a/src/tests/clutter/interactive/test-state-script.c b/src/tests/clutter/interactive/test-state-script.c deleted file mode 100644 index 8e3527eac..000000000 --- a/src/tests/clutter/interactive/test-state-script.c +++ /dev/null @@ -1,46 +0,0 @@ -#include - -#include - -#include - -#include "tests/clutter-test-utils.h" - -#define TEST_STATE_SCRIPT_FILE "test-script-signals.json" - -int -test_state_script_main (int argc, char *argv[]); - -G_MODULE_EXPORT int -test_state_script_main (int argc, char *argv[]) -{ - ClutterActor *stage, *button; - ClutterScript *script; - GError *error = NULL; - - clutter_test_init (&argc, &argv); - - script = clutter_script_new (); - clutter_script_load_from_file (script, TEST_STATE_SCRIPT_FILE, &error); - if (error != NULL) - g_error ("Unable to load '%s': %s\n", - TEST_STATE_SCRIPT_FILE, - error->message); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "State Script"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - clutter_actor_show (stage); - - button = CLUTTER_ACTOR (clutter_script_get_object (script, "button")); - clutter_actor_add_child (stage, button); - clutter_actor_add_constraint (button, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); - - clutter_script_connect_signals (script, NULL); - - clutter_test_main (); - - g_object_unref (script); - - return EXIT_SUCCESS; -} diff --git a/src/tests/meson.build b/src/tests/meson.build index ccb294126..1bbd7bb43 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -161,7 +161,6 @@ test_client = executable('mutter-test-client', x11_dep, xext_dep, graphene_dep, - json_glib_dep, gsettings_desktop_schemas_dep, ], install: have_installed_tests,