2007-10-27 Emmanuele Bassi <ebassi@openedhand.com>

* clutter/clutter-script.[ch]: Slight API change in the
	clutter_script_get_objects() function: now it takes
	object name/object return location pairs and returns the
	number of objects found and returned.

	* tests/test-script.c: Exercise the clutter_script_get_objects()
	function.
This commit is contained in:
Emmanuele Bassi 2007-10-27 19:08:59 +00:00
parent ae7463cccf
commit 35132fb5de
4 changed files with 52 additions and 18 deletions

View File

@ -1,3 +1,13 @@
2007-10-27 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-script.[ch]: Slight API change in the
clutter_script_get_objects() function: now it takes
object name/object return location pairs and returns the
number of objects found and returned.
* tests/test-script.c: Exercise the clutter_script_get_objects()
function.
2007-10-27 Emmanuele Bassi <ebassi@openedhand.com> 2007-10-27 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-rectangle.c (clutter_rectangle_paint): Use * clutter/clutter-rectangle.c (clutter_rectangle_paint): Use

View File

@ -1446,50 +1446,69 @@ clutter_script_get_object (ClutterScript *script,
return clutter_script_construct_object (script, oinfo); return clutter_script_construct_object (script, oinfo);
} }
static GList * static gint
clutter_script_get_objects_valist (ClutterScript *script, clutter_script_get_objects_valist (ClutterScript *script,
const gchar *first_name, const gchar *first_name,
va_list args) va_list args)
{ {
GList *retval = NULL; gint retval = 0;
const gchar *name; const gchar *name;
name = first_name; name = first_name;
while (name) while (name)
{ {
retval = GObject **obj = NULL;
g_list_prepend (retval, clutter_script_get_object (script, name));
obj = va_arg (args, GObject**);
*obj = clutter_script_get_object (script, name);
if (*obj)
retval += 1;
name = va_arg (args, gchar*); name = va_arg (args, gchar*);
} }
return g_list_reverse (retval); return retval;
} }
/** /**
* clutter_script_get_objects: * clutter_script_get_objects:
* @script: a #ClutterScript * @script: a #ClutterScript
* @first_name: the name of the first object to retrieve * @first_name: the name of the first object to retrieve
* @Varargs: a %NULL-terminated list of names * @Varargs: return location for a #GObject, then additional names, ending
* with %NULL
* *
* Retrieves a list of objects for the given names. This function does * Retrieves a list of objects for the given names. After @script, object
* not increment the reference count of the returned objects. * names/return location pairs should be listed, with a %NULL pointer
* ending the list, like:
* *
* Return value: a newly allocated #GList containing the found objects, * <informalexample><programlisting>
* or %NULL. Use g_list_free() when done using it. * GObject *my_label, *a_button, *main_timeline;
*
* clutter_script_get_objects (script,
* "my-label", &amp;my_label,
* "a-button", &amp;a_button,
* "main-timeline", &amp;main_timeline,
* NULL);
* </programlisting</informalexample>
*
* Note: This function does not increment the reference count of the
* returned objects.
*
* Return value: the number of objects returned.
* *
* Since: 0.6 * Since: 0.6
*/ */
GList * gint
clutter_script_get_objects (ClutterScript *script, clutter_script_get_objects (ClutterScript *script,
const gchar *first_name, const gchar *first_name,
...) ...)
{ {
GList *retval = NULL; gint retval;
va_list var_args; va_list var_args;
g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), NULL); g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), 0);
g_return_val_if_fail (first_name != NULL, NULL); g_return_val_if_fail (first_name != NULL, 0);
va_start (var_args, first_name); va_start (var_args, first_name);
retval = clutter_script_get_objects_valist (script, first_name, var_args); retval = clutter_script_get_objects_valist (script, first_name, var_args);

View File

@ -99,7 +99,7 @@ guint clutter_script_load_from_data (ClutterScript *script,
GError **error); GError **error);
GObject * clutter_script_get_object (ClutterScript *script, GObject * clutter_script_get_object (ClutterScript *script,
const gchar *name); const gchar *name);
GList * clutter_script_get_objects (ClutterScript *script, gint clutter_script_get_objects (ClutterScript *script,
const gchar *first_name, const gchar *first_name,
...) G_GNUC_NULL_TERMINATED; ...) G_GNUC_NULL_TERMINATED;
void clutter_script_unmerge_objects (ClutterScript *script, void clutter_script_unmerge_objects (ClutterScript *script,

View File

@ -96,6 +96,7 @@ main (int argc, char *argv[])
{ {
GObject *stage, *timeline, *blue_button, *red_button; GObject *stage, *timeline, *blue_button, *red_button;
GError *error = NULL; GError *error = NULL;
gint res;
clutter_init (&argc, &argv); clutter_init (&argc, &argv);
@ -132,16 +133,20 @@ main (int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
stage = clutter_script_get_object (script, "main-stage"); res = clutter_script_get_objects (script,
"main-stage", &stage,
"red-button", &red_button,
"blue-button", &blue_button,
NULL);
g_assert (res == 3);
clutter_actor_show (CLUTTER_ACTOR (stage)); clutter_actor_show (CLUTTER_ACTOR (stage));
red_button = clutter_script_get_object (script, "red-button");
g_signal_connect (red_button, g_signal_connect (red_button,
"button-press-event", "button-press-event",
G_CALLBACK (red_button_press), G_CALLBACK (red_button_press),
NULL); NULL);
blue_button = clutter_script_get_object (script, "blue-button");
g_signal_connect (blue_button, g_signal_connect (blue_button,
"button-press-event", "button-press-event",
G_CALLBACK (blue_button_press), G_CALLBACK (blue_button_press),