int main (int argc, char *argv[]) { ClutterActor *stage; ClutterPath *path; ClutterConstraint *constraint; ClutterActor *rectangle; ClutterTimeline *timeline; const ClutterColor *stage_color = clutter_color_new (51, 51, 85, 255); const ClutterColor *red_color = clutter_color_new (255, 0, 0, 255); clutter_init (&argc, &argv); stage = clutter_stage_new (); clutter_actor_set_size (stage, 360, 300); clutter_stage_set_color (CLUTTER_STAGE (stage), stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); /* create the path */ path = clutter_path_new (); clutter_path_add_move_to (path, 30, 60); /* add a curve round to the top-right of the stage */ clutter_path_add_rel_curve_to (path, 120, 180, 180, 120, 240, 0); /* create a constraint based on the path */ constraint = clutter_path_constraint_new (path, 0.0); /* put a rectangle at the start of the path */ rectangle = clutter_rectangle_new_with_color (red_color); clutter_actor_set_size (rectangle, 60, 60); /* add the constraint to the rectangle */ clutter_actor_add_constraint_with_name (rectangle, "path", constraint); /* add the rectangle to the stage */ clutter_container_add_actor (CLUTTER_CONTAINER (stage), rectangle); /* set up the timeline */ timeline = clutter_timeline_new (1000); clutter_timeline_set_loop (timeline, TRUE); clutter_timeline_set_auto_reverse (timeline, TRUE); clutter_actor_animate_with_timeline (rectangle, CLUTTER_LINEAR, timeline, "@constraints.path.offset", 1.0, NULL); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
static gboolean path_test_add_move_to (CallbackData *data) { ClutterPathNode node = { 0, }; node.type = CLUTTER_PATH_MOVE_TO; node.points[0].x = 1; node.points[0].y = 2; clutter_path_add_move_to (data->path, node.points[0].x, node.points[0].y); data->nodes[data->n_nodes++] = node; return TRUE; }
/** * clutter_behaviour_path_new_with_knots: * @alpha: (allow-none): a #ClutterAlpha instance, or %NULL * @knots: an array of #ClutterKnot<!-- -->s * @n_knots: number of entries in @knots * * Creates a new path behaviour that will make the actors visit all of * the given knots in order with straight lines in between. * * A path will be created where the first knot is used in a * %CLUTTER_PATH_MOVE_TO and the subsequent knots are used in * %CLUTTER_PATH_LINE_TO<!-- -->s. * * If @alpha is not %NULL, the #ClutterBehaviour will take ownership * of the #ClutterAlpha instance. In the case when @alpha is %NULL, * it can be set later with clutter_behaviour_set_alpha(). * * Return value: (transfer full): a #ClutterBehaviour * * Since: 1.0 * * Deprecated: 1.6 */ ClutterBehaviour * clutter_behaviour_path_new_with_knots (ClutterAlpha *alpha, const ClutterKnot *knots, guint n_knots) { ClutterPath *path = clutter_path_new (); guint i; if (n_knots > 0) { clutter_path_add_move_to (path, knots[0].x, knots[0].y); for (i = 1; i < n_knots; i++) clutter_path_add_line_to (path, knots[i].x, knots[i].y); } return g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH, "alpha", alpha, "path", path, NULL); }