[clutter] test-interactive: Add signal-based state transitions
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter] test-interactive: Add signal-based state transitions
- Date: Mon, 13 Jun 2011 12:47:35 +0000 (UTC)
commit e745ce52e77211ecff131245e6871cef6b97539a
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Mon Feb 7 13:57:16 2011 +0000
test-interactive: Add signal-based state transitions
Use the newly added support for binding signal emissions to state
changes on a ClutterState.
tests/data/Makefile.am | 3 +-
tests/data/test-script-signals.json | 68 +++++++++++++++++++++++++++++++++
tests/interactive/Makefile.am | 3 +-
tests/interactive/test-state-script.c | 54 ++++++++++++++++++++++++++
4 files changed, 126 insertions(+), 2 deletions(-)
---
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index f886a6d..b30d3d1 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -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 = \
diff --git a/tests/data/test-script-signals.json b/tests/data/test-script-signals.json
new file mode 100644
index 0000000..b7c14be
--- /dev/null
+++ b/tests/data/test-script-signals.json
@@ -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)" ]
+ ]
+ }
+ ]
+ }
+]
diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am
index 5c04bf6..3079804 100644
--- a/tests/interactive/Makefile.am
+++ b/tests/interactive/Makefile.am
@@ -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
diff --git a/tests/interactive/test-state-script.c b/tests/interactive/test-state-script.c
new file mode 100644
index 0000000..276cd85
--- /dev/null
+++ b/tests/interactive/test-state-script.c
@@ -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;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]