mirror of
https://github.com/brl/mutter.git
synced 2025-08-01 14:15:30 +00:00
docs/cookbook: Add script->state connection recipe
Script definitions can connect a signal to a State transition; this is a useful thing to document with a recipe in the cookbook.
This commit is contained in:
@@ -2,6 +2,8 @@ include $(top_srcdir)/build/autotools/Makefile.am.silent
|
||||
|
||||
NULL =
|
||||
|
||||
EXTRA_DIST =
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
actors-composite-main \
|
||||
animations-complex \
|
||||
@@ -11,15 +13,15 @@ noinst_PROGRAMS = \
|
||||
animations-moving-animator \
|
||||
animations-moving-implicit \
|
||||
animations-moving-state \
|
||||
animations-path \
|
||||
animations-path \
|
||||
animations-path-circle \
|
||||
animations-path-easing \
|
||||
animations-reuse \
|
||||
animations-rotating \
|
||||
animations-scaling \
|
||||
animations-scaling-zoom \
|
||||
effects-basic \
|
||||
effects-built-in \
|
||||
effects-basic \
|
||||
effects-built-in \
|
||||
effects-custom-deform \
|
||||
text-shadow \
|
||||
textures-reflection \
|
||||
@@ -43,6 +45,7 @@ noinst_PROGRAMS = \
|
||||
textures-crossfade-slideshow \
|
||||
script-ui \
|
||||
script-signals \
|
||||
script-states \
|
||||
events-buttons \
|
||||
events-buttons-click \
|
||||
events-buttons-lasso \
|
||||
@@ -51,10 +54,7 @@ noinst_PROGRAMS = \
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir)/ \
|
||||
-I$(top_srcdir)/clutter \
|
||||
-I$(top_srcdir)/clutter/cogl \
|
||||
-I$(top_srcdir)/clutter/cogl/pango \
|
||||
-I$(top_builddir)/clutter \
|
||||
-I$(top_builddir)/clutter/cogl \
|
||||
$(NULL)
|
||||
|
||||
LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_SONAME_INFIX@-@CLUTTER_API_VERSION@.la
|
||||
@@ -113,8 +113,19 @@ textures_crossfade_cogl_SOURCES = textures-crossfade-cogl.c
|
||||
textures_crossfade_slideshow_SOURCES = textures-crossfade-slideshow.c
|
||||
script_ui_SOURCES = script-ui.c
|
||||
script_signals_SOURCES = script-signals.c
|
||||
script_states_SOURCES = script-states.c
|
||||
events_buttons_SOURCES = events-buttons.c
|
||||
events_buttons_click_SOURCES = events-buttons-click.c
|
||||
events_buttons_lasso_SOURCES = events-buttons-lasso.c
|
||||
|
||||
EXTRA_DIST += \
|
||||
animations-complex.json \
|
||||
animations-complex-overlapping.json \
|
||||
animations-reuse-animation.json \
|
||||
animations-reuse-ui.json \
|
||||
script-signals.json \
|
||||
script-states.json \
|
||||
script-ui.json \
|
||||
$(NULL)
|
||||
|
||||
-include $(top_srcdir)/build/autotools/Makefile.am.gitignore
|
||||
|
@@ -42,7 +42,10 @@ foo_button_clicked_cb (ClutterClickAction *action,
|
||||
CLUTTER_Z_AXIS,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
z_angle += 90.0;
|
||||
if (clutter_click_action_get_button (action) == 1)
|
||||
z_angle += 90.0;
|
||||
else
|
||||
z_angle -= 90.0;
|
||||
|
||||
/* animate to new rotation angle */
|
||||
clutter_actor_animate (rectangle,
|
||||
|
44
doc/cookbook/examples/script-states.c
Normal file
44
doc/cookbook/examples/script-states.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdlib.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterScript *ui;
|
||||
|
||||
gchar *filename = "script-states.json";
|
||||
GError *error = NULL;
|
||||
|
||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
||||
return 1;
|
||||
|
||||
ui = clutter_script_new ();
|
||||
|
||||
clutter_script_load_from_file (ui, filename, &error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
g_critical ("Error loading ClutterScript file %s\n%s", filename, error->message);
|
||||
g_error_free (error);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
clutter_script_get_objects (ui,
|
||||
"stage", &stage,
|
||||
NULL);
|
||||
|
||||
/* make the objects in the script available to all signals
|
||||
* by passing the script as the second argument
|
||||
* to clutter_script_connect_signals()
|
||||
*/
|
||||
clutter_script_connect_signals (ui, ui);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
g_object_unref (ui);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
92
doc/cookbook/examples/script-states.json
Normal file
92
doc/cookbook/examples/script-states.json
Normal file
@@ -0,0 +1,92 @@
|
||||
[
|
||||
{
|
||||
"id" : "stage",
|
||||
"type" : "ClutterStage",
|
||||
"width" : 300,
|
||||
"height" : 300,
|
||||
"color" : "#335",
|
||||
|
||||
"signals" : [
|
||||
{ "name" : "destroy", "handler" : "clutter_main_quit" }
|
||||
],
|
||||
|
||||
"children" : [ "rectangle" ]
|
||||
},
|
||||
|
||||
{
|
||||
"id" : "rectangle-states",
|
||||
"type" : "ClutterState",
|
||||
"duration" : 1000,
|
||||
|
||||
"transitions" : [
|
||||
{
|
||||
"source" : null,
|
||||
"target" : "base",
|
||||
|
||||
"keys" : [
|
||||
[ "rectangle", "scale-x", "ease-in-cubic", 0.7 ],
|
||||
[ "rectangle", "scale-y", "ease-in-cubic", 0.7 ],
|
||||
[ "rectangle", "rotation-angle-z", "ease-out-cubic", 0.0 ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"source" : null,
|
||||
"target" : "hover",
|
||||
|
||||
"keys" : [
|
||||
[ "rectangle", "scale-x", "ease-in-cubic", 1.2 ],
|
||||
[ "rectangle", "scale-y", "ease-in-cubic", 1.2 ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"source" : null,
|
||||
"target" : "clicked",
|
||||
|
||||
"keys" : [
|
||||
[ "rectangle", "rotation-angle-z", "ease-out-bounce", 90.0 ]
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"id" : "rectangle",
|
||||
"type" : "ClutterRectangle",
|
||||
"width" : 200,
|
||||
"height" : 200,
|
||||
"x" : 50,
|
||||
"y" : 50,
|
||||
"color" : "#a90",
|
||||
"rotation-center-z-gravity" : "center",
|
||||
"scale-gravity" : "center",
|
||||
"scale-x" : 0.7,
|
||||
"scale-y" : 0.7,
|
||||
"reactive" : true,
|
||||
|
||||
"signals" : [
|
||||
{
|
||||
"name" : "enter-event",
|
||||
"states" : "rectangle-states",
|
||||
"target-state" : "hover"
|
||||
},
|
||||
{
|
||||
"name" : "leave-event",
|
||||
"states" : "rectangle-states",
|
||||
"target-state" : "base"
|
||||
}
|
||||
],
|
||||
|
||||
"actions" : [
|
||||
{
|
||||
"type" : "ClutterClickAction",
|
||||
"signals" : [
|
||||
{
|
||||
"name" : "clicked",
|
||||
"states" : "rectangle-states",
|
||||
"target-state" : "clicked"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user