test-interactive: Add signal-based state transitions
Use the newly added support for binding signal emissions to state changes on a ClutterState.
This commit is contained in:
parent
dd8cf63a62
commit
e745ce52e7
@ -3,17 +3,18 @@ NULL =
|
||||
json_files = \
|
||||
test-script-animation.json \
|
||||
test-script-child.json \
|
||||
test-script-layout-property.json \
|
||||
test-script-implicit-alpha.json \
|
||||
test-script.json \
|
||||
test-script-named-object.json \
|
||||
test-script-object-property.json \
|
||||
test-script-signals.json \
|
||||
test-script-single.json \
|
||||
test-script-model.json \
|
||||
test-animator-1.json \
|
||||
test-animator-2.json \
|
||||
test-animator-3.json \
|
||||
test-state-1.json \
|
||||
test-script-layout-property.json \
|
||||
$(NULL)
|
||||
|
||||
png_files = \
|
||||
|
68
tests/data/test-script-signals.json
Normal file
68
tests/data/test-script-signals.json
Normal file
@ -0,0 +1,68 @@
|
||||
[
|
||||
{
|
||||
"id" : "button",
|
||||
"type" : "ClutterRectangle",
|
||||
|
||||
"width" : "16 em",
|
||||
"height" : "6 em",
|
||||
|
||||
"color" : "rgb(255, 0, 0)",
|
||||
"opacity" : 128,
|
||||
|
||||
"scale-gravity" : "center",
|
||||
|
||||
"reactive" : true,
|
||||
|
||||
"signals" : [
|
||||
{
|
||||
"name" : "button-press-event",
|
||||
"handler" : "on_button_press"
|
||||
},
|
||||
{ "name" : "enter-event", "state" : "button-states", "target-state" : "hover" },
|
||||
{ "name" : "leave-event", "state" : "button-states", "target-state" : "base" },
|
||||
{ "name" : "button-press-event", "state" : "button-states", "target-state" : "active" },
|
||||
{ "name" : "button-release-event", "state" : "button-states", "target-state" : "base" }
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"id" : "button-states",
|
||||
"type" : "ClutterState",
|
||||
|
||||
"duration" : 250,
|
||||
|
||||
"transitions" : [
|
||||
{
|
||||
"source" : null,
|
||||
"target" : "base",
|
||||
|
||||
"keys" : [
|
||||
[ "button", "opacity", "linear", 128 ],
|
||||
[ "button", "scale-x", "ease-in-cubic", 1.0 ],
|
||||
[ "button", "scale-y", "ease-in-cubic", 1.0 ],
|
||||
[ "button", "color", "linear", "rgb(255, 0, 0)" ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"source" : null,
|
||||
"target" : "hover",
|
||||
|
||||
"keys" : [
|
||||
[ "button", "opacity", "linear", 255 ],
|
||||
[ "button", "scale-x", "ease-out-bounce", 1.4 ],
|
||||
[ "button", "scale-y", "ease-out-bounce", 1.4 ],
|
||||
[ "button", "color", "linear", "rgb(0, 255, 0)" ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"source" : null,
|
||||
"target" : "active",
|
||||
|
||||
"keys" : [
|
||||
[ "button", "opacity", "linear", 255 ],
|
||||
[ "button", "color", "linear", "rgb(0, 0, 255)" ]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -55,7 +55,8 @@ UNIT_TESTS = \
|
||||
test-cogl-point-sprites.c \
|
||||
test-table-layout.c \
|
||||
test-path-constraint.c \
|
||||
test-snap-constraint.c
|
||||
test-snap-constraint.c \
|
||||
test-state-script.c
|
||||
|
||||
if X11_TESTS
|
||||
UNIT_TESTS += test-pixmap.c test-devices.c
|
||||
|
54
tests/interactive/test-state-script.c
Normal file
54
tests/interactive/test-state-script.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gmodule.h>
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define TEST_STATE_SCRIPT_FILE TESTS_DATADIR G_DIR_SEPARATOR_S "test-script-signals.json"
|
||||
|
||||
gboolean
|
||||
on_button_press (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer dummy G_GNUC_UNUSED)
|
||||
{
|
||||
g_print ("Button pressed!\n");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT int
|
||||
test_state_script_main (int argc, char *argv[])
|
||||
{
|
||||
ClutterActor *stage, *button;
|
||||
ClutterScript *script;
|
||||
GError *error = NULL;
|
||||
|
||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
script = clutter_script_new ();
|
||||
clutter_script_load_from_file (script, TEST_STATE_SCRIPT_FILE, &error);
|
||||
if (error != NULL)
|
||||
g_error ("Unable to load '%s': %s\n",
|
||||
TEST_STATE_SCRIPT_FILE,
|
||||
error->message);
|
||||
|
||||
stage = clutter_stage_new ();
|
||||
clutter_stage_set_title (CLUTTER_STAGE (stage), "State Script");
|
||||
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
|
||||
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
||||
clutter_actor_show (stage);
|
||||
|
||||
button = CLUTTER_ACTOR (clutter_script_get_object (script, "button"));
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), button);
|
||||
clutter_actor_add_constraint (button, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5));
|
||||
clutter_actor_add_constraint (button, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5));
|
||||
|
||||
clutter_script_connect_signals (script, NULL);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
g_object_unref (script);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user