cookbook: Simplified ClutterScript example
authorElliot Smith <elliot.smith@intel.com>
Thu, 26 Aug 2010 09:52:12 +0000 (10:52 +0100)
committerElliot Smith <elliot.smith@intel.com>
Fri, 27 Aug 2010 10:21:30 +0000 (11:21 +0100)
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
doc/cookbook/examples/script-ui.json

index a20e8e4..cc9a121 100644 (file)
@@ -1,44 +1,12 @@
 #include <stdlib.h>
 #include <clutter/clutter.h>
 
-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 ();
index 88d3c31..99a58e9 100644 (file)
@@ -12,6 +12,8 @@
   {
     "id" : "box",
     "type" : "ClutterBox",
+    "width" : 400,
+    "height" : 400,
 
     "layout-manager" : {
       "type" : "ClutterBinLayout",
       "y-align" : "CLUTTER_BIN_ALIGNMENT_CENTER"
     },
 
-    "constraints" : [
-      {
-        "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 ]
-        ]
-      },
-
+    "children" : [
       {
-        "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"
       }
     ]
   }