static void clutter_bin_layout_get_property (GObject *gobject, guint prop_id, GValue *value, GParamSpec *pspec) { ClutterBinLayoutPrivate *priv; priv = CLUTTER_BIN_LAYOUT (gobject)->priv; switch (prop_id) { case PROP_X_ALIGN: g_value_set_enum (value, priv->x_align); break; case PROP_Y_ALIGN: g_value_set_enum (value, priv->y_align); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; } }
static void clutter_bin_layout_set_container (ClutterLayoutManager *manager, ClutterContainer *container) { ClutterBinLayoutPrivate *priv; ClutterLayoutManagerClass *parent_class; priv = CLUTTER_BIN_LAYOUT (manager)->priv; priv->container = container; parent_class = CLUTTER_LAYOUT_MANAGER_CLASS (clutter_bin_layout_parent_class); parent_class->set_container (manager, container); }
static ClutterLayoutMeta * clutter_bin_layout_create_child_meta (ClutterLayoutManager *manager, ClutterContainer *container, ClutterActor *actor) { ClutterBinLayoutPrivate *priv; priv = CLUTTER_BIN_LAYOUT (manager)->priv; return g_object_new (CLUTTER_TYPE_BIN_LAYER, "container", container, "actor", actor, "manager", manager, "x-align", priv->x_align, "y_align", priv->y_align, NULL); }
static void clutter_bin_layout_set_property (GObject *gobject, guint prop_id, const GValue *value, GParamSpec *pspec) { ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (gobject); switch (prop_id) { case PROP_X_ALIGN: set_x_align (layout, g_value_get_enum (value)); break; case PROP_Y_ALIGN: set_y_align (layout, g_value_get_enum (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; } }
int main(int argc, char *argv[]) { ClutterTimeline *timeline; ClutterActor *stage; if (argc < 1) { g_error ("Usage: %s", argv[0]); return EXIT_FAILURE; } else { GError *error = NULL; GOptionContext *context; context = g_option_context_new (PROGRAM_DESC); g_option_context_add_main_entries (context, entries, NULL); //GETTEXT_PACKAGE); //g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (! g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); return EXIT_FAILURE; // exit (1); } } if (option_version) { g_print("contextize version %s\n", PACKAGE_VERSION); return 0; } g_thread_init(NULL); // to load images asynchronously. must be called before clutter_init if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) { g_error ("Failed to initialize clutter\n"); return EXIT_FAILURE; } gst_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_actor_set_size(stage, STAGE_WIDTH, STAGE_HEIGHT); clutter_stage_set_color(CLUTTER_STAGE(stage), &black); clutter_stage_set_title(CLUTTER_STAGE(stage), STAGE_TITLE); /* Make a timeline */ timeline = clutter_timeline_new (1000); g_object_set(timeline, "loop", TRUE, NULL); ClutterActor *texture_live = setup_camera_texture(stage); // create the layout ClutterLayoutManager *layout; ClutterActor *box; layout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_box_new(layout); /* then the container */ clutter_actor_set_name(box, BOX_ACTOR); /* we can use the layout object to add actors */ clutter_bin_layout_add(CLUTTER_BIN_LAYOUT(layout), texture_live, CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL); clutter_container_add_actor(CLUTTER_CONTAINER(stage), box); clutter_actor_set_size(box, STAGE_WIDTH, STAGE_HEIGHT); clutter_actor_show_all(box); g_signal_connect(G_OBJECT(stage), "fullscreen", G_CALLBACK(on_fullscreen), NULL); g_signal_connect(G_OBJECT(stage), "unfullscreen", G_CALLBACK(on_unfullscreen), NULL); g_signal_connect(G_OBJECT(stage), "key-press-event", G_CALLBACK(key_press_event), NULL); /* start the timeline */ clutter_timeline_start (timeline); clutter_actor_show_all (stage); if (option_fullscreen) clutter_stage_set_fullscreen(CLUTTER_STAGE(stage), TRUE); // OSC server lo_server_thread osc_server = NULL; if (option_osc_receive_port != 0) { gchar *osc_port_str = g_strdup_printf("%i", option_osc_receive_port); if (option_verbose) g_print("Listening on osc.udp://localhost:%s\n", osc_port_str); osc_server = lo_server_thread_new(osc_port_str, on_osc_error); g_free(osc_port_str); lo_server_thread_start(osc_server); } clutter_main(); if (option_osc_receive_port != 0) lo_server_thread_free(osc_server); return EXIT_SUCCESS; }
G_MODULE_EXPORT int test_bin_layout_main (int argc, char *argv[]) { ClutterActor *stage, *box, *rect; ClutterLayoutManager *layout; ClutterColor stage_color = { 0xe0, 0xf2, 0xfc, 0xff }; ClutterColor bg_color = { 0xcc, 0xcc, 0xcc, 0x99 }; ClutterColor *color; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Box test"); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_actor_set_size (stage, 640, 480); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_box_new (layout); clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); clutter_actor_set_anchor_point_from_gravity (box, CLUTTER_GRAVITY_CENTER); clutter_actor_set_position (box, 320, 240); clutter_actor_set_reactive (box, TRUE); clutter_actor_set_name (box, "box"); rect = make_background (&bg_color, 200, 200); /* first method: use clutter_box_pack() */ clutter_box_pack (CLUTTER_BOX (box), rect, "x-align", CLUTTER_BIN_ALIGNMENT_FILL, "y-align", CLUTTER_BIN_ALIGNMENT_FILL, NULL); clutter_actor_lower_bottom (rect); clutter_actor_set_name (rect, "background"); { ClutterActor *tex; GError *error; gchar *file; error = NULL; file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); tex = clutter_texture_new_from_file (file, &error); if (error) g_error ("Unable to create texture: %s", error->message); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (tex), TRUE); /* second method: use clutter_bin_layout_add() */ clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), tex, CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); clutter_actor_raise (tex, rect); clutter_actor_set_width (tex, 175); clutter_actor_set_name (tex, "texture"); g_free (file); } color = clutter_color_new (g_random_int_range (0, 255), g_random_int_range (0, 255), g_random_int_range (0, 255), 224); rect = clutter_rectangle_new_with_color (color); /* third method: container_add() and set_alignment() */ clutter_container_add_actor (CLUTTER_CONTAINER (box), rect); clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout), rect, CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END); clutter_actor_set_size (rect, 50, 50); clutter_actor_set_opacity (rect, 0); clutter_actor_raise_top (rect); clutter_actor_set_name (rect, "emblem"); g_signal_connect (box, "enter-event", G_CALLBACK (on_box_enter), rect); g_signal_connect (box, "leave-event", G_CALLBACK (on_box_leave), rect); clutter_actor_show_all (stage); clutter_main (); clutter_color_free (color); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterLayoutManager *layout; ClutterActor *box; ClutterActor *rect; ClutterActor *text; ClutterState *transitions; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "btn"); clutter_actor_set_background_color (stage, &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL); box = clutter_actor_new (); clutter_actor_set_layout_manager (box, layout); clutter_actor_set_position (box, 25, 25); clutter_actor_set_reactive (box, TRUE); clutter_actor_set_size (box, 100, 30); /* background for the button */ rect = clutter_rectangle_new_with_color (&yellow); clutter_actor_add_child (box, rect); /* text for the button */ text = clutter_text_new_full ("Sans 10pt", "Hover me", &white); /* * NB don't set the height, so the actor assumes the height of the text; * then when added to the bin layout, it gets centred on it; * also if you don't set the width, the layout goes gets really wide; * the 10pt text fits inside the 30px height of the rectangle */ clutter_actor_set_width (text, 100); clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), text, CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); /* animations */ transitions = clutter_state_new (); clutter_state_set (transitions, NULL, "fade-out", box, "opacity", CLUTTER_LINEAR, 180, NULL); /* * NB you can't use an easing mode where alpha > 1.0 if you're * animating to a value of 255, as the value you're animating * to will possibly go > 255 */ clutter_state_set (transitions, NULL, "fade-in", box, "opacity", CLUTTER_LINEAR, 255, NULL); clutter_state_set_duration (transitions, NULL, NULL, 50); clutter_state_warp_to_state (transitions, "fade-out"); g_signal_connect (box, "enter-event", G_CALLBACK (_pointer_enter_cb), transitions); g_signal_connect (box, "leave-event", G_CALLBACK (_pointer_leave_cb), transitions); /* bind the stage size to the box size + 50px in each axis */ clutter_actor_add_constraint (stage, clutter_bind_constraint_new (box, CLUTTER_BIND_HEIGHT, 50.0)); clutter_actor_add_constraint (stage, clutter_bind_constraint_new (box, CLUTTER_BIND_WIDTH, 50.0)); clutter_actor_add_child (stage, box); clutter_actor_show (stage); clutter_main (); g_object_unref (transitions); return 0; }