2007-10-25 10:34:54 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Emmanuele Bassi <ebassi@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-25 10:34:54 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:clutter-scriptable
|
|
|
|
* @short_description: Override the UI definition parsing
|
|
|
|
*
|
|
|
|
* The #ClutterScriptableIface 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
|
|
|
|
* GObject properties, or allow custom properties.
|
|
|
|
*
|
|
|
|
* #ClutterScriptable is available since Clutter 0.6
|
|
|
|
*/
|
|
|
|
|
2016-05-05 10:21:51 -04:00
|
|
|
#include "clutter-build-config.h"
|
2007-10-25 10:34:54 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "clutter-scriptable.h"
|
|
|
|
#include "clutter-script-private.h"
|
|
|
|
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-debug.h"
|
|
|
|
|
2010-10-08 09:47:46 -04:00
|
|
|
typedef ClutterScriptableIface ClutterScriptableInterface;
|
2007-10-25 10:34:54 -04:00
|
|
|
|
2010-10-08 09:47:46 -04:00
|
|
|
G_DEFINE_INTERFACE (ClutterScriptable, clutter_scriptable, G_TYPE_OBJECT);
|
2007-10-25 10:34:54 -04:00
|
|
|
|
2010-10-08 09:47:46 -04:00
|
|
|
static void
|
|
|
|
clutter_scriptable_default_init (ClutterScriptableInterface *iface)
|
|
|
|
{
|
2007-10-25 10:34:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-14 06:32:24 -05:00
|
|
|
* clutter_scriptable_set_id:
|
2007-10-25 10:34:54 -04:00
|
|
|
* @scriptable: a #ClutterScriptable
|
2011-02-15 06:50:26 -05:00
|
|
|
* @id_: the #ClutterScript id of the object
|
2007-10-25 10:34:54 -04:00
|
|
|
*
|
2011-02-15 06:50:26 -05:00
|
|
|
* Sets @id_ as the unique Clutter script it for this instance of
|
2007-11-14 06:32:24 -05:00
|
|
|
* #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 #ClutterScript.
|
2007-10-25 10:34:54 -04:00
|
|
|
*
|
2015-01-03 15:34:20 -05:00
|
|
|
* Since: 0.6
|
2007-10-25 10:34:54 -04:00
|
|
|
*/
|
|
|
|
void
|
2007-11-14 06:32:24 -05:00
|
|
|
clutter_scriptable_set_id (ClutterScriptable *scriptable,
|
2011-02-15 06:50:26 -05:00
|
|
|
const gchar *id_)
|
2007-10-25 10:34:54 -04:00
|
|
|
{
|
|
|
|
ClutterScriptableIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable));
|
2011-02-15 06:50:26 -05:00
|
|
|
g_return_if_fail (id_ != NULL);
|
2007-10-25 10:34:54 -04:00
|
|
|
|
|
|
|
iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
|
2007-11-14 06:32:24 -05:00
|
|
|
if (iface->set_id)
|
2011-02-15 06:50:26 -05:00
|
|
|
iface->set_id (scriptable, id_);
|
2007-10-25 10:34:54 -04:00
|
|
|
else
|
|
|
|
g_object_set_data_full (G_OBJECT (scriptable),
|
2007-11-14 06:32:24 -05:00
|
|
|
"clutter-script-id",
|
2011-02-15 06:50:26 -05:00
|
|
|
g_strdup (id_),
|
2007-10-25 10:34:54 -04:00
|
|
|
g_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-14 06:32:24 -05:00
|
|
|
* clutter_scriptable_get_id:
|
2007-10-25 10:34:54 -04:00
|
|
|
* @scriptable: a #ClutterScriptable
|
|
|
|
*
|
2007-11-14 06:32:24 -05:00
|
|
|
* Retrieves the id of @scriptable set using clutter_scriptable_set_id().
|
2007-10-25 10:34:54 -04:00
|
|
|
*
|
2007-11-14 06:32:24 -05:00
|
|
|
* Return value: the id of the object. The returned string is owned by
|
2007-10-25 10:34:54 -04:00
|
|
|
* the scriptable object and should never be modified of freed
|
|
|
|
*
|
2015-01-03 15:34:20 -05:00
|
|
|
* Since: 0.6
|
2007-10-25 10:34:54 -04:00
|
|
|
*/
|
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_scriptable_get_id (ClutterScriptable *scriptable)
|
2007-10-25 10:34:54 -04:00
|
|
|
{
|
|
|
|
ClutterScriptableIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), NULL);
|
|
|
|
|
|
|
|
iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
|
2007-11-14 06:32:24 -05:00
|
|
|
if (iface->get_id)
|
|
|
|
return iface->get_id (scriptable);
|
2007-10-25 10:34:54 -04:00
|
|
|
else
|
2007-11-14 06:32:24 -05:00
|
|
|
return g_object_get_data (G_OBJECT (scriptable), "clutter-script-id");
|
2007-10-25 10:34:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 #GValue pointer using g_value_init().
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the node was successfully parsed, %FALSE otherwise.
|
|
|
|
*
|
2015-01-03 15:34:20 -05:00
|
|
|
* Since: 0.6
|
2007-10-25 10:34:54 -04:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2015-01-03 15:34:20 -05:00
|
|
|
* Since: 0.6
|
2007-10-25 10:34:54 -04:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|