int main (int argc, char **argv) { const ClutterColor red = { 0xff, 0x00, 0x00, 0xff }; ClutterActor *stage, *box, *tile, *rectangle; clutter_init (&argc, &argv); mex_style_load_default (); stage = clutter_stage_get_default (); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); tile = mex_tile_new_with_label ("Red rectangle"); mex_tile_set_important (MEX_TILE (tile), TRUE); rectangle = clutter_rectangle_new_with_color (&red); clutter_actor_set_size (rectangle, 300, 300); mx_bin_set_child (MX_BIN (tile), rectangle); box = mex_expander_box_new (); clutter_container_add (CLUTTER_CONTAINER (box), tile, clutter_text_new_with_text ("Sans 16", "Hello"), NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); clutter_actor_set_reactive (rectangle, TRUE); g_signal_connect_swapped (rectangle, "enter-event", G_CALLBACK (toggle_important), box); clutter_actor_show (stage); clutter_main (); return 0; }
G_MODULE_EXPORT int test_pixmap_main (int argc, char **argv) { GOptionContext *context; Display *xdpy; int screen; ClutterActor *group = NULL, *label, *stage, *tex; Pixmap pixmap; const ClutterColor gry = { 0x99, 0x99, 0x99, 0xFF }; Window win_remote; guint w, h, d; GC gc; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *depth_behavior; int i; int row_height; #ifdef CLUTTER_WINDOWING_X11 clutter_set_windowing_backend (CLUTTER_WINDOWING_X11); #endif if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; #ifdef CLUTTER_WINDOWING_X11 if (!clutter_check_windowing_backend (CLUTTER_WINDOWING_X11)) g_error ("test-pixmap requires the X11 Clutter backend."); #endif xdpy = clutter_x11_get_default_display (); XSynchronize (xdpy, True); context = g_option_context_new (" - test-pixmap options"); g_option_context_add_main_entries (context, g_options, NULL); g_option_context_parse (context, &argc, &argv, NULL); pixmap = create_pixmap (&w, &h, &d); screen = DefaultScreen(xdpy); win_remote = XCreateSimpleWindow (xdpy, DefaultRootWindow(xdpy), 0, 0, 200, 200, 0, WhitePixel(xdpy, screen), WhitePixel(xdpy, screen)); XMapWindow (xdpy, win_remote); stage = clutter_stage_new (); clutter_actor_set_position (stage, 0, 150); clutter_actor_set_background_color (stage, &gry); clutter_stage_set_title (CLUTTER_STAGE (stage), "X11 Texture from Pixmap"); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); timeline = clutter_timeline_new (5000); g_signal_connect (timeline, "completed", G_CALLBACK (timeline_completed), NULL); alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400); if (!disable_x11) { group = clutter_group_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); label = clutter_text_new_with_text ("fixed", "ClutterX11Texture (Window)"); clutter_container_add_actor (CLUTTER_CONTAINER (group), label); tex = clutter_x11_texture_pixmap_new_with_window (win_remote); clutter_container_add_actor (CLUTTER_CONTAINER (group), tex); clutter_actor_set_position (tex, 0, 20); clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex), TRUE); clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex), CLUTTER_TEXTURE_QUALITY_HIGH); clutter_actor_set_position (group, 0, 0); if (!disable_animation) clutter_behaviour_apply (depth_behavior, group); } if (group) row_height = clutter_actor_get_height (group); else row_height = 0; /* NB: We only draw on the window after being redirected, so we dont * have to worry about handling expose events... */ gc = XCreateGC (xdpy, win_remote, 0, NULL); XSetForeground (xdpy, gc, BlackPixel (xdpy, screen)); XSetLineAttributes(xdpy, gc, 5, LineSolid, CapButt, JoinMiter); for (i = 0; i < 10; i++) XDrawLine (xdpy, win_remote, gc, 0+i*20, 0, 10+i*20+i, 200); group = clutter_group_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); label = clutter_text_new_with_text ("fixed", "ClutterX11Texture (Pixmap)"); clutter_container_add_actor (CLUTTER_CONTAINER (group), label); tex = clutter_x11_texture_pixmap_new_with_pixmap (pixmap); clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex), TRUE); clutter_container_add_actor (CLUTTER_CONTAINER (group), tex); clutter_actor_set_position (tex, 0, 20); clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex), CLUTTER_TEXTURE_QUALITY_HIGH); /* oddly, the actor's size is 0 until it is realized, even though pixmap-height is set */ clutter_actor_set_position (group, 0, row_height); if (!disable_animation) clutter_behaviour_apply (depth_behavior, group); g_signal_connect (stage, "key-release-event", G_CALLBACK (stage_key_release_cb), (gpointer)pixmap); g_signal_connect (stage, "button-press-event", G_CALLBACK (stage_button_press_cb), (gpointer)pixmap); clutter_actor_show (stage); if (!disable_animation) clutter_timeline_start (timeline); clutter_threads_add_timeout (1000, draw_arc, GUINT_TO_POINTER (pixmap)); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char **argv) { GList *v; GDir *dir; gchar *text; const gchar *filename; ClutterActor *stage, *label; gint x, y, n, cols, rows, width, height; GList *views = NULL; GError *error = NULL; clutter_init (&argc, &argv); /* This is a *massive* hack just to demonstrate live previews. Please don't * ever do this, use IPC to coordinate doing this cleanly with * clutter_mozembed_new_view() and clutter_mozembed_connect_view() */ dir = g_dir_open (g_get_tmp_dir (), 0, &error); if (!dir) { g_warning ("Error opening temporary files directory: %s", error->message); g_error_free (error); } else { while ((filename = g_dir_read_name (dir))) { gint fd; ClutterActor *mozembed; gchar *full_file, *input, *output, *command; if (!strstr (filename, "clutter-mozheadless-")) continue; full_file = g_build_filename (g_get_tmp_dir (), filename, NULL); /* I've *no* idea what happens when two processes are writing on the * same pipe in terms of the possibility of interleaved messages... */ /* Open the pipe and ask it to create a new view */ fd = open (full_file, O_WRONLY | O_NDELAY); if (fd) { mozembed = clutter_mozembed_new_view (); /* Get the pipe names */ g_object_get (G_OBJECT (mozembed), "input", &input, "output", &output, NULL); /* You should NEVER do this, you need to use IPC to tell the * parent application to connect the view with * clutter_mozembed_connect_view() */ command = g_strdup_printf ("new-view %s %s", input, output); write (fd, command, strlen (command) + 1); g_free (command); close (fd); g_free (input); g_free (output); views = g_list_append (views, mozembed); } g_free (full_file); } g_dir_close (dir); } /* Now put all the views on a stage */ stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 800, 600); n = g_list_length (views); text = g_strdup_printf ("%d live previews:", n); label = clutter_text_new_with_text ("Sans 20px", text); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); clutter_actor_set_position (label, 10, 10); x = y = 0; rows = MAX (1, (gint)sqrt ((gdouble)n)); cols = MAX (1, n / rows); width = (clutter_actor_get_width (stage) - 20) / cols; height = (clutter_actor_get_height (stage) - 60) / rows; for (v = views; v; v = v->next) { ClutterActor *mozembed = CLUTTER_ACTOR (v->data); clutter_container_add_actor (CLUTTER_CONTAINER (stage), mozembed); clutter_actor_set_position (mozembed, (x*width) + 10, (y*height) + 40); clutter_actor_set_size (mozembed, width, height); x++; if (x > cols) { x = 0; y++; } } g_list_free (views); clutter_actor_show_all (stage); clutter_main (); clutter_actor_destroy (stage); return 0; }
int main (int argc, char **argv) { const ClutterColor transp = { 0x00, 0x00, 0x00, 0x00 }; const ClutterColor bg_color = { 0xe0, 0xf2, 0xfc, 0xff }; ClutterTimeline *timeline; ClutterActor *stage; gint i; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Circles"); clutter_stage_set_color (CLUTTER_STAGE (stage), &bg_color); clutter_actor_set_size (stage, SCREEN_W, SCREEN_H); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); timeline = clutter_timeline_new (5000); clutter_timeline_set_loop (timeline, TRUE); for (i = 0; i < N_CIRCLES; i++) { gint size; gdouble *angle; ClutterActor *actor; ClutterAlpha *alpha; ClutterBehaviour *behaviour; actor = clutter_rectangle_new_with_color (&transp); size = (i + 1) * (CIRCLE_W + CIRCLE_G) * 2; clutter_actor_set_size (actor, size, size); clutter_actor_set_position (actor, SCREEN_W - size / 2.0, SCREEN_H - size / 2.0); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); angle = g_slice_new (gdouble); *angle = g_random_double_range (0.0, 90.0); g_object_set_data (G_OBJECT (actor), "angle", angle); g_signal_connect (actor, "paint", G_CALLBACK (circle_paint_cb), NULL); /* Animate */ alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); behaviour = clutter_behaviour_rotate_new (alpha, CLUTTER_Z_AXIS, (i % 2) ? CLUTTER_ROTATE_CW : CLUTTER_ROTATE_CCW, 0.0, 0.0); clutter_behaviour_rotate_set_center (CLUTTER_BEHAVIOUR_ROTATE (behaviour), size / 2, size / 2, 0); clutter_behaviour_apply (behaviour, actor); } ClutterActor *actor2 = clutter_group_new(); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor2); clutter_actor_set_position(actor2, 10, 10); ClutterEffect *effect2 = nineslice_effect_new_from_source(source); clutter_actor_add_effect(actor2, effect2); ClutterActor *actor = clutter_group_new(); clutter_container_add_actor (CLUTTER_CONTAINER (actor2), actor); ClutterEffect *effect = nineslice_effect_new_from_source(source); clutter_actor_add_effect(actor, effect); ClutterActor *text = clutter_text_new_with_text("Sans 40px","Example Text"); clutter_actor_set_position(text, 0, 0); clutter_container_add_actor (CLUTTER_CONTAINER (actor), text); ClutterActor *rect = clutter_rectangle_new(); clutter_actor_set_position(rect, 10, 100); clutter_actor_set_size(rect, 50, 50); clutter_container_add_actor (CLUTTER_CONTAINER (actor), rect); clutter_actor_set_position(actor, 200, 100); //clutter_actor_set_rotation(actor, CLUTTER_Z_AXIS, 30.0, 130, 50, 0); /* GValue cvalue = G_VALUE_INIT; g_value_init(&cvalue, CLUTTER_TYPE_ACTOR_BOX); g_value_set_boxed(&cvalue, clutter_actor_box_new(0.0, 0.0, 0.0, 0.0)); GValue ovalue = G_VALUE_INIT; g_value_init(&ovalue, CLUTTER_TYPE_ACTOR_BOX); g_value_set_boxed(&ovalue, clutter_actor_box_new(50.0, 50.0, 50.0, 50.0)); ClutterState *transition = clutter_state_new(); clutter_state_set_duration(transition, NULL, NULL, 5000); clutter_state_set_key (transition, NULL, "close", G_OBJECT(effect), "padding", CLUTTER_LINEAR, &cvalue, 0.0, 0.0); clutter_state_set_key (transition, NULL, "open", G_OBJECT(effect), "padding", CLUTTER_LINEAR, &ovalue, 0.0, 0.0); //clutter_state_set(transition, NULL, "close", effect, "padding_right", CLUTTER_LINEAR, 0.0, NULL); //clutter_state_set(transition, NULL, "open", effect, "padding_right", CLUTTER_LINEAR, 50.0, NULL); clutter_state_warp_to_state(transition, "close"); clutter_state_set_state(transition, "open"); */ clutter_actor_animate(rect, CLUTTER_LINEAR, 5000, "height", 200.0, NULL); clutter_actor_show_all (stage); clutter_timeline_start (timeline); clutter_main (); return 0; }
G_MODULE_EXPORT int test_scale_main (int argc, char *argv[]) { ClutterActor *stage, *rect; ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *behave; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Scaling"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); clutter_actor_set_size (stage, 300, 300); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (rect, 100, 100); clutter_actor_set_position (rect, 100, 100); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); label = clutter_text_new_with_text ("Sans 20px", ""); clutter_text_set_color (CLUTTER_TEXT (label), CLUTTER_COLOR_White); clutter_actor_set_position (label, clutter_actor_get_x (rect), clutter_actor_get_y (rect) + clutter_actor_get_height (rect)); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); rect_color.alpha = 0xff; rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_position (rect, 100, 100); clutter_actor_set_size (rect, 100, 100); set_next_gravity (rect); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); timeline = clutter_timeline_new (750); alpha = clutter_alpha_new_with_func (timeline, my_ramp_func, NULL, NULL); behave = clutter_behaviour_scale_new (alpha, 0.0, 0.0, /* scale start */ 1.0, 1.0); /* scale end */ clutter_behaviour_apply (behave, rect); clutter_timeline_set_repeat_count (timeline, -1); g_signal_connect_swapped (timeline, "completed", G_CALLBACK (set_next_gravity), rect); clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (timeline); g_object_unref (behave); return EXIT_SUCCESS; }
G_MODULE_EXPORT gint test_shader_main (gint argc, gchar *argv[]) { ClutterActor *actor; ClutterActor *stage; ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; ClutterShader *shader; GError *error; gchar *file; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Shaders"); clutter_actor_set_size (stage, 512, 384); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); g_print ("applying shaders[%i] named '%s'\n", shader_no, shaders[shader_no].name); shader = clutter_shader_new (); error = NULL; clutter_shader_set_fragment_source (shader, shaders[shader_no].source, -1); clutter_shader_compile (shader, &error); if (error) { g_print ("unable to load shaders[%d] named '%s': %s\n", shader_no, shaders[shader_no].name, error->message); g_error_free (error); return EXIT_FAILURE; } clutter_stage_set_title (CLUTTER_STAGE (stage), "Shader Test"); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); #ifndef TEST_GROUP actor = clutter_texture_new_from_file (file, &error); if (!actor) g_error("pixbuf load failed: %s", error ? error->message : "Unknown"); #else actor = clutter_group_new (); { ClutterActor *child1, *child2, *child3, *child4; ClutterColor color = { 0xff, 0x22, 0x66, 0x99 }; child1 = clutter_texture_new_from_file (file, &error); if (!child1) g_error("pixbuf load failed: %s", error ? error->message : "Unknown"); child2 = clutter_texture_new_from_file (file, &error); if (!child2) g_error("pixbuf load failed: %s", error ? error->message : "Unknown"); child3 = clutter_rectangle_new (); child4 = clutter_text_new_with_text ("Sans 20px", "Shady stuff"); clutter_rectangle_set_color (CLUTTER_RECTANGLE (child3), &color); clutter_actor_set_size (child3, 50, 50); clutter_actor_set_position (child1, 0, 0); clutter_actor_set_position (child2, 50, 100); clutter_actor_set_position (child3, 30, -30); clutter_actor_set_position (child4, -50, 20); clutter_container_add (CLUTTER_CONTAINER (actor), child1, child2, child3, child4, NULL); clutter_actor_show_all (actor); } #endif /* !TEST_GROUP */ g_free (file); clutter_actor_set_shader (actor, shader); clutter_actor_set_position (actor, 100, 100); g_object_unref (shader); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); clutter_actor_set_shader_param_int (actor, "tex", 0); clutter_actor_set_shader_param_float (actor, "brightness", 0.4); clutter_actor_set_shader_param_float (actor, "contrast", -1.9); clutter_actor_set_reactive (actor, TRUE); g_signal_connect (actor, "button-release-event", G_CALLBACK (button_release_cb), NULL); #ifdef COGL_HAS_GLES2 /* On an embedded platform it is difficult to right click so we will cycle through the shaders automatically */ g_timeout_add_seconds (3, timeout_cb, actor); #endif /* Show everying ( and map window ) */ clutter_actor_show_all (stage); clutter_main (); return EXIT_SUCCESS; }
G_MODULE_EXPORT int test_unproject_main (int argc, char *argv[]) { gchar *txt; ClutterActor *rect, *stage, *label0; int i, rotate_x = 0, rotate_y = 60, rotate_z = 0; ClutterColor stage_clr = { 0x0, 0x0, 0x0, 0xff }, white = { 0xff, 0xff, 0xff, 0xff }, blue = { 0x0, 0xff, 0xff, 0xff }; for (i = 0; i < argc; ++i) { if (!strncmp (argv[i], "--rotate-x", 10)) { rotate_x = atoi (argv[i] + 11); } else if (!strncmp (argv[i], "--rotate-y", 10)) { rotate_y = atoi (argv[i] + 11); } else if (!strncmp (argv[i], "--rotate-z", 10)) { rotate_z = atoi (argv[i] + 11); } else if (!strncmp (argv[i], "--help", 6)) { g_print ("%s [--rotage-x=degrees] " "[--rotage-y=degrees] " "[--rotage-z=degrees]\n", argv[0]); return EXIT_FAILURE; } } if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr); clutter_actor_set_size (stage, 640, 480); rect = clutter_rectangle_new_with_color (&white); clutter_actor_set_size (rect, RECT_W, RECT_H); clutter_actor_set_position (rect, RECT_L, RECT_T); clutter_actor_set_rotation (rect, CLUTTER_X_AXIS, rotate_x, 0, 0, 0); clutter_actor_set_rotation (rect, CLUTTER_Y_AXIS, rotate_y, 0, 0, 0); clutter_actor_set_rotation (rect, CLUTTER_Z_AXIS, rotate_z, 0, 0, 0); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); test_rectangle = rect; txt = g_strdup_printf ("Rectangle: L %d, R %d, T %d, B %d\n" "Rotation : x %d, y %d, z %d", RECT_L, RECT_L + RECT_W, RECT_T, RECT_T + RECT_H, rotate_x, rotate_y, rotate_z); label0 = clutter_text_new_with_text ("Mono 8pt", txt); clutter_text_set_color (CLUTTER_TEXT (label0), &white); clutter_actor_set_position (label0, 10, 10); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label0); g_free (txt); label = clutter_text_new_with_text ("Mono 8pt", "Click around!"); clutter_text_set_color (CLUTTER_TEXT (label), &blue); clutter_actor_set_position (label, 10, 50); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); clutter_actor_show_all (stage); g_signal_connect (stage, "event", G_CALLBACK (on_event), NULL); clutter_main(); test_rectangle = NULL; label = NULL; return EXIT_SUCCESS; }
void opt_show_toggle_position (OptShow *show) { OptShowPrivate *priv; ClutterActor *stage; ClutterGeometry stage_geom; g_return_if_fail (OPT_IS_SHOW (show)); priv = show->priv; stage = clutter_stage_get_default (); clutter_actor_get_geometry (stage, &stage_geom); if (!priv->position_label) { ClutterActor *rect; ClutterActor *label; ClutterColor rect_color = { 0x00, 0x00, 0x00, 0x33 }; ClutterColor label_color = { 0xff, 0xff, 0xff, 0xee }; ClutterGeometry rect_geom; rect = clutter_rectangle_new (); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_color); rect_geom.width = 102; rect_geom.height = 77; rect_geom.x = stage_geom.width / 2 - rect_geom.width / 2; rect_geom.y = stage_geom.height - rect_geom.height - 20; clutter_actor_set_geometry (rect, &rect_geom); label = clutter_text_new_with_text ("Sans Bold 20", "0/0"); clutter_text_set_color (CLUTTER_TEXT (label), &label_color); clutter_actor_set_position (label, rect_geom.x + 10, rect_geom.y + 10); clutter_group_add_many (CLUTTER_GROUP (stage), rect, label, NULL); priv->position_label = label; priv->position_rect = rect; priv->position_label_visible = FALSE; } if (!priv->position_label_visible) { priv->position_label_visible = TRUE; opt_show_update_position_label (show); clutter_actor_show (priv->position_rect); clutter_actor_show (priv->position_label); } else { clutter_actor_hide (priv->position_label); clutter_actor_hide (priv->position_rect); priv->position_label_visible = FALSE; } }
/* bullet hacks, needs redoing */ ClutterActor* opt_show_bullet_clone (OptShow *show) { return clutter_text_new_with_text (show->priv->bullet_font, "•"); }
G_MODULE_EXPORT int test_scale_main (int argc, char *argv[]) { ClutterActor *stage, *rect; ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; ClutterColor white_color = { 0xff, 0xff, 0xff, 0xFF }; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *behave; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_actor_set_size (stage, 300, 300); rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (rect, 100, 100); clutter_actor_set_position (rect, 100, 100); clutter_group_add (CLUTTER_GROUP (stage), rect); label = clutter_text_new_with_text ("Sans 20px", ""); clutter_text_set_color (CLUTTER_TEXT (label), &white_color); clutter_actor_set_position (label, clutter_actor_get_x (rect), clutter_actor_get_y (rect) + clutter_actor_get_height (rect)); clutter_group_add (CLUTTER_GROUP (stage), label); rect_color.alpha = 0xff; rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_position (rect, 100, 100); clutter_actor_set_size (rect, 100, 100); set_next_gravity (rect); clutter_group_add (CLUTTER_GROUP (stage), rect); timeline = clutter_timeline_new (750); alpha = clutter_alpha_new_with_func (timeline, my_ramp_func, NULL, NULL); behave = clutter_behaviour_scale_new (alpha, 0.0, 0.0, /* scale start */ 1.0, 1.0); /* scale end */ clutter_behaviour_apply (behave, rect); clutter_timeline_set_loop (timeline, TRUE); g_signal_connect_swapped (timeline, "completed", G_CALLBACK (set_next_gravity), rect); clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (timeline); g_object_unref (behave); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage, *box, *instructions; ClutterLayoutManager *stage_layout, *grid_layout; GError *error = NULL; if (clutter_init_with_args (&argc, &argv, NULL, entries, NULL, &error) != CLUTTER_INIT_SUCCESS) { g_print ("Unable to run grid-layout: %s", error->message); g_error_free (error); return EXIT_FAILURE; } stage = clutter_stage_new (); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); stage_layout = clutter_box_layout_new (); clutter_box_layout_set_orientation (CLUTTER_BOX_LAYOUT (stage_layout), CLUTTER_ORIENTATION_VERTICAL); clutter_actor_set_layout_manager (stage, stage_layout); grid_layout = clutter_grid_layout_new (); if (is_vertical) clutter_grid_layout_set_orientation (CLUTTER_GRID_LAYOUT (grid_layout), CLUTTER_ORIENTATION_VERTICAL); box = clutter_actor_new (); clutter_actor_set_background_color (box, CLUTTER_COLOR_LightGray); clutter_actor_set_x_expand (box, TRUE); clutter_actor_set_y_expand (box, TRUE); clutter_actor_set_layout_manager (box, grid_layout); clutter_actor_add_child (stage, box); clutter_actor_set_x_align (box, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_y_align (box, CLUTTER_ACTOR_ALIGN_FILL); add_actor (box, 0, 0, 1, 1); add_actor (box, 1, 0, 1, 1); add_actor (box, 2, 0, 1, 1); add_actor (box, 0, 1, 1, 1); add_actor (box, 1, 1, 2, 1); add_actor (box, 0, 2, 3, 1); add_actor (box, 0, 3, 2, 2); add_actor (box, 2, 3, 1, 1); add_actor (box, 2, 4, 1, 1); instructions = clutter_text_new_with_text ("Sans 12px", INSTRUCTIONS); clutter_actor_set_margin_top (instructions, 4); clutter_actor_set_margin_left (instructions, 4); clutter_actor_set_margin_bottom (instructions, 4); clutter_actor_add_child (stage, instructions); clutter_actor_set_x_align (instructions, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_y_align (instructions, CLUTTER_ACTOR_ALIGN_CENTER); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); g_signal_connect (stage, "key-release-event", G_CALLBACK (key_release_cb), box); clutter_actor_show (stage); clutter_main (); return 0; }
static void add_actor (ClutterActor *box, gint left, gint top, gint width, gint height) { ClutterLayoutManager *layout; ClutterActor *rect, *text; ClutterColor color; clutter_color_from_hls (&color, g_random_double_range (0.0, 360.0), 0.5, 0.5); color.alpha = 255; rect = clutter_actor_new (); clutter_actor_set_layout_manager (rect, clutter_bin_layout_new ()); clutter_actor_set_background_color (rect, &color); clutter_actor_set_reactive (rect, TRUE); if (random_size) clutter_actor_set_size (rect, g_random_int_range (40, 80), g_random_int_range (40, 80)); else clutter_actor_set_size (rect, 60, 60); clutter_actor_set_x_expand (rect, default_expand); clutter_actor_set_y_expand (rect, default_expand); if (!default_expand) { clutter_actor_set_x_align (rect, CLUTTER_ACTOR_ALIGN_CENTER); clutter_actor_set_y_align (rect, CLUTTER_ACTOR_ALIGN_CENTER); } if (random_align) { clutter_actor_set_x_align (rect, g_random_int_range (0, 3)); clutter_actor_set_y_align (rect, g_random_int_range (0, 3)); } text = clutter_text_new_with_text ("Sans 8px", NULL); clutter_text_set_line_alignment (CLUTTER_TEXT (text), PANGO_ALIGN_CENTER); clutter_actor_add_child (rect, text); g_signal_connect (rect, "button-release-event", G_CALLBACK (button_release_cb), NULL); g_signal_connect (rect, "notify::x-expand", G_CALLBACK (changed_cb), text); g_signal_connect (rect, "notify::y-expand", G_CALLBACK (changed_cb), text); g_signal_connect (rect, "notify::x-align", G_CALLBACK (changed_cb), text); g_signal_connect (rect, "notify::y-align", G_CALLBACK (changed_cb), text); layout = clutter_actor_get_layout_manager (box); if (use_box) clutter_actor_add_child (box, rect); else clutter_grid_layout_attach (CLUTTER_GRID_LAYOUT (layout), rect, left, top, width, height); changed_cb (rect, NULL, text); }
G_MODULE_EXPORT int test_shader_effects_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterActor *stage, *hand, *label, *rect; gchar *file; clutter_init (&argc, &argv); /* Make a timeline */ timeline = clutter_timeline_new (7692); clutter_timeline_set_loop (timeline, TRUE); stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Rotations"); clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Aluminium3); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); /* Make a hand */ file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); hand = clutter_texture_new_from_file (file, NULL); if (!hand) g_error("Unable to load '%s'", file); g_free (file); clutter_actor_set_position (hand, 326, 265); clutter_actor_add_effect_with_name (hand, "desaturate", clutter_desaturate_effect_new (0.75)); clutter_actor_add_effect_with_name (hand, "blur", clutter_blur_effect_new ()); clutter_actor_animate_with_timeline (hand, CLUTTER_LINEAR, timeline, "@effects.desaturate.factor", 1.0, "rotation-angle-z", 360.0, "fixed::anchor-x", 86.0, "fixed::anchor-y", 125.0, "opacity", 128, NULL); rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_DarkOrange); clutter_actor_add_effect_with_name (rect, "blur", clutter_blur_effect_new ()); clutter_actor_set_position (rect, 415, 215); clutter_actor_set_size (rect, 150, 150); clutter_actor_animate_with_timeline (rect, CLUTTER_LINEAR, timeline, "rotation-angle-z", 360.0, "fixed::anchor-x", 75.0, "fixed::anchor-y", 75.0, NULL); label = clutter_text_new_with_text ("Mono 16", "The Wonder\n" "of the\n" "Spinning Hand"); clutter_text_set_line_alignment (CLUTTER_TEXT (label), PANGO_ALIGN_CENTER); clutter_actor_set_position (label, 336, 275); clutter_actor_set_size (label, 500, 100); clutter_actor_animate_with_timeline (label, CLUTTER_LINEAR, timeline, "rotation-angle-z", 360.0, "fixed::anchor-x", 86.0, "fixed::anchor-y", 125.0, NULL); clutter_container_add (CLUTTER_CONTAINER (stage), rect, hand, label, NULL); /* start the timeline and thus the animations */ clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (timeline); return 0; }