示例#1
0
G_MODULE_EXPORT int
test_cairo_flowers_main (int argc, char **argv)
{
    Flower *flowers[N_FLOWERS];
    ClutterTimeline *timeline;
    int i;

    srand (time (NULL));

    if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
        return 1;

    /* Create a timeline to manage animation */
    timeline = clutter_timeline_new (6000);
    clutter_timeline_set_repeat_count (timeline, -1);

    stage = clutter_stage_new ();
    clutter_stage_set_title (CLUTTER_STAGE (stage), "Cairo Flowers");
    g_signal_connect (stage, "destroy", G_CALLBACK (stop_and_quit), timeline);

    clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black);

    for (i=0; i< N_FLOWERS; i++)
    {
        flowers[i]       = g_new0(Flower, 1);
        flowers[i]->ctex = make_flower_actor();
        flowers[i]->x    = rand() % (int) clutter_actor_get_width (stage)
                           - (PETAL_MIN + PETAL_VAR) * 2;
        flowers[i]->y    = rand() % (int) clutter_actor_get_height (stage);
        flowers[i]->rv   = rand() % 5 + 1;
        flowers[i]->v    = rand() % 10 + 2;

        clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                                     flowers[i]->ctex);
        clutter_actor_set_position (flowers[i]->ctex,
                                    flowers[i]->x, flowers[i]->y);
    }

    /* fire a callback for frame change */
    g_signal_connect (timeline, "new-frame", G_CALLBACK (tick), flowers);

    clutter_actor_show (stage);

    clutter_timeline_start (timeline);

    g_signal_connect (stage, "key-press-event",
                      G_CALLBACK (clutter_main_quit),
                      NULL);

    clutter_main();

    g_object_unref (timeline);

    return EXIT_SUCCESS;
}
示例#2
0
int
test_cairo_flowers_main (int argc, char **argv)
{
  int              i;
  ClutterActor    *stage;
  ClutterColor     stage_color = { 0x0, 0x0, 0x0, 0xff };
  ClutterTimeline *timeline;
  Flower          *flowers[N_FLOWERS];

  srand (time (NULL));

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  stage = clutter_stage_get_default ();

  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  for (i=0; i< N_FLOWERS; i++)
    {
      flowers[i]       = g_new0(Flower, 1);
      flowers[i]->ctex = make_flower_actor();
      flowers[i]->x    = rand() % (int) clutter_actor_get_width (stage)
                       - (PETAL_MIN + PETAL_VAR) * 2;
      flowers[i]->y    = rand() % (int) clutter_actor_get_height (stage);
      flowers[i]->rv   = rand() % 5 + 1;
      flowers[i]->v    = rand() % 10 + 2;

      clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                                   flowers[i]->ctex);
      clutter_actor_set_position (flowers[i]->ctex,
				  flowers[i]->x, flowers[i]->y);
    }

  /* Create a timeline to manage animation */
  timeline = clutter_timeline_new (6000);
  clutter_timeline_set_loop (timeline, TRUE);

  /* fire a callback for frame change */
  g_signal_connect (timeline, "new-frame", G_CALLBACK (tick), flowers);

  clutter_actor_show (stage);

  clutter_timeline_start (timeline);

  g_signal_connect (stage, "key-press-event",
		    G_CALLBACK (clutter_main_quit),
		    NULL);

  clutter_main();

  return EXIT_SUCCESS;
}