From 27d9825abe50d5fc38788c1c47f4a28b5225f098 Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Thu, 26 Aug 2010 10:52:12 +0100 Subject: [PATCH] cookbook: Simplified ClutterScript example There was too much in the example code to cover in a single recipe, so I trimmed it down to demonstrate simple UI building (no constraints, effects, animations, or signals). --- doc/cookbook/examples/script-ui.c | 35 ------------ doc/cookbook/examples/script-ui.json | 85 +++------------------------- 2 files changed, 8 insertions(+), 112 deletions(-) diff --git a/doc/cookbook/examples/script-ui.c b/doc/cookbook/examples/script-ui.c index a20e8e494..cc9a12148 100644 --- a/doc/cookbook/examples/script-ui.c +++ b/doc/cookbook/examples/script-ui.c @@ -1,44 +1,12 @@ #include #include -gboolean -_pointer_motion_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer user_data) -{ - g_debug ("Pointer movement"); - return TRUE; -} - -void -_button_clicked_cb (ClutterClickAction *action, - ClutterActor *actor, - gpointer user_data) -{ - /* get the UI definition passed to the handler */ - ClutterScript *ui = CLUTTER_SCRIPT (user_data); - - ClutterState *transitions; - - clutter_script_get_objects (ui, - "transitions", &transitions, - NULL); - - clutter_state_set_state (transitions, "faded-in"); -} - int main (int argc, char *argv[]) { - g_thread_init (NULL); - clutter_init (&argc, &argv); - /* path to the directory containing assets (e.g. images) for the script to load */ - const gchar *paths[] = { TESTS_DATA_DIR }; - ClutterScript *ui = clutter_script_new (); - clutter_script_add_search_paths (ui, paths, 1); gchar *filename = "script-ui.json"; GError *error = NULL; @@ -58,9 +26,6 @@ main (int argc, char *argv[]) "stage", &stage, NULL); - /* make the objects in the script available to all signals */ - clutter_script_connect_signals (ui, ui); - clutter_actor_show (stage); clutter_main (); diff --git a/doc/cookbook/examples/script-ui.json b/doc/cookbook/examples/script-ui.json index 88d3c31c4..99a58e917 100644 --- a/doc/cookbook/examples/script-ui.json +++ b/doc/cookbook/examples/script-ui.json @@ -12,6 +12,8 @@ { "id" : "box", "type" : "ClutterBox", + "width" : 400, + "height" : 400, "layout-manager" : { "type" : "ClutterBinLayout", @@ -19,84 +21,13 @@ "y-align" : "CLUTTER_BIN_ALIGNMENT_CENTER" }, - "constraints" : [ + "children" : [ { - "type" : "ClutterAlignConstraint", - "align-axis" : "CLUTTER_ALIGN_X_AXIS", - "factor" : 0.5, - "source" : "stage" - }, - { - "type" : "ClutterAlignConstraint", - "align-axis" : "CLUTTER_ALIGN_Y_AXIS", - "factor" : 0.5, - "source" : "stage" - } - ], - - "children" : [ "texture1", "texture2" ] - }, - - { - "id" : "texture1", - "type" : "ClutterTexture", - "width" : 200, - "keep-aspect-ratio" : true, - "filename" : "redhand.png", - "load-async" : true, - "reactive" : true, - - "signals" : [ - { "name" : "motion-event", "handler" : "_pointer_motion_cb" } - ], - - "actions" : [ - { - "type" : "ClutterClickAction", - "signals" : [ - { "name" : "clicked", "handler" : "_button_clicked_cb" } - ] - } - ] - }, - - { - "id" : "texture2", - "type" : "ClutterTexture", - "filename" : "redhand.png", - "load-async" : true, - "rotation-center-z-gravity" : "CLUTTER_GRAVITY_CENTER", - "layout::x-align" : "CLUTTER_BIN_ALIGNMENT_FILL", - "layout::y-align" : "CLUTTER_BIN_ALIGNMENT_FILL", - - "effects" : [ - { "type" : "ClutterColorizeEffect", "tint" : "blue" } - ] - }, - - { - "id" : "transitions", - "type" : "ClutterState", - "duration" : 2000, - "state" : "faded-out", - - "transitions" : [ - { - "source" : null, - "target" : "faded-out", - "keys" : [ - [ "texture2", "opacity", "linear", 0 ] - ] - }, - - { - "source" : null, - "target" : "faded-in", - "keys" : [ - [ "texture1", "opacity", "linear", 0 ], - [ "texture2", "opacity", "linear", 255 ], - [ "texture2", "rotation-angle-z", "linear", 90.0 ] - ] + "id" : "rectangle", + "type" : "ClutterRectangle", + "width" : 200, + "height" : 200, + "color" : "red" } ] }