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 <stdlib.h>
|
||||||
#include <clutter/clutter.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
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
g_thread_init (NULL);
|
|
||||||
|
|
||||||
clutter_init (&argc, &argv);
|
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 ();
|
ClutterScript *ui = clutter_script_new ();
|
||||||
clutter_script_add_search_paths (ui, paths, 1);
|
|
||||||
|
|
||||||
gchar *filename = "script-ui.json";
|
gchar *filename = "script-ui.json";
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@ -58,9 +26,6 @@ main (int argc, char *argv[])
|
|||||||
"stage", &stage,
|
"stage", &stage,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* make the objects in the script available to all signals */
|
|
||||||
clutter_script_connect_signals (ui, ui);
|
|
||||||
|
|
||||||
clutter_actor_show (stage);
|
clutter_actor_show (stage);
|
||||||
|
|
||||||
clutter_main ();
|
clutter_main ();
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
{
|
{
|
||||||
"id" : "box",
|
"id" : "box",
|
||||||
"type" : "ClutterBox",
|
"type" : "ClutterBox",
|
||||||
|
"width" : 400,
|
||||||
|
"height" : 400,
|
||||||
|
|
||||||
"layout-manager" : {
|
"layout-manager" : {
|
||||||
"type" : "ClutterBinLayout",
|
"type" : "ClutterBinLayout",
|
||||||
@ -19,84 +21,13 @@
|
|||||||
"y-align" : "CLUTTER_BIN_ALIGNMENT_CENTER"
|
"y-align" : "CLUTTER_BIN_ALIGNMENT_CENTER"
|
||||||
},
|
},
|
||||||
|
|
||||||
"constraints" : [
|
"children" : [
|
||||||
{
|
{
|
||||||
"type" : "ClutterAlignConstraint",
|
"id" : "rectangle",
|
||||||
"align-axis" : "CLUTTER_ALIGN_X_AXIS",
|
"type" : "ClutterRectangle",
|
||||||
"factor" : 0.5,
|
"width" : 200,
|
||||||
"source" : "stage"
|
"height" : 200,
|
||||||
},
|
"color" : "red"
|
||||||
{
|
|
||||||
"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 ]
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user