int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *actor; ClutterTimeline *timeline; ClutterAnimator *animator; 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_size (actor, 100, 100); clutter_actor_set_position (actor, 150, 50); timeline = clutter_timeline_new (2000); clutter_timeline_set_loop (timeline, TRUE); animator = clutter_animator_new (); clutter_animator_set_timeline (animator, timeline); clutter_animator_set (animator, actor, "x", CLUTTER_LINEAR, 0.0, 150.0, actor, "x", CLUTTER_LINEAR, 0.5, 50.0, actor, "x", CLUTTER_LINEAR, 1.0, 150.0, NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); g_signal_connect (stage, "key-press-event", G_CALLBACK (key_pressed_cb), timeline); clutter_actor_show (stage); clutter_main (); g_object_unref (animator); return EXIT_SUCCESS; }
/* add keys to the animator such that the actor is moved * to a random x position */ static void add_keys_for_actor (ClutterActor *actor, ClutterAnimator *animator) { gfloat x, end_x; x = clutter_actor_get_x (actor); end_x = 50.0; if (x == 50.0) end_x = 225.0 + (100.0 * rand () / (RAND_MAX + 1.0)); clutter_animator_set (animator, actor, "x", CLUTTER_LINEAR, 0.0, x, actor, "x", CLUTTER_EASE_OUT_CUBIC, 1.0, end_x, NULL); }
int main (int argc, char *argv[]) { State *state = g_new0 (State, 1); ClutterActor *stage; ClutterAnimator *animator; clutter_init (&argc, &argv); stage = clutter_stage_new (); clutter_actor_set_size (stage, 400, 400); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); state->red = clutter_rectangle_new_with_color (&red_color); clutter_actor_set_size (state->red, 100, 100); clutter_actor_set_position (state->red, 300, 300); state->green = clutter_rectangle_new_with_color (&green_color); clutter_actor_set_size (state->green, 100, 100); clutter_actor_set_position (state->green, 0, 0); animator = clutter_animator_new (); clutter_animator_set_duration (animator, 1000); clutter_animator_set (animator, state->red, "x", CLUTTER_LINEAR, 0.0, 300.0, state->red, "y", CLUTTER_LINEAR, 0.0, 300.0, state->red, "x", CLUTTER_LINEAR, 1.0, 0.0, state->red, "y", CLUTTER_EASE_IN_QUINT, 1.0, 0.0, NULL); clutter_animator_set (animator, state->green, "x", CLUTTER_LINEAR, 0.0, 0.0, state->green, "y", CLUTTER_LINEAR, 0.0, 0.0, state->green, "x", CLUTTER_LINEAR, 1.0, 300.0, state->green, "y", CLUTTER_EASE_IN_QUINT, 1.0, 300.0, NULL); state->timeline = clutter_animator_get_timeline (animator); clutter_timeline_set_auto_reverse (state->timeline, TRUE); g_signal_connect (stage, "key-press-event", G_CALLBACK (key_pressed_cb), state); clutter_container_add (CLUTTER_CONTAINER (stage), state->red, state->green, NULL); clutter_actor_show (stage); clutter_main (); g_object_unref (animator); g_free (state); return EXIT_SUCCESS; }
void mex_shell_present (MexShell *shell, ClutterActor *actor, MexShellDirection in) { GList *l; ClutterActor *stage; ClutterActorBox box; MexShellPrivate *priv; MexShellChildData *data; gfloat x, y, width, height; g_return_if_fail (MEX_IS_SHELL (shell)); g_return_if_fail (CLUTTER_IS_ACTOR (actor)); priv = shell->priv; l = g_list_find_custom (priv->children, actor, mex_shell_find_child); if (!l) { g_warning (G_STRLOC ": Attempted to present an unknown child."); return; } data = l->data; clutter_actor_get_allocation_box (CLUTTER_ACTOR (shell), &box); width = box.x2 - box.x1; height = box.y2 - box.y1; x = 0; y = 0; if (clutter_actor_get_opacity (data->child) == 0x00) { switch (in) { case MEX_SHELL_DIRECTION_NONE: clutter_actor_set_position (data->child, 0, 0); break; case MEX_SHELL_DIRECTION_TOP: clutter_actor_set_position (data->child, x, -height); break; case MEX_SHELL_DIRECTION_RIGHT: clutter_actor_set_position (data->child, width, y); break; default: case MEX_SHELL_DIRECTION_BOTTOM: clutter_actor_set_position (data->child, x, height); break; case MEX_SHELL_DIRECTION_LEFT: clutter_actor_set_position (data->child, -width, y); break; } data->last_direction = in; } clutter_animator_remove_key (data->animator, (GObject *)data->child, NULL, -1); clutter_animator_set (data->animator, data->child, "x", CLUTTER_LINEAR, 0.0, 0.f, data->child, "x", CLUTTER_EASE_OUT_QUAD, 1.0, x, data->child, "y", CLUTTER_LINEAR, 0.0, 0.f, data->child, "y", CLUTTER_EASE_OUT_QUAD, 1.0, y, data->child, "opacity", CLUTTER_LINEAR, 0.0, 0x00, data->child, "opacity", CLUTTER_EASE_OUT_QUAD, 0.1, 0xff, NULL); clutter_animator_property_set_ease_in (data->animator, (GObject *)data->child, "x", TRUE); clutter_animator_property_set_ease_in (data->animator, (GObject *)data->child, "y", TRUE); clutter_animator_property_set_ease_in (data->animator, (GObject *)data->child, "opacity", TRUE); data->start_animator = TRUE; if (priv->presented && (priv->presented != actor)) { MexShellDirection dir; l = g_list_find_custom (priv->children, priv->presented, mex_shell_find_child); if (!l) { g_warning (G_STRLOC ": Former presented actor is unknown"); return; } data = l->data; x = y = 0; switch (in) { case 0: x = y = 0; dir = 0; break; case MEX_SHELL_DIRECTION_TOP: y = height; dir = MEX_SHELL_DIRECTION_BOTTOM; break; case MEX_SHELL_DIRECTION_RIGHT: x = -width; dir = MEX_SHELL_DIRECTION_LEFT; break; case MEX_SHELL_DIRECTION_BOTTOM: y = -height; dir = MEX_SHELL_DIRECTION_TOP; break; default: case MEX_SHELL_DIRECTION_LEFT: x = width; dir = MEX_SHELL_DIRECTION_RIGHT; break; } data->last_direction = dir; clutter_animator_remove_key (data->animator, (GObject *)data->child, NULL, -1); clutter_animator_set (data->animator, data->child, "x", CLUTTER_LINEAR, 0.0, 0.f, data->child, "x", CLUTTER_EASE_OUT_QUAD, 1.0, x, data->child, "y", CLUTTER_LINEAR, 0.0, 0.f, data->child, "y", CLUTTER_EASE_OUT_QUAD, 1.0, y, data->child, "opacity", CLUTTER_LINEAR, 0.9, 0xff, data->child, "opacity", CLUTTER_EASE_OUT_QUAD, 1.0, 0x00, NULL); clutter_animator_property_set_ease_in (data->animator, (GObject *)data->child, "x", TRUE); clutter_animator_property_set_ease_in (data->animator, (GObject *)data->child, "y", TRUE); clutter_animator_property_set_ease_in (data->animator, (GObject *)data->child, "opacity", TRUE); data->start_animator = TRUE; } priv->presented = actor; stage = clutter_actor_get_stage (actor); if (stage) { MxFocusManager *manager = mx_focus_manager_get_for_stage ((ClutterStage *)stage); if (manager) { if (MX_IS_FOCUSABLE (actor)) mx_focus_manager_push_focus_with_hint (manager, MX_FOCUSABLE (shell), MX_FOCUS_HINT_PRIOR); else mx_focus_manager_move_focus (manager, MX_FOCUS_DIRECTION_OUT); } } clutter_actor_queue_redraw (CLUTTER_ACTOR (shell)); }
G_MODULE_EXPORT gint test_animator_main (gint argc, gchar **argv) { ClutterActor *stage; ClutterActor *rects[COUNT]; gint i; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); for (i=0; i<COUNT; i++) { rects[i]=new_rect (255 *(i * 1.0/COUNT), 50, 160, 255); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rects[i]); clutter_actor_set_anchor_point (rects[i], 64, 64); clutter_actor_set_position (rects[i], 320.0, 240.0); clutter_actor_set_opacity (rects[i], 0x70); } g_timeout_add (10000, nuke_one, rects[2]); animator = clutter_animator_new (); /* Note: when both animations are active for the same actor at the same * time there is a race, such races should be handled by avoiding * controlling the same properties from multiple animations. This is * an intentional design flaw of this test for testing the corner case. */ clutter_animator_set (animator, rects[0], "x", 1, 0.0, 180.0, rects[0], "x", CLUTTER_LINEAR, 0.25, 450.0, rects[0], "x", CLUTTER_LINEAR, 0.5, 450.0, rects[0], "x", CLUTTER_LINEAR, 0.75, 180.0, rects[0], "x", CLUTTER_LINEAR, 1.0, 180.0, rects[0], "y", -1, 0.0, 100.0, rects[0], "y", CLUTTER_LINEAR, 0.25, 100.0, rects[0], "y", CLUTTER_LINEAR, 0.5, 380.0, rects[0], "y", CLUTTER_LINEAR, 0.75, 380.0, rects[0], "y", CLUTTER_LINEAR, 1.0, 100.0, rects[3], "x", 0, 0.0, 180.0, rects[3], "x", CLUTTER_LINEAR, 0.25, 180.0, rects[3], "x", CLUTTER_LINEAR, 0.5, 450.0, rects[3], "x", CLUTTER_LINEAR, 0.75, 450.0, rects[3], "x", CLUTTER_LINEAR, 1.0, 180.0, rects[3], "y", 0, 0.0, 100.0, rects[3], "y", CLUTTER_LINEAR, 0.25, 380.0, rects[3], "y", CLUTTER_LINEAR, 0.5, 380.0, rects[3], "y", CLUTTER_LINEAR, 0.75, 100.0, rects[3], "y", CLUTTER_LINEAR, 1.0, 100.0, rects[2], "rotation-angle-y", 0, 0.0, 0.0, rects[2], "rotation-angle-y", CLUTTER_LINEAR, 1.0, 360.0, rects[1], "scale-x", 0, 0.0, 1.0, rects[1], "scale-x", CLUTTER_LINEAR, 1.0, 2.0, rects[1], "scale-y", 0, 0.0, 1.0, rects[1], "scale-y", CLUTTER_LINEAR, 1.0, 2.0, NULL); clutter_actor_set_scale (rects[0], 1.4, 1.4); clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "x", TRUE); clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "y", TRUE); clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]), "x", CLUTTER_INTERPOLATION_CUBIC); clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]), "y", CLUTTER_INTERPOLATION_CUBIC); clutter_stage_hide_cursor(CLUTTER_STAGE (stage)); clutter_actor_show (stage); clutter_animator_set_duration (animator, 5000); g_signal_connect (clutter_animator_start (animator), "completed", G_CALLBACK (reverse_timeline), NULL); clutter_main (); g_object_unref (animator); return EXIT_SUCCESS; }