mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 17:40:40 -05:00
cookbook: Cleaned up the "animations reuse" example
With some help from pippin, moved variable declarations into more sensible positions within their functions, changed a function name, and found a better way to unref a script once its associated actor has been destroyed.
This commit is contained in:
parent
d4190cbf8c
commit
d7a3e35f46
@ -9,7 +9,6 @@
|
|||||||
"id" : "bounce",
|
"id" : "bounce",
|
||||||
"timeline" : {
|
"timeline" : {
|
||||||
"type" : "ClutterTimeline",
|
"type" : "ClutterTimeline",
|
||||||
"id" : "bounce_timeline",
|
|
||||||
"duration" : 2500
|
"duration" : 2500
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#define ANIMATION_FILE "animations-reuse-animation.json"
|
#define ANIMATION_FILE "animations-reuse-animation.json"
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_load_script (ClutterScript *script,
|
load_script_from_file (ClutterScript *script,
|
||||||
gchar *filename)
|
gchar *filename)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
@ -30,16 +30,15 @@ foo_button_pressed_cb (ClutterActor *actor,
|
|||||||
ClutterScript *ui = CLUTTER_SCRIPT (user_data);
|
ClutterScript *ui = CLUTTER_SCRIPT (user_data);
|
||||||
ClutterStage *stage = CLUTTER_STAGE (clutter_script_get_object (ui, "stage"));
|
ClutterStage *stage = CLUTTER_STAGE (clutter_script_get_object (ui, "stage"));
|
||||||
|
|
||||||
ClutterScript *script = clutter_script_new ();
|
ClutterScript *script;
|
||||||
|
|
||||||
_load_script (script, ANIMATION_FILE);
|
|
||||||
|
|
||||||
ClutterAnimator *bounce;
|
|
||||||
ClutterActor *rig;
|
ClutterActor *rig;
|
||||||
ClutterTimeline *bounce_timeline;
|
ClutterAnimator *bounce;
|
||||||
|
|
||||||
|
script = clutter_script_new ();
|
||||||
|
|
||||||
|
load_script_from_file (script, ANIMATION_FILE);
|
||||||
|
|
||||||
clutter_script_get_objects (script,
|
clutter_script_get_objects (script,
|
||||||
"bounce_timeline", &bounce_timeline,
|
|
||||||
"rig", &rig,
|
"rig", &rig,
|
||||||
"bounce", &bounce,
|
"bounce", &bounce,
|
||||||
NULL);
|
NULL);
|
||||||
@ -53,11 +52,8 @@ foo_button_pressed_cb (ClutterActor *actor,
|
|||||||
foo_button_pressed_cb,
|
foo_button_pressed_cb,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* add a handler to clean up when the animation completes */
|
/* add a callback to clean up the script when the rig is destroyed */
|
||||||
g_signal_connect_swapped (bounce_timeline,
|
g_object_set_data_full (G_OBJECT (rig), "script", script, g_object_unref);
|
||||||
"completed",
|
|
||||||
G_CALLBACK (g_object_unref),
|
|
||||||
script);
|
|
||||||
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig);
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig);
|
||||||
|
|
||||||
@ -71,14 +67,16 @@ foo_button_pressed_cb (ClutterActor *actor,
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
ClutterScript *script;
|
||||||
|
ClutterActor *stage;
|
||||||
|
|
||||||
clutter_init (&argc, &argv);
|
clutter_init (&argc, &argv);
|
||||||
|
|
||||||
ClutterScript *script = clutter_script_new ();
|
script = clutter_script_new ();
|
||||||
_load_script (script, UI_FILE);
|
load_script_from_file (script, UI_FILE);
|
||||||
|
|
||||||
clutter_script_connect_signals (script, script);
|
clutter_script_connect_signals (script, script);
|
||||||
|
|
||||||
ClutterActor *stage;
|
|
||||||
clutter_script_get_objects (script,
|
clutter_script_get_objects (script,
|
||||||
"stage", &stage,
|
"stage", &stage,
|
||||||
NULL);
|
NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user