2010-08-31 12:42:37 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2010-09-01 05:21:23 -04:00
|
|
|
#define UI_FILE "animations-reuse-ui.json"
|
|
|
|
#define ANIMATION_FILE "animations-reuse-animation.json"
|
|
|
|
|
|
|
|
static gboolean
|
2010-09-01 06:18:15 -04:00
|
|
|
load_script_from_file (ClutterScript *script,
|
|
|
|
gchar *filename)
|
2010-09-01 05:21:23 -04:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
clutter_script_load_from_file (script, filename, &error);
|
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
g_critical ("Error loading ClutterScript file %s\n%s", filename, error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-31 12:42:37 -04:00
|
|
|
gboolean
|
|
|
|
foo_button_pressed_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2010-09-01 05:21:23 -04:00
|
|
|
ClutterScript *ui = CLUTTER_SCRIPT (user_data);
|
|
|
|
ClutterStage *stage = CLUTTER_STAGE (clutter_script_get_object (ui, "stage"));
|
|
|
|
|
2010-09-01 06:18:15 -04:00
|
|
|
ClutterScript *script;
|
|
|
|
ClutterActor *rig;
|
2010-09-09 07:02:02 -04:00
|
|
|
ClutterAnimator *animator;
|
2010-09-01 05:21:23 -04:00
|
|
|
|
2010-09-09 07:02:02 -04:00
|
|
|
/* load the rig and its animator from a JSON file */
|
2010-09-01 06:18:15 -04:00
|
|
|
script = clutter_script_new ();
|
2010-08-31 12:42:37 -04:00
|
|
|
|
2010-09-09 07:02:02 -04:00
|
|
|
/* use a function defined statically in this source file to load the JSON */
|
2010-09-01 06:18:15 -04:00
|
|
|
load_script_from_file (script, ANIMATION_FILE);
|
2010-08-31 12:42:37 -04:00
|
|
|
|
|
|
|
clutter_script_get_objects (script,
|
|
|
|
"rig", &rig,
|
2010-09-09 07:02:02 -04:00
|
|
|
"animator", &animator,
|
2010-08-31 12:42:37 -04:00
|
|
|
NULL);
|
|
|
|
|
2010-09-09 07:02:02 -04:00
|
|
|
/* remove the button press handler from the rectangle */
|
2011-09-02 06:01:36 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (actor,
|
|
|
|
G_CALLBACK (foo_button_pressed_cb),
|
2010-08-31 12:42:37 -04:00
|
|
|
NULL);
|
|
|
|
|
2010-09-01 06:18:15 -04:00
|
|
|
/* add a callback to clean up the script when the rig is destroyed */
|
|
|
|
g_object_set_data_full (G_OBJECT (rig), "script", script, g_object_unref);
|
2010-08-31 12:42:37 -04:00
|
|
|
|
2010-09-09 07:02:02 -04:00
|
|
|
/* add the rig to the stage */
|
2010-09-01 05:21:23 -04:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig);
|
2010-08-31 12:42:37 -04:00
|
|
|
|
2010-09-09 07:02:02 -04:00
|
|
|
/* place the rig at the same coordinates on the stage as the rectangle */
|
|
|
|
clutter_actor_set_position (rig,
|
|
|
|
clutter_actor_get_x (actor),
|
|
|
|
clutter_actor_get_y (actor));
|
|
|
|
|
|
|
|
/* put the rectangle into the top-left corner of the rig */
|
2010-09-01 05:21:23 -04:00
|
|
|
clutter_actor_reparent (actor, rig);
|
2010-08-31 12:42:37 -04:00
|
|
|
|
2010-09-09 07:02:02 -04:00
|
|
|
clutter_actor_set_position (actor, 0, 0);
|
|
|
|
|
|
|
|
/* animate the rig */
|
|
|
|
clutter_animator_start (animator);
|
2010-09-01 05:21:23 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2010-08-31 12:42:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2010-09-01 06:18:15 -04:00
|
|
|
ClutterScript *script;
|
|
|
|
ClutterActor *stage;
|
|
|
|
|
2011-02-21 19:44:55 -05:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2010-08-31 12:42:37 -04:00
|
|
|
|
2010-09-01 06:18:15 -04:00
|
|
|
script = clutter_script_new ();
|
|
|
|
load_script_from_file (script, UI_FILE);
|
2010-08-31 12:42:37 -04:00
|
|
|
|
|
|
|
clutter_script_connect_signals (script, script);
|
|
|
|
|
|
|
|
clutter_script_get_objects (script,
|
|
|
|
"stage", &stage,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
g_object_unref (script);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|