2007-10-25 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/Makefile.am: * clutter/clutter.h: * clutter/clutter-scriptable.[ch]: Add the ClutterScriptable interface; by implementing this interface, a class can override the UI definition parsing and transform complex data types into GObject properties, or allow custom properties. * clutter/clutter-script.c: * clutter/clutter-script-parser.c: * clutter/clutter-script-private.h: Rearrange the code and use the ClutterScriptable interface to parse and build the custom properties. This cleans up the code and also it makes it more reliable (the complex type parsing is now done using the target type and not just the name of the property).
This commit is contained in:
parent
9c38eead46
commit
6c01499abf
8 changed files with 1520 additions and 823 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2007-10-25 Emmanuele Bassi <ebassi@openedhand.com>
|
||||
|
||||
* clutter/Makefile.am:
|
||||
* clutter/clutter.h:
|
||||
* clutter/clutter-scriptable.[ch]: Add the ClutterScriptable
|
||||
interface; by implementing this interface, a class can
|
||||
override the UI definition parsing and transform complex data
|
||||
types into GObject properties, or allow custom properties.
|
||||
|
||||
* clutter/clutter-script.c:
|
||||
* clutter/clutter-script-parser.c:
|
||||
* clutter/clutter-script-private.h: Rearrange the code and
|
||||
use the ClutterScriptable interface to parse and build the
|
||||
custom properties. This cleans up the code and also it makes
|
||||
it more reliable (the complex type parsing is now done using
|
||||
the target type and not just the name of the property).
|
||||
|
||||
2007-10-25 Emmanuele Bassi <ebassi@openedhand.com>
|
||||
|
||||
* clutter/clutter-json.h: Header for including the JSON
|
||||
|
|
|
@ -23,6 +23,7 @@ INCLUDES = \
|
|||
-DDATADIR=\""$(datadir)"\" \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DG_LOG_DOMAIN=\"Clutter\" \
|
||||
-DCLUTTER_JSON_API=1 \
|
||||
$(GCC_FLAGS) \
|
||||
$(CLUTTER_CFLAGS) \
|
||||
$(CLUTTER_DEBUG_CFLAGS) \
|
||||
|
@ -66,11 +67,12 @@ source_h = \
|
|||
$(srcdir)/clutter-main.h \
|
||||
$(srcdir)/clutter-media.h \
|
||||
$(srcdir)/clutter-rectangle.h \
|
||||
$(srcdir)/clutter-score.h \
|
||||
$(srcdir)/clutter-script.h \
|
||||
$(srcdir)/clutter-scriptable.h \
|
||||
$(srcdir)/clutter-stage.h \
|
||||
$(srcdir)/clutter-texture.h \
|
||||
$(srcdir)/clutter-timeline.h \
|
||||
$(srcdir)/clutter-score.h \
|
||||
$(srcdir)/clutter-timeout-pool.h \
|
||||
$(srcdir)/clutter-types.h \
|
||||
$(srcdir)/clutter-units.h \
|
||||
|
@ -150,12 +152,14 @@ source_c = \
|
|||
clutter-main.c \
|
||||
clutter-marshal.c \
|
||||
clutter-media.c \
|
||||
clutter-stage.c \
|
||||
clutter-rectangle.c \
|
||||
clutter-texture.c \
|
||||
clutter-timeline.c \
|
||||
clutter-score.c \
|
||||
clutter-script.c \
|
||||
clutter-script-parser.c \
|
||||
clutter-scriptable.c \
|
||||
clutter-stage.c \
|
||||
clutter-texture.c \
|
||||
clutter-timeline.c \
|
||||
clutter-timeout-pool.c \
|
||||
clutter-util.c \
|
||||
clutter-vbox.c \
|
||||
|
@ -189,6 +193,7 @@ clutterdir = $(includedir)/clutter-@CLUTTER_API_VERSION@/clutter
|
|||
|
||||
clutter_HEADERS = \
|
||||
$(source_h) \
|
||||
clutter-json.h \
|
||||
clutter-enum-types.h \
|
||||
clutter-version.h \
|
||||
clutter.h
|
||||
|
|
466
clutter/clutter-script-parser.c
Normal file
466
clutter/clutter-script-parser.c
Normal file
|
@ -0,0 +1,466 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "clutter-actor.h"
|
||||
#include "clutter-behaviour.h"
|
||||
#include "clutter-container.h"
|
||||
|
||||
#include "clutter-script.h"
|
||||
#include "clutter-script-private.h"
|
||||
#include "clutter-scriptable.h"
|
||||
|
||||
#include "clutter-debug.h"
|
||||
#include "clutter-private.h"
|
||||
|
||||
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;
|
||||
GTypeGetFunc func;
|
||||
GString *symbol_name = g_string_new ("");
|
||||
char c, *symbol;
|
||||
int i;
|
||||
GType gtype = G_TYPE_INVALID;
|
||||
|
||||
if (!module)
|
||||
module = g_module_open (NULL, 0);
|
||||
|
||||
for (i = 0; name[i] != '\0'; i++)
|
||||
{
|
||||
c = name[i];
|
||||
/* skip if uppercase, first or previous is uppercase */
|
||||
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))
|
||||
gtype = func ();
|
||||
|
||||
g_free (symbol);
|
||||
|
||||
return gtype;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
GFlagsClass *fclass;
|
||||
gchar *endptr, *prevptr;
|
||||
guint i, j, ret, value;
|
||||
gchar *flagstr;
|
||||
GFlagsValue *fv;
|
||||
const gchar *flag;
|
||||
gunichar ch;
|
||||
gboolean eos;
|
||||
|
||||
g_return_val_if_fail (G_TYPE_IS_FLAGS (type), 0);
|
||||
g_return_val_if_fail (string != 0, 0);
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
value = strtoul (string, &endptr, 0);
|
||||
if (endptr != string) /* parsed a number */
|
||||
*flags_value = value;
|
||||
else
|
||||
{
|
||||
fclass = g_type_class_ref (type);
|
||||
|
||||
flagstr = g_strdup (string);
|
||||
for (value = i = j = 0; ; i++)
|
||||
{
|
||||
|
||||
eos = flagstr[i] == '\0';
|
||||
|
||||
if (!eos && flagstr[i] != '|')
|
||||
continue;
|
||||
|
||||
flag = &flagstr[j];
|
||||
endptr = &flagstr[i];
|
||||
|
||||
if (!eos)
|
||||
{
|
||||
flagstr[i++] = '\0';
|
||||
j = i;
|
||||
}
|
||||
|
||||
/* trim spaces */
|
||||
for (;;)
|
||||
{
|
||||
ch = g_utf8_get_char (flag);
|
||||
if (!g_unichar_isspace (ch))
|
||||
break;
|
||||
flag = g_utf8_next_char (flag);
|
||||
}
|
||||
|
||||
while (endptr > flag)
|
||||
{
|
||||
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)
|
||||
{
|
||||
JsonNode *val;
|
||||
|
||||
if (json_array_get_length (array) < 2)
|
||||
return FALSE;
|
||||
|
||||
val = json_array_get_element (array, 0);
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
knot->x = json_node_get_int (val);
|
||||
|
||||
val = json_array_get_element (array, 1);
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
knot->y = json_node_get_int (val);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_knot_from_object (JsonObject *object,
|
||||
ClutterKnot *knot)
|
||||
{
|
||||
JsonNode *val;
|
||||
|
||||
if (json_object_get_size (object) < 2)
|
||||
return FALSE;
|
||||
|
||||
val = json_object_get_member (object, "x");
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
knot->x = json_node_get_int (val);
|
||||
|
||||
val = json_object_get_member (object, "y");
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
knot->y = json_node_get_int (val);
|
||||
|
||||
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 ClutterUnit
|
||||
get_units_from_node (JsonNode *node)
|
||||
{
|
||||
ClutterUnit retval = 0;
|
||||
GValue value = { 0, };
|
||||
|
||||
if (JSON_NODE_TYPE (node) != JSON_NODE_VALUE)
|
||||
return 0;
|
||||
|
||||
json_node_get_value (node, &value);
|
||||
switch (G_VALUE_TYPE (&value))
|
||||
{
|
||||
case G_TYPE_INT:
|
||||
retval = CLUTTER_UNITS_FROM_INT (g_value_get_int (&value));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gboolean
|
||||
clutter_script_parse_padding (ClutterScript *script,
|
||||
JsonNode *node,
|
||||
ClutterPadding *padding)
|
||||
{
|
||||
JsonArray *array;
|
||||
gint array_len, i;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
|
||||
g_return_val_if_fail (node != NULL, FALSE);
|
||||
g_return_val_if_fail (padding != NULL, FALSE);
|
||||
|
||||
if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY)
|
||||
return FALSE;
|
||||
|
||||
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);
|
||||
ClutterUnit units = get_units_from_node (val);
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
padding->top = units;
|
||||
padding->right = padding->top;
|
||||
padding->bottom = padding->top;
|
||||
padding->left = padding->top;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
padding->right = padding->left = units;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
padding->bottom = units;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
padding->left = units;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
clutter_script_parse_margin (ClutterScript *script,
|
||||
JsonNode *node,
|
||||
ClutterMargin *margin)
|
||||
{
|
||||
JsonArray *array;
|
||||
gint array_len, i;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
|
||||
g_return_val_if_fail (node != NULL, FALSE);
|
||||
g_return_val_if_fail (margin != NULL, FALSE);
|
||||
|
||||
if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY)
|
||||
return FALSE;
|
||||
|
||||
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);
|
||||
ClutterUnit units = get_units_from_node (val);
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
margin->top = units;
|
||||
margin->right = margin->top;
|
||||
margin->bottom = margin->top;
|
||||
margin->left = margin->top;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
margin->right = margin->left = units;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
margin->bottom = units;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
margin->left = units;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_geometry_from_array (JsonArray *array,
|
||||
ClutterGeometry *geometry)
|
||||
{
|
||||
JsonNode *val;
|
||||
|
||||
if (json_array_get_length (array) < 4)
|
||||
return FALSE;
|
||||
|
||||
val = json_array_get_element (array, 0);
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->x = json_node_get_int (val);
|
||||
|
||||
val = json_array_get_element (array, 1);
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->y = json_node_get_int (val);
|
||||
|
||||
val = json_array_get_element (array, 2);
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->width = json_node_get_int (val);
|
||||
|
||||
val = json_array_get_element (array, 3);
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->height = json_node_get_int (val);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_geometry_from_object (JsonObject *object,
|
||||
ClutterGeometry *geometry)
|
||||
{
|
||||
JsonNode *val;
|
||||
|
||||
if (json_object_get_size (object) < 4)
|
||||
return FALSE;
|
||||
|
||||
val = json_object_get_member (object, "x");
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->x = json_node_get_int (val);
|
||||
|
||||
val = json_object_get_member (object, "y");
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->y = json_node_get_int (val);
|
||||
|
||||
val = json_object_get_member (object, "width");
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->width = json_node_get_int (val);
|
||||
|
||||
val = json_object_get_member (object, "height");
|
||||
if (JSON_NODE_TYPE (val) == JSON_NODE_VALUE)
|
||||
geometry->height = json_node_get_int (val);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
clutter_script_parse_geometry (ClutterScript *script,
|
||||
JsonNode *node,
|
||||
ClutterGeometry *geometry)
|
||||
{
|
||||
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
|
||||
g_return_val_if_fail (node != NULL, FALSE);
|
||||
g_return_val_if_fail (geometry != NULL, FALSE);
|
||||
|
||||
switch (JSON_NODE_TYPE (node))
|
||||
{
|
||||
case JSON_NODE_ARRAY:
|
||||
return parse_geometry_from_array (json_node_get_array (node), geometry);
|
||||
|
||||
case JSON_NODE_OBJECT:
|
||||
return parse_geometry_from_object (json_node_get_object (node), geometry);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
|
@ -27,6 +27,8 @@
|
|||
#define __CLUTTER_SCRIPT_PRIVATE_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "json/json-types.h"
|
||||
#include "clutter-types.h"
|
||||
#include "clutter-script.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
@ -52,11 +54,25 @@ typedef struct {
|
|||
guint is_unmerged : 1;
|
||||
} ObjectInfo;
|
||||
|
||||
void object_info_free (gpointer data);
|
||||
|
||||
typedef struct {
|
||||
gchar *property_name;
|
||||
GValue value;
|
||||
gchar *name;
|
||||
JsonNode *node;
|
||||
GParamSpec *pspec;
|
||||
} PropertyInfo;
|
||||
|
||||
void property_info_free (gpointer data);
|
||||
|
||||
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);
|
||||
|
||||
GObject *clutter_script_construct_object (ClutterScript *script,
|
||||
ObjectInfo *info);
|
||||
|
||||
|
@ -67,6 +83,21 @@ 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_padding (ClutterScript *script,
|
||||
JsonNode *node,
|
||||
ClutterPadding *padding);
|
||||
gboolean clutter_script_parse_margin (ClutterScript *script,
|
||||
JsonNode *node,
|
||||
ClutterMargin *margin);
|
||||
gboolean clutter_script_parse_geometry (ClutterScript *script,
|
||||
JsonNode *node,
|
||||
ClutterGeometry *geometry);
|
||||
GObject *clutter_script_parse_alpha (ClutterScript *script,
|
||||
JsonNode *node);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_SCRIPT_PRIVATE_H__ */
|
||||
|
|
File diff suppressed because it is too large
Load diff
186
clutter/clutter-scriptable.c
Normal file
186
clutter/clutter-scriptable.c
Normal file
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* 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
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#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"
|
||||
|
||||
GType
|
||||
clutter_scriptable_get_type (void)
|
||||
{
|
||||
static GType scriptable_type = 0;
|
||||
|
||||
if (!scriptable_type)
|
||||
scriptable_type =
|
||||
g_type_register_static_simple (G_TYPE_INTERFACE, "ClutterScriptable",
|
||||
sizeof (ClutterScriptableIface),
|
||||
NULL, 0, NULL, 0);
|
||||
|
||||
return scriptable_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_scriptable_set_name:
|
||||
* @scriptable: a #ClutterScriptable
|
||||
* @name: the name of the object
|
||||
*
|
||||
* Sets @name as the name for this instance of #ClutterScriptableIface.
|
||||
* This name can be used by user interface designer applications.
|
||||
*
|
||||
* Since: 0.6
|
||||
*/
|
||||
void
|
||||
clutter_scriptable_set_name (ClutterScriptable *scriptable,
|
||||
const gchar *name)
|
||||
{
|
||||
ClutterScriptableIface *iface;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable));
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
|
||||
if (iface->set_name)
|
||||
iface->set_name (scriptable, name);
|
||||
else
|
||||
g_object_set_data_full (G_OBJECT (scriptable),
|
||||
"clutter-script-name",
|
||||
g_strdup (name),
|
||||
g_free);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_scriptable_get_name:
|
||||
* @scriptable: a #ClutterScriptable
|
||||
*
|
||||
* Retrieves the name of @scriptable set using clutter_scriptable_set_name().
|
||||
*
|
||||
* Return value: the name of the object. The returned string is owned by
|
||||
* the scriptable object and should never be modified of freed
|
||||
*
|
||||
* Since: 0.6
|
||||
*/
|
||||
G_CONST_RETURN gchar *
|
||||
clutter_scriptable_get_name (ClutterScriptable *scriptable)
|
||||
{
|
||||
ClutterScriptableIface *iface;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), NULL);
|
||||
|
||||
iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
|
||||
if (iface->get_name)
|
||||
return iface->get_name (scriptable);
|
||||
else
|
||||
return g_object_get_data (G_OBJECT (scriptable), "clutter-script-name");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Since: 0.6
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* Since: 0.6
|
||||
*/
|
||||
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);
|
||||
}
|
94
clutter/clutter-scriptable.h
Normal file
94
clutter/clutter-scriptable.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __CLUTTER_SCRIPTABLE_H__
|
||||
#define __CLUTTER_SCRIPTABLE_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <clutter/clutter-script.h>
|
||||
#include <clutter/clutter-json.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_name: virtual function for setting the name of a scriptable object
|
||||
* @get_name: virtual function for getting the name 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
|
||||
*
|
||||
* Since: 0.6
|
||||
*/
|
||||
struct _ClutterScriptableIface
|
||||
{
|
||||
GTypeInterface g_iface;
|
||||
|
||||
void (* set_name) (ClutterScriptable *scriptable,
|
||||
const gchar *name);
|
||||
const gchar *(* get_name) (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);
|
||||
};
|
||||
|
||||
GType clutter_scriptable_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void clutter_scriptable_set_name (ClutterScriptable *scriptable,
|
||||
const gchar *name);
|
||||
G_CONST_RETURN gchar *clutter_scriptable_get_name (ClutterScriptable *scriptable);
|
||||
gboolean clutter_scriptable_parse_custom_node (ClutterScriptable *scriptable,
|
||||
ClutterScript *script,
|
||||
GValue *value,
|
||||
const gchar *name,
|
||||
JsonNode *node);
|
||||
void clutter_scriptable_set_custom_property (ClutterScriptable *scriptable,
|
||||
ClutterScript *script,
|
||||
const gchar *name,
|
||||
const GValue *value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_SCRIPTABLE_H__ */
|
|
@ -59,6 +59,7 @@
|
|||
#include "clutter-timeline.h"
|
||||
#include "clutter-score.h"
|
||||
#include "clutter-script.h"
|
||||
#include "clutter-scriptable.h"
|
||||
#include "clutter-types.h"
|
||||
#include "clutter-units.h"
|
||||
#include "clutter-util.h"
|
||||
|
|
Loading…
Reference in a new issue