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).
This commit is contained in:
parent
4cba0cf3e8
commit
27d9825abe
@ -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 ();
|
||||
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user