mirror of
https://github.com/brl/mutter.git
synced 2024-11-12 17:27:03 -05:00
cookbook: Added complex animations example
To support recipe about using ClutterAnimator to create complex animations.
This commit is contained in:
parent
9210c46730
commit
c0aa72a042
@ -3,6 +3,7 @@ include $(top_srcdir)/build/autotools/Makefile.am.silent
|
||||
NULL =
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
animations-complex \
|
||||
animations-rotating \
|
||||
text-shadow \
|
||||
textures-reflection \
|
||||
@ -41,6 +42,7 @@ AM_CFLAGS = \
|
||||
|
||||
AM_LDFLAGS = $(CLUTTER_LIBS) -export-dynamic
|
||||
|
||||
animations_complex_SOURCES = animations-complex.c
|
||||
animations_rotating_SOURCES = animations-rotating.c
|
||||
text_shadow_SOURCES = text-shadow.c
|
||||
textures_reflection_SOURCES = textures-reflection.c
|
||||
|
64
doc/cookbook/examples/animations-complex.c
Normal file
64
doc/cookbook/examples/animations-complex.c
Normal file
@ -0,0 +1,64 @@
|
||||
#include <stdlib.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define UI_FILE "animations-complex.json"
|
||||
|
||||
/*
|
||||
* start the animation when a key is pressed;
|
||||
* see the signals recipe in the Script chapter for more details
|
||||
*/
|
||||
gboolean
|
||||
foo_key_pressed_cb (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
ClutterScript *script = CLUTTER_SCRIPT (user_data);
|
||||
|
||||
ClutterAnimator *animator;
|
||||
clutter_script_get_objects (script,
|
||||
"animator", &animator,
|
||||
NULL);
|
||||
|
||||
if (clutter_timeline_is_playing (clutter_animator_get_timeline (animator)))
|
||||
return FALSE;
|
||||
|
||||
clutter_animator_start (animator);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
ClutterScript *script;
|
||||
ClutterActor *stage;
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
script = clutter_script_new ();
|
||||
clutter_script_load_from_file (script, UI_FILE, &error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
g_critical ("Error loading ClutterScript file %s\n%s", UI_FILE, error->message);
|
||||
g_error_free (error);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* connect signal handlers as defined in the script */
|
||||
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;
|
||||
}
|
80
doc/cookbook/examples/animations-complex.json
Normal file
80
doc/cookbook/examples/animations-complex.json
Normal file
@ -0,0 +1,80 @@
|
||||
[
|
||||
{
|
||||
"type" : "ClutterStage",
|
||||
"id" : "stage",
|
||||
"width" : 400,
|
||||
"height" : 400,
|
||||
"color" : "#333355ff",
|
||||
|
||||
"signals" : [
|
||||
{ "name" : "destroy", "handler" : "clutter_main_quit" },
|
||||
{ "name" : "key-press-event", "handler" : "foo_key_pressed_cb" }
|
||||
],
|
||||
|
||||
"children" : [
|
||||
{
|
||||
"type" : "ClutterRectangle",
|
||||
"id" : "rectangle",
|
||||
"color" : "red",
|
||||
"width" : 100,
|
||||
"height" : 100,
|
||||
"x" : 0,
|
||||
"y" : 0,
|
||||
"scale-gravity" : "center"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"type" : "ClutterAnimator",
|
||||
"id" : "animator",
|
||||
"duration" : 3000,
|
||||
|
||||
"properties" : [
|
||||
{
|
||||
"object" : "rectangle",
|
||||
"name" : "x",
|
||||
"ease-in" : true,
|
||||
"keys" : [
|
||||
[ 0.0, "linear", 0.0 ],
|
||||
[ 0.1, "easeInCubic", 150.0 ],
|
||||
[ 0.8, "linear", 150.0 ],
|
||||
[ 1.0, "easeInCubic", 0.0 ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"object" : "rectangle",
|
||||
"name" : "y",
|
||||
"ease-in" : true,
|
||||
"keys" : [
|
||||
[ 0.0, "linear", 0.0 ],
|
||||
[ 0.1, "easeInCubic", 150.0 ],
|
||||
[ 0.8, "linear", 150.0 ],
|
||||
[ 1.0, "easeInCubic", 300.0 ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"object" : "rectangle",
|
||||
"name" : "scale-x",
|
||||
"ease-in" : true,
|
||||
"keys" : [
|
||||
[ 0.1, "linear", 1.0 ],
|
||||
[ 0.3, "easeOutBounce", 2.0 ],
|
||||
[ 0.8, "linear", 2.0 ],
|
||||
[ 1.0, "linear", 1.0 ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"object" : "rectangle",
|
||||
"name" : "scale-y",
|
||||
"ease-in" : true,
|
||||
"keys" : [
|
||||
[ 0.1, "linear", 1.0 ],
|
||||
[ 0.3, "easeOutBounce", 2.0 ],
|
||||
[ 0.8, "linear", 2.0 ],
|
||||
[ 1.0, "linear", 1.0 ]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user