int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *actor; ClutterState *transitions; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 300, 200); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); actor = clutter_rectangle_new_with_color (&red_color); clutter_actor_set_position (actor, 150, 50); clutter_actor_set_size (actor, 100, 100); transitions = clutter_state_new (); clutter_state_set_duration (transitions, NULL, NULL, 1000); clutter_state_set (transitions, NULL, "right", actor, "x", CLUTTER_LINEAR, 150.0, NULL); clutter_state_set (transitions, NULL, "left", actor, "x", CLUTTER_LINEAR, 50.0, NULL); clutter_state_warp_to_state (transitions, "right"); g_signal_connect (stage, "key-press-event", G_CALLBACK (key_pressed_cb), transitions); g_signal_connect (transitions, "completed", G_CALLBACK (next_state), NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); clutter_actor_show (stage); clutter_main (); g_object_unref (transitions); return EXIT_SUCCESS; }
static void clutter_widget_init ( ClutterWidget *_self ) { ClutterWidgetPrivate *priv; ClutterAction *action; ClutterState *state; _self->priv = priv = CLUTTER_WIDGET_GET_PRIVATE (_self); priv->borderColor = *CLUTTER_COLOR_LightGray; clutter_actor_set_reactive ( CLUTTER_ACTOR(_self), TRUE ); // TODO: only in drag-bar { action = clutter_drag_action_new (); clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action), 0, 0); clutter_drag_action_set_drag_axis ( CLUTTER_DRAG_ACTION (action), CLUTTER_DRAG_X_AXIS&CLUTTER_DRAG_Y_AXIS ); g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL); g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL); clutter_actor_add_action (CLUTTER_ACTOR(_self), action); clutter_actor_add_effect_with_name (CLUTTER_ACTOR(_self), "disable", clutter_desaturate_effect_new (0.0)); // } TODO end // init state machine state = clutter_state_new (); g_object_set_data_full ( G_OBJECT (_self), "hover-state-machine", state, g_object_unref ); g_signal_connect ( _self, "enter-event", G_CALLBACK (on_enter), state ); g_signal_connect ( _self, "leave-event", G_CALLBACK (on_leave), state ); clutter_state_set ( state, NULL, "normal", _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_DarkGray, NULL ); clutter_state_set ( state, NULL, "hover", _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_LightSkyBlue, NULL ); clutter_state_set_duration ( state, NULL, NULL, 200 ); // set init state clutter_state_set_state (state, "normal"); }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *texture; ClutterState *transitions; GError *error = NULL; gfloat texture_width, texture_height; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); texture = clutter_texture_new (); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_texture_set_sync_size (CLUTTER_TEXTURE (texture), TRUE); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), TESTS_DATA_DIR "/redhand.png", &error); if (error != NULL) { g_error ("Problem loading image into texture - %s", error->message); g_error_free (error); return 1; } clutter_actor_get_size (texture, &texture_width, &texture_height); clutter_actor_set_size (stage, texture_width * 2, texture_height * 2); /* set all centres of rotation to the centre of the texture */ clutter_actor_set_rotation (texture, CLUTTER_X_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_rotation (texture, CLUTTER_Y_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_z_rotation_from_gravity (texture, 0.0, CLUTTER_GRAVITY_CENTER); clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture); /* set up the animations */ transitions = clutter_state_new (); clutter_state_set (transitions, NULL, "start", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-z", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "x-cw", texture, "rotation-angle-x", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-ccw", texture, "rotation-angle-x", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-after", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "y-cw", texture, "rotation-angle-y", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-ccw", texture, "rotation-angle-y", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-after", texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "z-cw", texture, "rotation-angle-z", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "z-ccw", texture, "rotation-angle-z", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set_duration (transitions, NULL, NULL, DURATION); clutter_state_set_duration (transitions, "start", NULL, DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "start", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "x-after", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "y-after", DURATION * 0.5); clutter_state_warp_to_state (transitions, "start"); g_signal_connect (transitions, "completed", G_CALLBACK (_set_next_state), NULL); clutter_state_set_state (transitions, "x-cw"); clutter_actor_show (stage); clutter_main (); return 0; }
G_MODULE_EXPORT gint test_state_main (gint argc, gchar **argv) { ClutterColor black={0,0,0,0xff}; ClutterActor *stage; ClutterState *layout_state; gint i; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); layout_state = clutter_state_new (); clutter_stage_set_color (CLUTTER_STAGE (stage), &black); clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); g_signal_connect (stage, "button-press-event", G_CALLBACK (press_event), layout_state); g_signal_connect (stage, "button-release-event", G_CALLBACK (release_event), layout_state); for (i=0; i<TOTAL; i++) { ClutterActor *actor; ClutterState *a_state; int row = i/COLS; int col = i%COLS; actor = new_rect (255 * ( 1.0*col/COLS), 50, 255 * ( 1.0*row/ROWS), 255); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); clutter_actor_set_position (actor, 320.0, 240.0); clutter_actor_set_reactive (actor, TRUE); clutter_state_set (layout_state, NULL, "active", actor, "delayed::x", CLUTTER_LINEAR, ACTOR_WIDTH * 1.0 * ((TOTAL-1-i) % COLS), ((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2, actor, "delayed::y", CLUTTER_LINEAR, ACTOR_HEIGHT * 1.0 * ((TOTAL-1-i) / COLS), ((row*1.0/ROWS))/2, 0.0, actor, "rotation-angle-x", CLUTTER_LINEAR, 0.0, actor, "rotation-angle-y", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (layout_state, NULL, "right", actor, "delayed::x", CLUTTER_LINEAR, STAGE_WIDTH * 1.0, ((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2, actor, "delayed::y", CLUTTER_LINEAR, STAGE_HEIGHT * 1.0, ((row*1.0/ROWS))/2, 0.0, NULL); clutter_state_set (layout_state, NULL, "left", actor, "rotation-angle-x", CLUTTER_LINEAR, 45.0, actor, "rotation-angle-y", CLUTTER_LINEAR, 5.0, actor, "x", CLUTTER_LINEAR, 0-64.0, actor, "y", CLUTTER_LINEAR, 0-64.0, NULL); a_state = clutter_state_new (); g_object_set_data_full (G_OBJECT (actor), "hover-state-machine", a_state, g_object_unref); g_signal_connect (actor, "enter-event", G_CALLBACK (enter_event), a_state); g_signal_connect (actor, "leave-event", G_CALLBACK (leave_event), a_state); clutter_state_set (a_state, NULL, "normal", actor, "opacity", CLUTTER_LINEAR, 0x77, actor, "rotation-angle-z", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (a_state, NULL, "hover", actor, "opacity", CLUTTER_LINEAR, 0xff, actor, "rotation-angle-z", CLUTTER_LINEAR, 10.0, NULL); clutter_actor_set_opacity (actor, 0x77); clutter_state_set_duration (a_state, NULL, NULL, 500); } clutter_state_set_duration (layout_state, NULL, NULL, 1000); clutter_state_set_duration (layout_state, "active", "left", 1400); g_signal_connect (layout_state, "completed", G_CALLBACK (completed), NULL); clutter_actor_show (stage); clutter_state_warp_to_state (layout_state, "left"); clutter_state_set_state (layout_state, "active"); clutter_main (); g_object_unref (layout_state); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { GError *error = NULL; /* UI */ ClutterActor *stage; ClutterLayoutManager *layout; ClutterActor *box; ClutterActor *top, *bottom; ClutterState *transitions; clutter_init_with_args (&argc, &argv, " - cross-fade", entries, NULL, NULL); if (source == NULL || target == NULL) { g_print ("Usage: %s -s <source> -t <target> [-d <duration>]\n", argv[0]); exit (EXIT_FAILURE); } clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_title (CLUTTER_STAGE (stage), "cross-fade"); clutter_actor_set_size (stage, 400, 300); clutter_actor_show (stage); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_box_new (layout); clutter_actor_set_size (box, 400, 300); bottom = clutter_texture_new (); top = clutter_texture_new (); clutter_container_add_actor (CLUTTER_CONTAINER (box), bottom); clutter_container_add_actor (CLUTTER_CONTAINER (box), top); clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); /* load the first image into the bottom */ load_image (CLUTTER_TEXTURE (bottom), source); /* load the second image into the top */ load_image (CLUTTER_TEXTURE (top), target); /* animations */ transitions = clutter_state_new (); clutter_state_set (transitions, NULL, "show-bottom", top, "opacity", CLUTTER_LINEAR, 0, bottom, "opacity", CLUTTER_LINEAR, 255, NULL); clutter_state_set (transitions, NULL, "show-top", top, "opacity", CLUTTER_EASE_IN_CUBIC, 255, bottom, "opacity", CLUTTER_EASE_IN_CUBIC, 0, NULL); clutter_state_set_duration (transitions, NULL, NULL, duration); /* make the bottom opaque and top transparent */ clutter_state_warp_to_state (transitions, "show-bottom"); /* on key press, fade in the top texture and fade out the bottom texture */ g_signal_connect (stage, "key-press-event", G_CALLBACK (start_animation), transitions); clutter_actor_show (stage); clutter_main (); g_object_unref (transitions); if (error != NULL) g_error_free (error); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *texture; ClutterEffect *effect; ClutterState *transitions; GError *error = NULL; gchar *filename; if (argc < 2) { g_print ("Usage: %s <path to image file>\n", argv[0]); return EXIT_FAILURE; } filename = argv[1]; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_actor_set_size (stage, 400, 300); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); texture = clutter_texture_new (); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture), TRUE); clutter_actor_set_width (texture, 400); clutter_actor_set_reactive (texture, TRUE); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), filename, &error); if (error != NULL) { g_critical ("Error loading texture from file %s; error was:\n%s", filename, error->message); return EXIT_FAILURE; } /* create the page fold effect instance with destination fold angle * of 180 degrees and starting period of 0 (no folding) */ effect = cb_page_fold_effect_new (180.0, 0.0); /* add the effect to the texture actor */ clutter_actor_add_effect (texture, effect); clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture); /* animation for the period property of the effect, * to animate its value between 0.0 and 1.0 and back */ transitions = clutter_state_new (); clutter_state_set_duration (transitions, NULL, NULL, 500); clutter_state_set_duration (transitions, "partially-folded", "folded", 375); clutter_state_set (transitions, NULL, "folded", effect, "period", CLUTTER_LINEAR, 1.0, NULL); clutter_state_set (transitions, NULL, "partially-folded", effect, "period", CLUTTER_LINEAR, 0.25, NULL); clutter_state_set (transitions, NULL, "unfolded", effect, "period", CLUTTER_LINEAR, 0.0, NULL); clutter_state_warp_to_state (transitions, "partially-folded"); g_signal_connect (texture, "button-press-event", G_CALLBACK (button_pressed_cb), transitions); clutter_actor_show (stage); clutter_main (); g_object_unref (transitions); 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; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *red; ClutterActor *green; ClutterState *transitions; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 650, 500); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); /* actor names choose the next ClutterState to transition to */ red = clutter_rectangle_new_with_color (&red_color); clutter_actor_set_reactive (red, TRUE); clutter_actor_set_name (red, "red"); clutter_actor_set_size (red, 100, 100); clutter_actor_set_position (red, 50, 50); green = clutter_rectangle_new_with_color (&green_color); clutter_actor_set_reactive (green, TRUE); clutter_actor_set_name (green, "green"); clutter_actor_set_size (green, 100, 100); clutter_actor_set_position (green, 50, 350); transitions = clutter_state_new (); clutter_state_set_duration (transitions, NULL, NULL, 250); /* state names match actor names */ clutter_state_set (transitions, NULL, "red", red, "x", CLUTTER_EASE_OUT_CUBIC, 200.0, red, "y", CLUTTER_EASE_OUT_CUBIC, 50.0, red, "scale-x", CLUTTER_EASE_OUT_CUBIC, 4.0, red, "scale-y", CLUTTER_EASE_OUT_CUBIC, 4.0, green, "x", CLUTTER_EASE_OUT_CUBIC, 50.0, green, "y", CLUTTER_EASE_OUT_CUBIC, 350.0, green, "scale-x", CLUTTER_EASE_OUT_CUBIC, 1.0, green, "scale-y", CLUTTER_EASE_OUT_CUBIC, 1.0, NULL); clutter_state_set (transitions, NULL, "green", green, "x", CLUTTER_EASE_OUT_CUBIC, 200.0, green, "y", CLUTTER_EASE_OUT_CUBIC, 50.0, green, "scale-x", CLUTTER_EASE_OUT_CUBIC, 4.0, green, "scale-y", CLUTTER_EASE_OUT_CUBIC, 4.0, red, "x", CLUTTER_EASE_OUT_CUBIC, 50.0, red, "y", CLUTTER_EASE_OUT_CUBIC, 50.0, red, "scale-x", CLUTTER_EASE_OUT_CUBIC, 1.0, red, "scale-y", CLUTTER_EASE_OUT_CUBIC, 1.0, NULL); g_signal_connect (red, "button-press-event", G_CALLBACK (button_pressed_cb), transitions); g_signal_connect (green, "button-press-event", G_CALLBACK (button_pressed_cb), transitions); clutter_container_add (CLUTTER_CONTAINER (stage), red, green, NULL); clutter_actor_show (stage); clutter_main (); g_object_unref (transitions); return EXIT_SUCCESS; }