Esempio n. 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;
}
Esempio n. 3
0
static void
mex_shell_child_data_free (MexShell *self, MexShellChildData *data)
{
  ClutterTimeline *timeline = clutter_animator_get_timeline (data->animator);

  if (clutter_timeline_is_playing (timeline))
    mex_shell_timeline_completed_cb (timeline, self);

  clutter_animator_remove_key (data->animator, NULL, NULL, -1);
  g_object_unref (data->animator);
  g_slice_free (MexShellChildData, data);
}
Esempio n. 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;
}
Esempio n. 5
0
static MexShellChildData *
mex_shell_child_data_new (MexShell *self, ClutterActor *child)
{
  ClutterTimeline *timeline;

  MexShellChildData *data = g_slice_new0 (MexShellChildData);
  data->child = child;
  data->animator = clutter_animator_new ();
  data->last_direction = MEX_SHELL_DIRECTION_RIGHT;

  clutter_animator_set_duration (data->animator, 250);

  timeline = clutter_animator_get_timeline (data->animator);
  g_signal_connect (timeline, "started",
                    G_CALLBACK (mex_shell_timeline_started_cb), self);
  g_signal_connect (timeline, "completed",
                    G_CALLBACK (mex_shell_timeline_completed_cb), self);

  return data;
}
Esempio n. 6
0
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;
}