2007-10-09 09:29:03 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* 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
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2007-10-09 09:29:03 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:clutter-script
|
|
|
|
* @short_description: 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 instanciated. Every other attribute will
|
|
|
|
* be mapped to the class properties.
|
|
|
|
*
|
2007-10-25 10:34:54 -04:00
|
|
|
* 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.
|
|
|
|
*
|
2007-10-09 09:29:03 -04:00
|
|
|
* A simple object might be defined as:
|
|
|
|
*
|
2010-06-30 10:50:47 -04:00
|
|
|
* <informalexample><programlisting><![CDATA[
|
2007-10-09 09:29:03 -04:00
|
|
|
* {
|
|
|
|
* "id" : "red-button",
|
|
|
|
* "type" : "ClutterRectangle",
|
|
|
|
* "width" : 100,
|
|
|
|
* "height" : 100,
|
2008-07-24 05:11:54 -04:00
|
|
|
* "color" : "#ff0000ff"
|
2007-10-09 09:29:03 -04:00
|
|
|
* }
|
2010-06-30 10:50:47 -04:00
|
|
|
* ]]></programlisting></informalexample>
|
2007-10-09 09:29:03 -04:00
|
|
|
*
|
|
|
|
* This will produce a red #ClutterRectangle, 100x100 pixels wide, and
|
2008-06-19 16:45:28 -04:00
|
|
|
* with a ClutterScript id of "red-button"; it can be retrieved by calling:
|
2007-10-09 09:29:03 -04:00
|
|
|
*
|
2008-06-19 16:45:28 -04:00
|
|
|
* |[
|
2007-10-09 09:29:03 -04:00
|
|
|
* ClutterActor *red_button;
|
|
|
|
*
|
|
|
|
* red_button = CLUTTER_ACTOR (clutter_script_get_object (script, "red-button"));
|
2008-06-19 16:45:28 -04:00
|
|
|
* ]|
|
2007-10-09 09:29:03 -04:00
|
|
|
*
|
2008-06-19 16:45:28 -04:00
|
|
|
* and then manipulated with the Clutter API. For every object created
|
|
|
|
* using ClutterScript it is possible to check the id by calling
|
|
|
|
* clutter_get_script_id().
|
2007-10-09 09:29:03 -04:00
|
|
|
*
|
|
|
|
* Packing can be represented using the "children" member, and passing an
|
|
|
|
* array of objects or ids of objects already defined (but not packed: the
|
2007-10-25 10:34:54 -04:00
|
|
|
* packing rules of Clutter still apply, and an actor cannot be packed
|
|
|
|
* in multiple containers without unparenting it in between).
|
2007-10-09 09:29:03 -04:00
|
|
|
*
|
|
|
|
* Behaviours and timelines can also be defined inside a UI definition
|
|
|
|
* buffer:
|
|
|
|
*
|
2010-06-30 10:50:47 -04:00
|
|
|
* <informalexample><programlisting><![CDATA[
|
2007-10-09 09:29:03 -04:00
|
|
|
* {
|
|
|
|
* "id" : "rotate-behaviour",
|
|
|
|
* "type" : "ClutterBehaviourRotate",
|
2007-11-13 08:21:56 -05:00
|
|
|
* "angle-start" : 0.0,
|
2007-10-09 09:29:03 -04:00
|
|
|
* "angle-end" : 360.0,
|
|
|
|
* "axis" : "z-axis",
|
|
|
|
* "alpha" : {
|
2009-10-21 10:43:01 -04:00
|
|
|
* "timeline" : { "duration" : 4000, "loop" : true },
|
|
|
|
* "mode" : "easeInSine"
|
2007-10-09 09:29:03 -04:00
|
|
|
* }
|
|
|
|
* }
|
2010-06-30 10:50:47 -04:00
|
|
|
* ]]></programlisting></informalexample>
|
2007-10-09 09:29:03 -04:00
|
|
|
*
|
2007-10-10 06:42:19 -04:00
|
|
|
* And then to apply a defined behaviour to an actor defined inside the
|
|
|
|
* definition of an actor, the "behaviour" member can be used:
|
|
|
|
*
|
2010-06-30 10:50:47 -04:00
|
|
|
* <informalexample><programlisting><![CDATA[
|
2007-10-10 06:42:19 -04:00
|
|
|
* {
|
|
|
|
* "id" : "my-rotating-actor",
|
|
|
|
* "type" : "ClutterTexture",
|
|
|
|
* ...
|
|
|
|
* "behaviours" : [ "rotate-behaviour" ]
|
|
|
|
* }
|
2010-06-30 10:50:47 -04:00
|
|
|
* ]]></programlisting></informalexample>
|
2007-10-10 06:42:19 -04:00
|
|
|
*
|
2007-10-25 10:34:54 -04:00
|
|
|
* A #ClutterAlpha belonging to a #ClutterBehaviour can only be defined
|
2009-10-21 10:43:01 -04:00
|
|
|
* implicitly like in the example above, or explicitly by setting the
|
|
|
|
* "alpha" property to point to a previously defined #ClutterAlpha, e.g.:
|
|
|
|
*
|
2010-06-30 10:50:47 -04:00
|
|
|
* <informalexample><programlisting><![CDATA[
|
2009-10-21 10:43:01 -04:00
|
|
|
* {
|
|
|
|
* "id" : "rotate-behaviour",
|
|
|
|
* "type" : "ClutterBehaviourRotate",
|
|
|
|
* "angle-start" : 0.0,
|
|
|
|
* "angle-end" : 360.0,
|
|
|
|
* "axis" : "z-axis",
|
|
|
|
* "alpha" : {
|
|
|
|
* "id" : "rotate-alpha",
|
|
|
|
* "type" : "ClutterAlpha",
|
|
|
|
* "timeline" : {
|
|
|
|
* "id" : "rotate-timeline",
|
|
|
|
* "type : "ClutterTimeline",
|
|
|
|
* "duration" : 4000,
|
|
|
|
* "loop" : true
|
|
|
|
* },
|
|
|
|
* "function" : "custom_sine_alpha"
|
|
|
|
* }
|
|
|
|
* }
|
2010-06-30 10:50:47 -04:00
|
|
|
* ]]></programlisting></informalexample>
|
2009-10-21 10:43:01 -04:00
|
|
|
*
|
|
|
|
* Implicitely defined #ClutterAlpha<!-- -->s and #ClutterTimeline<!-- -->s
|
|
|
|
* can omit the <varname>id</varname> member, as well as the
|
|
|
|
* <varname>type</varname> member, but will not be available using
|
|
|
|
* clutter_script_get_object() (they can, however, be extracted using the
|
|
|
|
* #ClutterBehaviour and #ClutterAlpha API respectively).
|
2007-10-25 10:34:54 -04:00
|
|
|
*
|
2007-11-15 10:24:43 -05:00
|
|
|
* Signal handlers can be defined inside a Clutter UI definition file and
|
|
|
|
* then autoconnected to their respective signals using the
|
|
|
|
* clutter_script_connect_signals() function:
|
|
|
|
*
|
2010-06-30 10:50:47 -04:00
|
|
|
* <informalexample><programlisting><![CDATA[
|
2007-11-15 10:24:43 -05:00
|
|
|
* ...
|
|
|
|
* "signals" : [
|
|
|
|
* { "name" : "button-press-event", "handler" : "on_button_press" },
|
|
|
|
* {
|
|
|
|
* "name" : "foo-signal",
|
|
|
|
* "handler" : "after_foo",
|
|
|
|
* "after" : true
|
|
|
|
* },
|
2008-06-19 16:45:28 -04:00
|
|
|
* ],
|
|
|
|
* ...
|
2010-06-30 10:50:47 -04:00
|
|
|
* ]]></programlisting></informalexample>
|
2007-11-15 10:24:43 -05:00
|
|
|
*
|
|
|
|
* 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().
|
|
|
|
*
|
2011-06-11 08:30:02 -04:00
|
|
|
* Signals can also be directly attached to a specific state defined
|
|
|
|
* inside a #ClutterState instance, for instance:
|
|
|
|
*
|
|
|
|
* |[
|
|
|
|
* ...
|
|
|
|
* "signals" : [
|
|
|
|
* {
|
|
|
|
* "name" : "enter-event",
|
|
|
|
* "states" : "button-states",
|
|
|
|
* "target-state" : "hover"
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* "name" : "leave-event",
|
|
|
|
* "states" : "button-states",
|
|
|
|
* "target-state" : "base"
|
2011-06-13 08:07:04 -04:00
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* "name" : "button-press-event",
|
|
|
|
* "states" : "button-states",
|
|
|
|
* "target-state" : "active",
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* "name" : "key-press-event",
|
|
|
|
* "states" : "button-states",
|
|
|
|
* "target-state" : "key-focus",
|
|
|
|
* "warp" : true
|
2011-06-11 08:30:02 -04:00
|
|
|
* }
|
|
|
|
* ],
|
|
|
|
* ...
|
|
|
|
* ]|
|
|
|
|
*
|
|
|
|
* The "states" key defines the #ClutterState instance to be used to
|
|
|
|
* resolve the "target-state" key; it can be either a script id for a
|
|
|
|
* #ClutterState built by the same #ClutterScript instance, or to a
|
|
|
|
* #ClutterState built in code and associated to the #ClutterScript
|
|
|
|
* instance through the clutter_script_add_states() function. If no
|
|
|
|
* "states" key is present, then the default #ClutterState associated to
|
|
|
|
* the #ClutterScript instance will be used; the default #ClutterState
|
2011-06-13 08:07:04 -04:00
|
|
|
* can be set using clutter_script_add_states() using a %NULL name. The
|
|
|
|
* "warp" key can be used to warp to a specific state instead of
|
|
|
|
* animating to it. State changes on signal emission will not affect
|
|
|
|
* the signal emission chain.
|
2011-06-11 08:30:02 -04:00
|
|
|
*
|
2007-10-10 10:29:29 -04:00
|
|
|
* Clutter reserves the following names, so classes defining properties
|
|
|
|
* through the usual GObject registration process should avoid using these
|
|
|
|
* names to avoid collisions:
|
|
|
|
*
|
|
|
|
* <programlisting><![CDATA[
|
|
|
|
* "id" := the unique name of a ClutterScript object
|
2008-11-04 11:37:04 -05:00
|
|
|
* "type" := the class literal name, also used to infer the type
|
|
|
|
* function
|
2007-10-10 10:29:29 -04:00
|
|
|
* "type_func" := the GType function name, for non-standard classes
|
|
|
|
* "children" := an array of names or objects to add as children
|
|
|
|
* "behaviours" := an array of names or objects to apply to an actor
|
2007-11-15 10:24:43 -05:00
|
|
|
* "signals" := an array of signal definitions to connect to an object
|
2008-11-04 11:37:04 -05:00
|
|
|
* "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
|
2007-10-10 10:29:29 -04:00
|
|
|
* ]]></programlisting>
|
|
|
|
*
|
2007-10-09 09:29:03 -04:00
|
|
|
* #ClutterScript is available since Clutter 0.6
|
|
|
|
*/
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-10-08 11:03:22 -04:00
|
|
|
#include "config.h"
|
2007-10-12 04:17:00 -04:00
|
|
|
#endif
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib-object.h>
|
2008-04-25 09:37:36 -04:00
|
|
|
#include <gmodule.h>
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
#include "clutter-actor.h"
|
2007-10-09 09:29:03 -04:00
|
|
|
#include "clutter-alpha.h"
|
|
|
|
#include "clutter-behaviour.h"
|
2007-10-08 11:03:22 -04:00
|
|
|
#include "clutter-container.h"
|
2007-10-09 09:29:03 -04:00
|
|
|
#include "clutter-stage.h"
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
#include "clutter-state.h"
|
2007-10-16 10:40:00 -04:00
|
|
|
#include "clutter-texture.h"
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
#include "clutter-script.h"
|
|
|
|
#include "clutter-script-private.h"
|
2007-10-25 10:34:54 -04:00
|
|
|
#include "clutter-scriptable.h"
|
2007-10-08 11:03:22 -04:00
|
|
|
|
2009-01-20 13:24:58 -05:00
|
|
|
#include "clutter-enum-types.h"
|
2007-10-08 11:03:22 -04:00
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-debug.h"
|
|
|
|
|
2007-10-29 11:57:59 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_FILENAME_SET,
|
2010-06-21 05:20:32 -04:00
|
|
|
PROP_FILENAME,
|
2012-03-06 09:23:33 -05:00
|
|
|
PROP_TRANSLATION_DOMAIN,
|
2010-06-21 05:20:32 -04:00
|
|
|
|
|
|
|
PROP_LAST
|
2007-10-29 11:57:59 -04:00
|
|
|
};
|
|
|
|
|
2010-06-21 05:20:32 -04:00
|
|
|
static GParamSpec *obj_props[PROP_LAST];
|
|
|
|
|
2007-10-08 11:03:22 -04:00
|
|
|
#define CLUTTER_SCRIPT_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_SCRIPT, ClutterScriptPrivate))
|
|
|
|
|
|
|
|
struct _ClutterScriptPrivate
|
|
|
|
{
|
|
|
|
GHashTable *objects;
|
|
|
|
|
|
|
|
guint last_merge_id;
|
2007-10-18 08:31:07 -04:00
|
|
|
guint last_unknown;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
2009-11-04 08:32:26 -05:00
|
|
|
ClutterScriptParser *parser;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
2011-06-10 12:16:45 -04:00
|
|
|
GHashTable *states;
|
|
|
|
|
2008-06-24 12:47:43 -04:00
|
|
|
gchar **search_paths;
|
|
|
|
|
2012-03-06 09:23:33 -05:00
|
|
|
gchar *translation_domain;
|
|
|
|
|
2007-10-08 11:03:22 -04:00
|
|
|
gchar *filename;
|
|
|
|
guint is_filename : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (ClutterScript, clutter_script, G_TYPE_OBJECT);
|
|
|
|
|
2007-10-26 05:05:06 -04:00
|
|
|
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;
|
|
|
|
|
2011-09-07 11:14:10 -04:00
|
|
|
return _clutter_script_get_type_from_class (type_name);
|
2007-10-26 05:05:06 -04:00
|
|
|
}
|
|
|
|
|
2007-10-25 10:34:54 -04:00
|
|
|
void
|
|
|
|
property_info_free (gpointer data)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (data))
|
|
|
|
{
|
|
|
|
PropertyInfo *pinfo = data;
|
|
|
|
|
2009-11-03 13:30:28 -05:00
|
|
|
if (pinfo->node)
|
|
|
|
json_node_free (pinfo->node);
|
|
|
|
|
2007-10-25 10:34:54 -04:00
|
|
|
if (pinfo->pspec)
|
|
|
|
g_param_spec_unref (pinfo->pspec);
|
|
|
|
|
|
|
|
g_free (pinfo->name);
|
|
|
|
|
|
|
|
g_slice_free (PropertyInfo, pinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-15 10:24:43 -05:00
|
|
|
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);
|
2011-06-13 08:08:26 -04:00
|
|
|
g_free (sinfo->state);
|
|
|
|
g_free (sinfo->target);
|
2007-11-15 10:24:43 -05:00
|
|
|
|
|
|
|
g_slice_free (SignalInfo, sinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-25 10:34:54 -04:00
|
|
|
void
|
2007-10-08 11:03:22 -04:00
|
|
|
object_info_free (gpointer data)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (data))
|
|
|
|
{
|
|
|
|
ObjectInfo *oinfo = data;
|
|
|
|
|
|
|
|
g_free (oinfo->id);
|
2007-10-10 06:42:19 -04:00
|
|
|
g_free (oinfo->class_name);
|
|
|
|
g_free (oinfo->type_func);
|
2007-10-08 11:03:22 -04:00
|
|
|
|
2007-10-25 10:34:54 -04:00
|
|
|
g_list_foreach (oinfo->properties, (GFunc) property_info_free, NULL);
|
2007-10-08 11:03:22 -04:00
|
|
|
g_list_free (oinfo->properties);
|
|
|
|
|
2007-11-15 10:24:43 -05:00
|
|
|
g_list_foreach (oinfo->signals, (GFunc) signal_info_free, NULL);
|
|
|
|
g_list_free (oinfo->signals);
|
|
|
|
|
2007-10-09 09:29:03 -04:00
|
|
|
/* these are ids */
|
2007-10-08 12:25:10 -04:00
|
|
|
g_list_foreach (oinfo->children, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (oinfo->children);
|
|
|
|
|
2008-05-28 05:03:49 -04:00
|
|
|
/* 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
|
|
|
|
*/
|
script: Fix the memory management
Currently, the memory management in ClutterScript is overly complicated.
The basic design tenet should be:
- ClutterScript owns a reference on every object it creates
This allows the Script instance to reliably handle the lifetime of the
instances from creation to disposal.
In case of unmerge, the Script instance should destroy any Actor
instance, except for the Stage, and release the reference it owns. The
Stage is special because it's really owned by Clutter itself, and it
should be destroyed explicitly.
When disposing the Script itself, it should just release the reference;
any parented actor, or any InitiallyUnowned instance, will then be
managed by the parent object, as they should, while every GObject
instance will go away, as documented.
This commit is based on a patch by:
Henrik Hedberg <hhedberg@innologies.fi>
http://bugzilla.clutter-project.org/show_bug.cgi?id=2316
2010-09-13 16:29:52 -04:00
|
|
|
if (oinfo->object != NULL)
|
2007-10-18 08:31:07 -04:00
|
|
|
{
|
2008-05-28 05:03:49 -04:00
|
|
|
if (oinfo->is_unmerged)
|
|
|
|
{
|
script: Fix the memory management
Currently, the memory management in ClutterScript is overly complicated.
The basic design tenet should be:
- ClutterScript owns a reference on every object it creates
This allows the Script instance to reliably handle the lifetime of the
instances from creation to disposal.
In case of unmerge, the Script instance should destroy any Actor
instance, except for the Stage, and release the reference it owns. The
Stage is special because it's really owned by Clutter itself, and it
should be destroyed explicitly.
When disposing the Script itself, it should just release the reference;
any parented actor, or any InitiallyUnowned instance, will then be
managed by the parent object, as they should, while every GObject
instance will go away, as documented.
This commit is based on a patch by:
Henrik Hedberg <hhedberg@innologies.fi>
http://bugzilla.clutter-project.org/show_bug.cgi?id=2316
2010-09-13 16:29:52 -04:00
|
|
|
if (oinfo->is_actor && !oinfo->is_stage)
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (oinfo->object));
|
2008-05-28 05:03:49 -04:00
|
|
|
}
|
2007-10-18 08:31:07 -04:00
|
|
|
|
script: Fix the memory management
Currently, the memory management in ClutterScript is overly complicated.
The basic design tenet should be:
- ClutterScript owns a reference on every object it creates
This allows the Script instance to reliably handle the lifetime of the
instances from creation to disposal.
In case of unmerge, the Script instance should destroy any Actor
instance, except for the Stage, and release the reference it owns. The
Stage is special because it's really owned by Clutter itself, and it
should be destroyed explicitly.
When disposing the Script itself, it should just release the reference;
any parented actor, or any InitiallyUnowned instance, will then be
managed by the parent object, as they should, while every GObject
instance will go away, as documented.
This commit is based on a patch by:
Henrik Hedberg <hhedberg@innologies.fi>
http://bugzilla.clutter-project.org/show_bug.cgi?id=2316
2010-09-13 16:29:52 -04:00
|
|
|
g_object_unref (oinfo->object);
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
oinfo->object = NULL;
|
|
|
|
}
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
g_slice_free (ObjectInfo, oinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_script_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
ClutterScriptPrivate *priv = CLUTTER_SCRIPT_GET_PRIVATE (gobject);
|
|
|
|
|
|
|
|
g_object_unref (priv->parser);
|
|
|
|
g_hash_table_destroy (priv->objects);
|
2008-06-24 12:47:43 -04:00
|
|
|
g_strfreev (priv->search_paths);
|
2007-10-08 11:03:22 -04:00
|
|
|
g_free (priv->filename);
|
2011-06-10 12:16:45 -04:00
|
|
|
g_hash_table_destroy (priv->states);
|
2012-03-06 09:23:33 -05:00
|
|
|
g_free (priv->translation_domain);
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_script_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
2012-03-06 09:23:33 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-29 11:57:59 -04:00
|
|
|
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;
|
2012-03-06 09:23:33 -05:00
|
|
|
|
2007-10-29 11:57:59 -04:00
|
|
|
case PROP_FILENAME:
|
|
|
|
g_value_set_string (value, script->priv->filename);
|
|
|
|
break;
|
2012-03-06 09:23:33 -05:00
|
|
|
|
|
|
|
case PROP_TRANSLATION_DOMAIN:
|
|
|
|
g_value_set_string (value, script->priv->translation_domain);
|
|
|
|
break;
|
|
|
|
|
2007-10-29 11:57:59 -04:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-08 11:03:22 -04:00
|
|
|
static void
|
|
|
|
clutter_script_class_init (ClutterScriptClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (ClutterScriptPrivate));
|
|
|
|
|
2007-10-26 05:05:06 -04:00
|
|
|
klass->get_type_from_name = clutter_script_real_get_type_from_name;
|
|
|
|
|
2007-10-29 11:57:59 -04:00
|
|
|
/**
|
|
|
|
* ClutterScript:filename-set:
|
|
|
|
*
|
2009-11-06 09:07:46 -05:00
|
|
|
* Whether the #ClutterScript:filename property is set. If this property
|
2007-10-29 11:57:59 -04:00
|
|
|
* is %TRUE then the currently parsed data comes from a file, and the
|
2009-11-06 09:07:46 -05:00
|
|
|
* file name is stored inside the #ClutterScript:filename property.
|
2007-10-29 11:57:59 -04:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
2010-10-15 10:24:27 -04:00
|
|
|
obj_props[PROP_FILENAME_SET] =
|
|
|
|
g_param_spec_boolean ("filename-set",
|
|
|
|
P_("Filename Set"),
|
|
|
|
P_("Whether the :filename property is set"),
|
|
|
|
FALSE,
|
|
|
|
CLUTTER_PARAM_READABLE);
|
2009-11-06 09:07:46 -05:00
|
|
|
|
2007-10-29 11:57:59 -04:00
|
|
|
/**
|
|
|
|
* ClutterScript:filename:
|
|
|
|
*
|
2009-11-06 09:07:46 -05:00
|
|
|
* The path of the currently parsed file. If #ClutterScript:filename-set
|
2007-10-29 11:57:59 -04:00
|
|
|
* is %FALSE then the value of this property is undefined.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
2010-10-15 10:24:27 -04:00
|
|
|
obj_props[PROP_FILENAME] =
|
|
|
|
g_param_spec_string ("filename",
|
|
|
|
P_("Filename"),
|
|
|
|
P_("The path of the currently parsed file"),
|
|
|
|
NULL,
|
|
|
|
CLUTTER_PARAM_READABLE);
|
|
|
|
|
2012-03-06 09:23:33 -05:00
|
|
|
/**
|
|
|
|
* ClutterScript:translation-domain:
|
|
|
|
*
|
|
|
|
* The translation domain, used to localize strings marked as translatable
|
|
|
|
* inside a UI definition.
|
|
|
|
*
|
|
|
|
* If #ClutterScript:translation-domain is set to %NULL, #ClutterScript
|
|
|
|
* will use gettext(), otherwise g_dgettext() will be used.
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
obj_props[PROP_TRANSLATION_DOMAIN] =
|
|
|
|
g_param_spec_string ("translation-domain",
|
|
|
|
P_("Translation Domain"),
|
|
|
|
P_("The translation domain used to localize string"),
|
|
|
|
NULL,
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gobject_class->set_property = clutter_script_set_property;
|
2010-10-15 10:24:27 -04:00
|
|
|
gobject_class->get_property = clutter_script_get_property;
|
|
|
|
gobject_class->finalize = clutter_script_finalize;
|
|
|
|
|
2011-03-03 06:35:46 -05:00
|
|
|
g_object_class_install_properties (gobject_class,
|
|
|
|
PROP_LAST,
|
|
|
|
obj_props);
|
2007-10-08 11:03:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_script_init (ClutterScript *script)
|
|
|
|
{
|
|
|
|
ClutterScriptPrivate *priv;
|
|
|
|
|
|
|
|
script->priv = priv = CLUTTER_SCRIPT_GET_PRIVATE (script);
|
|
|
|
|
2009-11-04 08:32:26 -05:00
|
|
|
priv->parser = g_object_new (CLUTTER_TYPE_SCRIPT_PARSER, NULL);
|
|
|
|
priv->parser->script = script;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
priv->is_filename = FALSE;
|
|
|
|
priv->last_merge_id = 0;
|
|
|
|
|
|
|
|
priv->objects = g_hash_table_new_full (g_str_hash, g_str_equal,
|
2008-05-28 08:09:41 -04:00
|
|
|
NULL,
|
2007-10-08 11:03:22 -04:00
|
|
|
object_info_free);
|
2011-06-10 12:16:45 -04:00
|
|
|
priv->states = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free,
|
|
|
|
(GDestroyNotify) g_object_unref);
|
2007-10-08 11:03:22 -04:00
|
|
|
}
|
|
|
|
|
2007-10-10 06:42:19 -04:00
|
|
|
/**
|
|
|
|
* 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 behaviours and 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.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
2007-10-08 11:03:22 -04:00
|
|
|
ClutterScript *
|
|
|
|
clutter_script_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CLUTTER_TYPE_SCRIPT, NULL);
|
|
|
|
}
|
|
|
|
|
2007-10-10 06:42:19 -04:00
|
|
|
/**
|
|
|
|
* 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
|
2007-10-18 08:31:07 -04:00
|
|
|
* accordingly. On success, the merge id for the UI definitions is
|
2010-08-17 09:54:20 -04:00
|
|
|
* returned. You can use the merge id with clutter_script_unmerge_objects().
|
2007-10-10 06:42:19 -04:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
2007-10-08 11:03:22 -04:00
|
|
|
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;
|
2007-10-18 08:31:07 -04:00
|
|
|
priv->last_merge_id += 1;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
internal_error = NULL;
|
2009-11-04 08:32:26 -05:00
|
|
|
json_parser_load_from_file (JSON_PARSER (priv->parser),
|
|
|
|
filename,
|
|
|
|
&internal_error);
|
2007-10-08 11:03:22 -04:00
|
|
|
if (internal_error)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, internal_error);
|
2007-10-18 08:31:07 -04:00
|
|
|
priv->last_merge_id -= 1;
|
2007-10-08 11:03:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return priv->last_merge_id;
|
|
|
|
}
|
|
|
|
|
2007-10-10 06:42:19 -04:00
|
|
|
/**
|
|
|
|
* 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
|
2007-10-18 08:31:07 -04:00
|
|
|
* accordingly. On success, the merge id for the UI definitions is
|
2010-11-18 09:14:37 -05:00
|
|
|
* returned. You can use the merge id with clutter_script_unmerge_objects().
|
2007-10-10 06:42:19 -04:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
2007-10-08 11:03:22 -04:00
|
|
|
guint
|
|
|
|
clutter_script_load_from_data (ClutterScript *script,
|
|
|
|
const gchar *data,
|
2007-12-06 06:25:16 -05:00
|
|
|
gssize length,
|
2007-10-08 11:03:22 -04:00
|
|
|
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);
|
|
|
|
|
2007-12-06 06:25:16 -05:00
|
|
|
if (length < 0)
|
|
|
|
length = strlen (data);
|
|
|
|
|
2007-10-08 11:03:22 -04:00
|
|
|
priv = script->priv;
|
|
|
|
|
|
|
|
g_free (priv->filename);
|
|
|
|
priv->filename = NULL;
|
|
|
|
priv->is_filename = FALSE;
|
2007-10-18 08:31:07 -04:00
|
|
|
priv->last_merge_id += 1;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
internal_error = NULL;
|
2009-11-04 08:32:26 -05:00
|
|
|
json_parser_load_from_data (JSON_PARSER (priv->parser),
|
2009-11-06 09:07:46 -05:00
|
|
|
data, length,
|
|
|
|
&internal_error);
|
2007-10-08 11:03:22 -04:00
|
|
|
if (internal_error)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, internal_error);
|
2007-10-18 08:31:07 -04:00
|
|
|
priv->last_merge_id -= 1;
|
2007-10-08 11:03:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return priv->last_merge_id;
|
|
|
|
}
|
|
|
|
|
2012-01-16 06:27:08 -05:00
|
|
|
/**
|
|
|
|
* 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 clutter_script_unmerge_objects().
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-10-10 06:42:19 -04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2010-10-11 10:07:06 -04:00
|
|
|
* Return value: (transfer none): the named object, or %NULL if no object
|
2009-02-16 19:25:20 -05:00
|
|
|
* with the given name was available
|
2007-10-10 06:42:19 -04:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
2007-10-08 11:03:22 -04:00
|
|
|
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;
|
|
|
|
|
2009-11-04 09:05:13 -05:00
|
|
|
_clutter_script_construct_object (script, oinfo);
|
|
|
|
_clutter_script_apply_properties (script, oinfo);
|
|
|
|
|
|
|
|
return oinfo->object;
|
2007-10-08 11:03:22 -04:00
|
|
|
}
|
|
|
|
|
2007-10-27 15:08:59 -04:00
|
|
|
static gint
|
2007-10-08 11:03:22 -04:00
|
|
|
clutter_script_get_objects_valist (ClutterScript *script,
|
|
|
|
const gchar *first_name,
|
|
|
|
va_list args)
|
|
|
|
{
|
2007-10-27 15:08:59 -04:00
|
|
|
gint retval = 0;
|
2007-10-08 11:03:22 -04:00
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
name = first_name;
|
|
|
|
while (name)
|
|
|
|
{
|
2007-10-27 15:08:59 -04:00
|
|
|
GObject **obj = NULL;
|
|
|
|
|
|
|
|
obj = va_arg (args, GObject**);
|
|
|
|
|
|
|
|
*obj = clutter_script_get_object (script, name);
|
|
|
|
if (*obj)
|
|
|
|
retval += 1;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
name = va_arg (args, gchar*);
|
|
|
|
}
|
|
|
|
|
2007-10-27 15:08:59 -04:00
|
|
|
return retval;
|
2007-10-08 11:03:22 -04:00
|
|
|
}
|
|
|
|
|
2007-10-10 06:42:19 -04:00
|
|
|
/**
|
|
|
|
* clutter_script_get_objects:
|
|
|
|
* @script: a #ClutterScript
|
|
|
|
* @first_name: the name of the first object to retrieve
|
2011-07-26 08:43:37 -04:00
|
|
|
* @...: return location for a #GObject, then additional names, ending
|
2007-10-27 15:08:59 -04:00
|
|
|
* with %NULL
|
2007-10-10 06:42:19 -04:00
|
|
|
*
|
2007-10-27 15:08:59 -04:00
|
|
|
* 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:
|
2007-10-10 06:42:19 -04:00
|
|
|
*
|
2007-10-27 15:08:59 -04:00
|
|
|
* <informalexample><programlisting>
|
|
|
|
* 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);
|
2007-10-29 11:57:59 -04:00
|
|
|
* </programlisting></informalexample>
|
2007-10-27 15:08:59 -04:00
|
|
|
*
|
|
|
|
* Note: This function does not increment the reference count of the
|
|
|
|
* returned objects.
|
|
|
|
*
|
|
|
|
* Return value: the number of objects returned.
|
2007-10-10 06:42:19 -04:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
2007-10-27 15:08:59 -04:00
|
|
|
gint
|
2007-10-08 11:03:22 -04:00
|
|
|
clutter_script_get_objects (ClutterScript *script,
|
|
|
|
const gchar *first_name,
|
|
|
|
...)
|
|
|
|
{
|
2007-10-27 15:08:59 -04:00
|
|
|
gint retval;
|
2007-10-08 11:03:22 -04:00
|
|
|
va_list var_args;
|
|
|
|
|
2007-10-27 15:08:59 -04:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), 0);
|
|
|
|
g_return_val_if_fail (first_name != NULL, 0);
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
va_start (var_args, first_name);
|
|
|
|
retval = clutter_script_get_objects_valist (script, first_name, var_args);
|
|
|
|
va_end (var_args);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
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)
|
|
|
|
{
|
2007-10-25 10:34:54 -04:00
|
|
|
CLUTTER_NOTE (SCRIPT,
|
|
|
|
"Unmerging object (id:%s, type:%s, merge-id:%d)",
|
|
|
|
oinfo->id,
|
|
|
|
oinfo->class_name,
|
|
|
|
oinfo->merge_id);
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
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_foreach (data.ids, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (data.ids);
|
|
|
|
|
|
|
|
clutter_script_ensure_objects (script);
|
|
|
|
}
|
|
|
|
|
2009-11-04 08:32:26 -05:00
|
|
|
static void
|
|
|
|
construct_each_objects (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ClutterScript *script = user_data;
|
|
|
|
ObjectInfo *oinfo = value;
|
|
|
|
|
2009-11-04 09:05:13 -05:00
|
|
|
/* we have unfinished business */
|
2009-11-04 08:32:26 -05:00
|
|
|
if (oinfo->has_unresolved)
|
2009-11-04 09:05:13 -05:00
|
|
|
{
|
|
|
|
/* this should not happen, but resilence 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,
|
|
|
|
* adding children and applying behaviours
|
|
|
|
*/
|
|
|
|
_clutter_script_apply_properties (script, oinfo);
|
|
|
|
}
|
2009-11-04 08:32:26 -05:00
|
|
|
}
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
/**
|
2007-11-23 08:11:10 -05:00
|
|
|
* clutter_script_ensure_objects:
|
2007-10-18 08:31:07 -04:00
|
|
|
* @script: a #ClutterScript
|
|
|
|
*
|
|
|
|
* Ensure that every object defined inside @script is correctly
|
|
|
|
* constructed. You should rarely need to use this function.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_script_ensure_objects (ClutterScript *script)
|
|
|
|
{
|
|
|
|
ClutterScriptPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_SCRIPT (script));
|
|
|
|
|
|
|
|
priv = script->priv;
|
2009-11-04 08:32:26 -05:00
|
|
|
g_hash_table_foreach (priv->objects, construct_each_objects, script);
|
2007-10-18 08:31:07 -04:00
|
|
|
}
|
|
|
|
|
2007-10-26 05:05:06 -04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-14 06:32:24 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
Eliminate G_CONST_RETURN
The G_CONST_RETURN define in GLib is, and has always been, a bit fuzzy.
We always used it to conform to the platform, at least for public-facing
API.
At first I assumed it has something to do with brain-damaged compilers
or with weird platforms where const was not really supported; sadly,
it's something much, much worse: it's a define that can be toggled at
compile-time to remove const from the signature of public API. This is a
truly terrifying feature that I assume was added in the past century,
and whose inception clearly had something to do with massive doses of
absynthe and opium — because any other explanation would make the
existence of such a feature even worse than assuming drugs had anything
to do with it.
Anyway, and pleasing the gods, this dubious feature is being
removed/deprecated in GLib; see bug:
https://bugzilla.gnome.org/show_bug.cgi?id=644611
Before deprecation, though, we should just remove its usage from the
whole API. We should especially remove its usage from Cally's internals,
since there it never made sense in the first place.
2011-06-07 10:49:20 -04:00
|
|
|
const gchar *
|
2007-11-14 06:32:24 -05:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2007-11-15 10:24:43 -05:00
|
|
|
typedef struct {
|
|
|
|
GModule *module;
|
|
|
|
gpointer data;
|
|
|
|
} ConnectData;
|
|
|
|
|
2008-08-04 12:21:27 -04:00
|
|
|
/* default signal connection code */
|
2007-11-15 10:24:43 -05:00
|
|
|
static void
|
|
|
|
clutter_script_default_connect (ClutterScript *script,
|
2008-08-04 12:33:43 -04:00
|
|
|
GObject *gobject,
|
2007-11-15 10:24:43 -05:00
|
|
|
const gchar *signal_name,
|
|
|
|
const gchar *signal_handler,
|
2008-08-04 12:33:43 -04:00
|
|
|
GObject *connect_gobject,
|
2007-11-15 10:24:43 -05:00
|
|
|
GConnectFlags flags,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-08-04 12:21:27 -04:00
|
|
|
ConnectData *data = user_data;
|
2008-08-04 12:33:43 -04:00
|
|
|
GCallback function;
|
|
|
|
|
|
|
|
if (!data->module)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_module_symbol (data->module, signal_handler, (gpointer) &function))
|
2007-11-15 10:24:43 -05:00
|
|
|
{
|
2008-08-04 12:21:27 -04:00
|
|
|
g_warning ("Could not find a signal handler '%s' for signal '%s::%s'",
|
|
|
|
signal_handler,
|
2008-08-04 12:33:43 -04:00
|
|
|
connect_gobject ? G_OBJECT_TYPE_NAME (connect_gobject)
|
|
|
|
: G_OBJECT_TYPE_NAME (gobject),
|
2008-08-04 12:21:27 -04:00
|
|
|
signal_name);
|
2007-11-15 10:24:43 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLUTTER_NOTE (SCRIPT,
|
2008-08-04 12:21:27 -04:00
|
|
|
"connecting %s::%s to %s (afetr:%s, swapped:%s, object:%s)",
|
2008-08-04 12:33:43 -04:00
|
|
|
(connect_gobject ? G_OBJECT_TYPE_NAME (connect_gobject)
|
|
|
|
: G_OBJECT_TYPE_NAME (gobject)),
|
2007-11-15 10:24:43 -05:00
|
|
|
signal_name,
|
|
|
|
signal_handler,
|
2008-08-04 12:21:27 -04:00
|
|
|
(flags & G_CONNECT_AFTER) ? "true" : "false",
|
|
|
|
(flags & G_CONNECT_SWAPPED) ? "true" : "false",
|
2008-08-04 12:33:43 -04:00
|
|
|
(connect_gobject ? G_OBJECT_TYPE_NAME (connect_gobject)
|
|
|
|
: "<none>"));
|
|
|
|
|
|
|
|
if (connect_gobject != NULL)
|
|
|
|
g_signal_connect_object (gobject,
|
|
|
|
signal_name, function,
|
|
|
|
connect_gobject,
|
|
|
|
flags);
|
2007-11-15 10:24:43 -05:00
|
|
|
else
|
2008-08-04 12:33:43 -04:00
|
|
|
g_signal_connect_data (gobject,
|
|
|
|
signal_name, function,
|
|
|
|
data->data,
|
|
|
|
NULL,
|
|
|
|
flags);
|
2007-11-15 10:24:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2008-08-04 12:33:43 -04:00
|
|
|
* This method invokes clutter_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.
|
2007-11-15 10:24:43 -05:00
|
|
|
*
|
2008-08-04 12:33:43 -04:00
|
|
|
* Note that this function will not work if #GModule is not supported by
|
|
|
|
* the platform Clutter is running on.
|
2007-11-15 10:24:43 -05:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_script_connect_signals (ClutterScript *script,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ConnectData *cd;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_SCRIPT (script));
|
|
|
|
|
|
|
|
if (!g_module_supported ())
|
2008-08-04 12:21:27 -04:00
|
|
|
{
|
|
|
|
g_critical ("clutter_script_connect_signals() requires a working "
|
|
|
|
"GModule support from GLib");
|
|
|
|
return;
|
|
|
|
}
|
2007-11-15 10:24:43 -05:00
|
|
|
|
|
|
|
cd = g_new (ConnectData, 1);
|
2009-11-06 09:04:36 -05:00
|
|
|
cd->module = g_module_open (NULL, 0);
|
2007-11-15 10:24:43 -05:00
|
|
|
cd->data = user_data;
|
|
|
|
|
|
|
|
clutter_script_connect_signals_full (script,
|
|
|
|
clutter_script_default_connect,
|
|
|
|
cd);
|
|
|
|
|
|
|
|
g_module_close (cd->module);
|
|
|
|
|
|
|
|
g_free (cd);
|
|
|
|
}
|
|
|
|
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
typedef struct {
|
|
|
|
ClutterState *state;
|
|
|
|
GObject *emitter;
|
|
|
|
gchar *target;
|
2011-06-12 06:27:34 -04:00
|
|
|
gulong signal_id;
|
|
|
|
gulong hook_id;
|
2011-06-13 08:07:04 -04:00
|
|
|
gboolean warp_to;
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
} HookData;
|
|
|
|
|
2007-11-15 10:24:43 -05:00
|
|
|
typedef struct {
|
|
|
|
ClutterScript *script;
|
|
|
|
ClutterScriptConnectFunc func;
|
|
|
|
gpointer user_data;
|
|
|
|
} SignalConnectData;
|
|
|
|
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
static void
|
|
|
|
hook_data_free (gpointer data)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (data != NULL))
|
|
|
|
{
|
|
|
|
HookData *hook_data = data;
|
|
|
|
|
|
|
|
g_free (hook_data->target);
|
|
|
|
g_slice_free (HookData, hook_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_script_state_change_hook (GSignalInvocationHint *ihint,
|
|
|
|
guint n_params,
|
|
|
|
const GValue *params,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
HookData *hook_data = user_data;
|
|
|
|
GObject *emitter;
|
|
|
|
|
|
|
|
emitter = g_value_get_object (¶ms[0]);
|
|
|
|
|
|
|
|
if (emitter == hook_data->emitter)
|
2011-06-13 08:07:04 -04:00
|
|
|
{
|
|
|
|
if (hook_data->warp_to)
|
|
|
|
clutter_state_warp_to_state (hook_data->state, hook_data->target);
|
|
|
|
else
|
|
|
|
clutter_state_set_state (hook_data->state, hook_data->target);
|
|
|
|
}
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-12 06:27:34 -04:00
|
|
|
static void
|
|
|
|
clutter_script_remove_state_change_hook (gpointer user_data,
|
|
|
|
GObject *object_p)
|
|
|
|
{
|
|
|
|
HookData *hook_data = user_data;
|
|
|
|
|
|
|
|
g_signal_remove_emission_hook (hook_data->signal_id,
|
|
|
|
hook_data->hook_id);
|
|
|
|
}
|
|
|
|
|
2007-11-15 10:24:43 -05:00
|
|
|
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;
|
|
|
|
|
2009-11-04 09:05:13 -05:00
|
|
|
_clutter_script_construct_object (script, oinfo);
|
2007-11-15 10:24:43 -05:00
|
|
|
|
|
|
|
unresolved = NULL;
|
|
|
|
for (l = oinfo->signals; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
SignalInfo *sinfo = l->data;
|
|
|
|
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
if (sinfo->is_handler)
|
|
|
|
{
|
|
|
|
GObject *connect_object = NULL;
|
2007-11-15 10:24:43 -05:00
|
|
|
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 10:24:43 -05:00
|
|
|
else
|
|
|
|
{
|
2011-06-10 12:16:45 -04:00
|
|
|
GObject *state_object = NULL;
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
const gchar *signal_name, *signal_detail;
|
|
|
|
gchar **components;
|
|
|
|
GQuark signal_quark;
|
|
|
|
guint signal_id;
|
|
|
|
HookData *hook_data;
|
|
|
|
|
2011-06-10 12:16:45 -04:00
|
|
|
if (sinfo->state == NULL)
|
2011-06-11 08:30:02 -04:00
|
|
|
state_object = (GObject *) clutter_script_get_states (script, NULL);
|
2011-06-10 12:16:45 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
state_object = clutter_script_get_object (script, sinfo->state);
|
|
|
|
if (state_object == NULL)
|
2011-06-11 08:30:02 -04:00
|
|
|
state_object = (GObject *) clutter_script_get_states (script, sinfo->state);
|
2011-06-10 12:16:45 -04:00
|
|
|
}
|
|
|
|
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
if (state_object == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
components = g_strsplit (sinfo->name, "::", 2);
|
|
|
|
if (g_strv_length (components) == 2)
|
|
|
|
{
|
|
|
|
signal_name = components[0];
|
|
|
|
signal_detail = components[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
signal_name = components[0];
|
|
|
|
signal_detail = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
signal_id = g_signal_lookup (signal_name, G_OBJECT_TYPE (object));
|
|
|
|
if (signal_id == 0)
|
|
|
|
{
|
|
|
|
g_strfreev (components);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (signal_detail != NULL)
|
|
|
|
signal_quark = g_quark_from_string (signal_detail);
|
|
|
|
else
|
|
|
|
signal_quark = 0;
|
|
|
|
|
|
|
|
hook_data = g_slice_new (HookData);
|
|
|
|
hook_data->emitter = object;
|
|
|
|
hook_data->state = CLUTTER_STATE (state_object);
|
|
|
|
hook_data->target = g_strdup (sinfo->target);
|
2011-06-13 08:07:04 -04:00
|
|
|
hook_data->warp_to = sinfo->warp_to;
|
2011-06-12 06:27:34 -04:00
|
|
|
hook_data->signal_id = signal_id;
|
|
|
|
hook_data->hook_id =
|
|
|
|
g_signal_add_emission_hook (signal_id, signal_quark,
|
|
|
|
clutter_script_state_change_hook,
|
|
|
|
hook_data,
|
|
|
|
hook_data_free);
|
|
|
|
|
|
|
|
g_object_weak_ref (hook_data->emitter,
|
|
|
|
clutter_script_remove_state_change_hook,
|
|
|
|
hook_data);
|
2007-11-15 10:24:43 -05:00
|
|
|
}
|
script: Allow connecting signal to ClutterState states
One of the uses of a ClutterState state machine along with ClutterScript
is to provide a quick way to transition from state to state in response
to signal emitted on specific instances.
Connecting a real function, in code, to a specific signal does not
improve the ease of use of ClutterScript to define scenes.
By adding a new signal definition to the current one we can have both a
simple way to define application logic in code and in the UI definition
file.
The new syntax is trivial:
{
"name" : <signal name>,
"state" : <state machine script id>,
"target-state" : <target state>
}
The ClutterState instance is identified by its script id, and the target
state is resolved at run-time, so it can be defined both in
ClutterScript or in code. Ideally, we should find a way to associate a
default ClutterState instance to the ClutterScript one that parses the
definition; this way we would be able to remove the "state" member, or
even "style" the behaviour of an object by replacing the ClutterState
instance.
The implementation uses a signal emission hook, to avoid knowing the
signal signature; we check the emitter of the signal against the object
that defined the signal, to avoid erroneous state changes.
2011-02-07 08:48:58 -05:00
|
|
|
|
|
|
|
signal_info_free (sinfo);
|
2007-11-15 10:24:43 -05:00
|
|
|
}
|
|
|
|
|
2008-08-04 12:21:27 -04:00
|
|
|
/* keep the unresolved signal handlers around, in case
|
|
|
|
* clutter_script_connect_signals() is called multiple
|
|
|
|
* times (e.g. after a UI definition merge)
|
|
|
|
*/
|
2007-11-15 10:24:43 -05:00
|
|
|
g_list_free (oinfo->signals);
|
|
|
|
oinfo->signals = unresolved;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-24 14:14:05 -05:00
|
|
|
* clutter_script_connect_signals_full:
|
2007-11-15 10:24:43 -05:00
|
|
|
* @script: a #ClutterScript
|
2011-11-24 14:14:05 -05:00
|
|
|
* @func: (scope call): signal connection function
|
2007-11-15 10:24:43 -05:00
|
|
|
* @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.
|
|
|
|
*
|
2008-08-04 12:21:27 -04:00
|
|
|
* 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
|
2010-09-03 07:14:50 -04:00
|
|
|
* names using the native API, but it can also be used on platforms
|
|
|
|
* that do not support GModule.
|
2008-08-04 12:21:27 -04:00
|
|
|
*
|
|
|
|
* Applications should use clutter_script_connect_signals().
|
2007-11-15 10:24:43 -05:00
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-10-09 09:29:03 -04:00
|
|
|
GQuark
|
|
|
|
clutter_script_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("clutter-script-error");
|
|
|
|
}
|
2008-06-24 12:47:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_script_add_search_paths:
|
|
|
|
* @script: a #ClutterScript
|
2011-07-27 03:14:10 -04:00
|
|
|
* @paths: (array length=n_paths): an array of strings containing
|
|
|
|
* different search paths
|
2008-06-24 12:47:43 -04:00
|
|
|
* @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 clutter_script_lookup_filename(), which
|
|
|
|
* can be used to define search paths for the textures source file name
|
|
|
|
* or other custom, file-based properties.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
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]);
|
|
|
|
|
2008-11-18 13:53:10 -05:00
|
|
|
CLUTTER_NOTE (SCRIPT,
|
|
|
|
"Added %" G_GSIZE_FORMAT " new search paths (new size: %d)",
|
2008-06-24 12:47:43 -04:00
|
|
|
n_paths,
|
|
|
|
g_strv_length (new_paths));
|
|
|
|
|
|
|
|
priv->search_paths = new_paths;
|
2008-08-04 12:21:27 -04:00
|
|
|
|
|
|
|
if (old_paths)
|
|
|
|
g_strfreev (old_paths);
|
2008-06-24 12:47:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
clutter_script_lookup_filename (ClutterScript *script,
|
|
|
|
const gchar *filename)
|
|
|
|
{
|
|
|
|
ClutterScriptPrivate *priv;
|
|
|
|
gchar *dirname;
|
|
|
|
gchar *retval;
|
|
|
|
|
2010-05-27 03:28:29 -04:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL);
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
2008-06-24 12:47:43 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-08-27 08:16:56 -04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2010-09-08 11:41:47 -04:00
|
|
|
* 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.
|
2008-08-27 08:16:56 -04:00
|
|
|
*
|
|
|
|
* Since: 0.8.2
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2009-11-04 08:32:26 -05:00
|
|
|
|
2011-06-10 12:16:45 -04:00
|
|
|
/**
|
2011-06-11 08:30:02 -04:00
|
|
|
* clutter_script_add_states:
|
2011-06-10 12:16:45 -04:00
|
|
|
* @script: a #ClutterScript
|
2011-06-11 08:30:02 -04:00
|
|
|
* @name: (allow-none): a name for the @state, or %NULL to
|
2011-06-10 12:16:45 -04:00
|
|
|
* set the default #ClutterState
|
2011-06-13 08:27:46 -04:00
|
|
|
* @state: a #ClutterState
|
2011-06-10 12:16:45 -04:00
|
|
|
*
|
2011-06-11 08:30:02 -04:00
|
|
|
* Associates a #ClutterState to the #ClutterScript instance using the given
|
|
|
|
* name.
|
2011-06-10 12:16:45 -04:00
|
|
|
*
|
|
|
|
* The #ClutterScript instance will use @state to resolve target states when
|
|
|
|
* connecting signal handlers.
|
|
|
|
*
|
|
|
|
* The #ClutterScript instance will take a reference on the #ClutterState
|
|
|
|
* passed to this function.
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
*/
|
|
|
|
void
|
2011-06-11 08:30:02 -04:00
|
|
|
clutter_script_add_states (ClutterScript *script,
|
|
|
|
const gchar *name,
|
|
|
|
ClutterState *state)
|
2011-06-10 12:16:45 -04:00
|
|
|
{
|
|
|
|
g_return_if_fail (CLUTTER_IS_SCRIPT (script));
|
|
|
|
g_return_if_fail (CLUTTER_IS_STATE (state));
|
|
|
|
|
2011-06-11 08:30:02 -04:00
|
|
|
if (name == NULL || *name == '\0')
|
|
|
|
name = "__clutter_script_default_state";
|
2011-06-10 12:16:45 -04:00
|
|
|
|
|
|
|
g_hash_table_replace (script->priv->states,
|
2011-06-11 08:30:02 -04:00
|
|
|
g_strdup (name),
|
2011-06-10 12:16:45 -04:00
|
|
|
g_object_ref (state));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-11 08:30:02 -04:00
|
|
|
* clutter_script_get_states:
|
2011-06-10 12:16:45 -04:00
|
|
|
* @script: a #ClutterScript
|
2011-06-11 08:30:02 -04:00
|
|
|
* @name: (allow-none): the name of the #ClutterState, or %NULL
|
2011-06-10 12:16:45 -04:00
|
|
|
*
|
|
|
|
* Retrieves the #ClutterState for the given @state_name.
|
|
|
|
*
|
2011-06-11 08:30:02 -04:00
|
|
|
* If @name is %NULL, this function will return the default
|
2011-06-10 12:16:45 -04:00
|
|
|
* #ClutterState instance.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): a pointer to the #ClutterState for the
|
|
|
|
* given name. The #ClutterState is owned by the #ClutterScript instance
|
|
|
|
* and it should not be unreferenced
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
*/
|
|
|
|
ClutterState *
|
2011-06-11 08:30:02 -04:00
|
|
|
clutter_script_get_states (ClutterScript *script,
|
|
|
|
const gchar *name)
|
2011-06-10 12:16:45 -04:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL);
|
|
|
|
|
2011-06-11 08:30:02 -04:00
|
|
|
if (name == NULL || *name == '\0')
|
|
|
|
name = "__clutter_script_default_state";
|
2011-06-10 12:16:45 -04:00
|
|
|
|
2011-06-11 08:30:02 -04:00
|
|
|
return g_hash_table_lookup (script->priv->states, name);
|
2011-06-10 12:16:45 -04:00
|
|
|
}
|
|
|
|
|
2012-03-06 09:23:33 -05:00
|
|
|
/**
|
|
|
|
* clutter_script_set_translation_domain:
|
|
|
|
* @script: a #ClutterScript
|
|
|
|
* @domain: (allow-none): the translation domain, or %NULL
|
|
|
|
*
|
|
|
|
* Sets the translation domain for @script.
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
* clutter_script_set_translation_domain().
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): the translation domain, if any is set,
|
|
|
|
* or %NULL
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
clutter_script_get_translation_domain (ClutterScript *script)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL);
|
|
|
|
|
|
|
|
return script->priv->translation_domain;
|
|
|
|
}
|
|
|
|
|
2009-11-06 09:07:26 -05:00
|
|
|
/*
|
|
|
|
* _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
|
|
|
|
*
|
|
|
|
*/
|
2009-11-04 08:32:26 -05:00
|
|
|
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++);
|
|
|
|
}
|
|
|
|
|
2009-11-06 09:07:26 -05:00
|
|
|
/*
|
|
|
|
* _clutter_script_warn_missing_attribute:
|
|
|
|
* @script: a #ClutterScript
|
2011-02-15 06:50:26 -05:00
|
|
|
* @id_: the id of an object definition, or %NULL
|
2009-11-06 09:07:26 -05:00
|
|
|
* @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
|
|
|
|
*/
|
2009-11-04 08:32:26 -05:00
|
|
|
void
|
|
|
|
_clutter_script_warn_missing_attribute (ClutterScript *script,
|
2011-02-15 06:50:26 -05:00
|
|
|
const gchar *id_,
|
2009-11-04 08:32:26 -05:00
|
|
|
const gchar *attribute)
|
|
|
|
{
|
|
|
|
ClutterScriptPrivate *priv = script->priv;
|
|
|
|
JsonParser *parser = JSON_PARSER (priv->parser);
|
2009-11-06 09:07:26 -05:00
|
|
|
gint current_line = json_parser_get_current_line (parser);
|
2009-11-04 08:32:26 -05:00
|
|
|
|
2011-02-15 06:50:26 -05:00
|
|
|
if (id_ != NULL && *id_ != '\0')
|
2009-11-04 08:32:26 -05:00
|
|
|
{
|
|
|
|
g_warning ("%s:%d: object '%s' has no '%s' attribute",
|
|
|
|
priv->is_filename ? priv->filename : "<input>",
|
2009-11-06 09:07:26 -05:00
|
|
|
current_line,
|
2011-02-15 06:50:26 -05:00
|
|
|
id_,
|
2009-11-04 08:32:26 -05:00
|
|
|
attribute);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("%s:%d: object has no '%s' attribute",
|
|
|
|
priv->is_filename ? priv->filename : "<input>",
|
2009-11-06 09:07:26 -05:00
|
|
|
current_line,
|
2009-11-04 08:32:26 -05:00
|
|
|
attribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-06 09:07:26 -05:00
|
|
|
/*
|
|
|
|
* _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
|
|
|
|
*/
|
2009-11-04 08:32:26 -05:00
|
|
|
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);
|
2009-11-06 09:07:26 -05:00
|
|
|
gint current_line = json_parser_get_current_line (parser);
|
2009-11-04 08:32:26 -05:00
|
|
|
|
|
|
|
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 : "<input>",
|
2009-11-06 09:07:26 -05:00
|
|
|
current_line,
|
2009-11-04 08:32:26 -05:00
|
|
|
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 : "<input>",
|
2009-11-06 09:07:26 -05:00
|
|
|
current_line,
|
2009-11-04 08:32:26 -05:00
|
|
|
attribute,
|
|
|
|
expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-06 09:07:26 -05:00
|
|
|
/*
|
|
|
|
* _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
|
|
|
|
*/
|
2009-11-04 08:32:26 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-11-06 09:07:26 -05:00
|
|
|
/*
|
|
|
|
* _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
|
|
|
|
*/
|
2009-11-04 08:32:26 -05:00
|
|
|
guint
|
|
|
|
_clutter_script_get_last_merge_id (ClutterScript *script)
|
|
|
|
{
|
|
|
|
return script->priv->last_merge_id;
|
|
|
|
}
|
|
|
|
|
2009-11-06 09:07:26 -05:00
|
|
|
/*
|
|
|
|
* _clutter_script_add_object_info:
|
|
|
|
* @script: a #ClutterScript
|
|
|
|
* @oinfo: a #ObjectInfo
|
|
|
|
*
|
|
|
|
* Adds @oinfo inside the objects list held by @script
|
|
|
|
*/
|
2009-11-04 08:32:26 -05:00
|
|
|
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);
|
|
|
|
}
|