Пример #1
0
static void
mex_shell_paint (ClutterActor *actor)
{
  GList *c;
  MexShellPrivate *priv = MEX_SHELL (actor)->priv;

  CLUTTER_ACTOR_CLASS (mex_shell_parent_class)->paint (actor);

  for (c = priv->children; c; c = c->next)
    {
      gboolean do_paint;
      MexShellChildData *data = c->data;

      if (data->child == priv->presented)
        do_paint = TRUE;
      else if (data->start_animator)
        do_paint = TRUE;
      else if (clutter_timeline_is_playing (
                 clutter_animator_get_timeline (data->animator)))
        do_paint = TRUE;
      else
        do_paint = FALSE;

      if (do_paint)
        clutter_actor_paint (((MexShellChildData *)c->data)->child);

      if (data->start_animator)
        {
          clutter_animator_start (data->animator);
          data->start_animator = FALSE;
        }
    }
}
static gboolean
move_actors (ClutterActor *actor,
             ClutterEvent *event,
             gpointer      user_data)
{
  State *state = user_data;
  ClutterActor *child;

  /* do nothing if the animator is already running */
  if (clutter_timeline_is_playing (clutter_animator_get_timeline (state->animator)))
    return TRUE;

  /* remove all keys from the animator */
  clutter_animator_remove_key (state->animator, NULL, NULL, -1);

  /* add keys for all actors in the group */
  for (child = clutter_actor_get_first_child (state->group);
       child != NULL;
       child = clutter_actor_get_next_sibling (child))
    {
      add_keys_for_actor (child, state->animator);
    }

  /* start the animation */
  clutter_animator_start (state->animator);

  return TRUE;
}
Пример #3
0
gboolean
foo_button_pressed_cb (ClutterActor *actor,
                       ClutterEvent *event,
                       gpointer      user_data)
{
  ClutterScript *ui = CLUTTER_SCRIPT (user_data);
  ClutterStage *stage = CLUTTER_STAGE (clutter_script_get_object (ui, "stage"));

  ClutterScript *script;
  ClutterActor *rig;
  ClutterAnimator *animator;

  /* load the rig and its animator from a JSON file */
  script = clutter_script_new ();

  /* use a function defined statically in this source file to load the JSON */
  load_script_from_file (script, ANIMATION_FILE);

  clutter_script_get_objects (script,
                              "rig", &rig,
                              "animator", &animator,
                              NULL);

  /* remove the button press handler from the rectangle */
  g_signal_handlers_disconnect_matched (actor,
                                        G_SIGNAL_MATCH_FUNC,
                                        0,
                                        0,
                                        NULL,
                                        foo_button_pressed_cb,
                                        NULL);

  /* add a callback to clean up the script when the rig is destroyed */
  g_object_set_data_full (G_OBJECT (rig), "script", script, g_object_unref);

  /* add the rig to the stage */
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig);

  /* place the rig at the same coordinates on the stage as the rectangle */
  clutter_actor_set_position (rig,
                              clutter_actor_get_x (actor),
                              clutter_actor_get_y (actor));

  /* put the rectangle into the top-left corner of the rig */
  clutter_actor_reparent (actor, rig);

  clutter_actor_set_position (actor, 0, 0);

  /* animate the rig */
  clutter_animator_start (animator);

  return TRUE;
}
Пример #4
0
/*
 * start the animation when a key is pressed;
 * see the signals recipe in the Script chapter for more details
 */
gboolean
foo_key_pressed_cb (ClutterActor *actor,
                    ClutterEvent *event,
                    gpointer      user_data)
{
  ClutterScript *script = CLUTTER_SCRIPT (user_data);

  ClutterAnimator *animator;
  clutter_script_get_objects (script,
                              "animator", &animator,
                              NULL);

  if (clutter_timeline_is_playing (clutter_animator_get_timeline (animator)))
    return FALSE;

  clutter_animator_start (animator);

  return TRUE;
}
Пример #5
0
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;
}