Transformations

Actors can be scaled, rotated, and moved.

Scaling

Call clutter_actor_set_scale() to increase or decrease the apparent size of the actor. Note that this will not change the result of clutter_actor_get_width() and clutter_actor_get_height() because it only changes the size of the actor as seen by the user. Calling clutter_actor_set_scale() again will replace the first scale rather than multiplying it.

Rotation

Call clutter_actor_set_rotation() to rotate the actor around an axis, specifying either CLUTTER_X_AXIS, CLUTTER_Y_AXIS or CLUTTER_Z_AXIS and the desired angle. Only two of the x, y, and z coordinates are used, depending on the specified axis. For instance, when using CLUTTER_X_AXIS, the y and z parameters specify the center of rotation on the plane of the x axis.

Like the clutter_actor_set_scale(), this does not affect the position, width, or height of the actor as returned by functions such as clutter_actor_get_x().

Clipping

Actors may be "clipped" so that only one rectangular part of the actor is visible, by calling clutter_actor_set_clip(), providing a position relative to the actor, along with the size. For instance, you might implement scrolling by creating a large container actor and setting a clip rectangle so that only a small part of the whole is visible at any one time. Scrolling up could then be implemented by moving the actor down while moving the clip up. Clipping can be reverted by calling clutter_actor_remove_clip().

The area outside of the clip does not consume video memory and generally does not require much processing.

Movement

Clutter does not have a translation function that behaves similarly to clutter_actor_set_scale() and clutter_actor_set_rotation(), but you can move the actor by calling clutter_actor_move_by() or clutter_actor_set_depth.

Unlike the scaling and rotation functions, clutter_actor_move_by() does change the result of functions such as clutter_actor_get_x().

Example

The following example demonstrates two unmoving actors in a stage, using rotation, scaling and movement:

Figure 5.2. Actor

Actor

Source Code

File: main.c

#include <clutter/clutter.h>
#include <stdlib.h>


int main(int argc, char *argv[])
{
  ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
  ClutterColor actor_color = { 0xff, 0xff, 0xff, 0x99 };

  clutter_init (&argc, &argv);

  /* Get the stage and set its size and color: */
  ClutterActor *stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 200, 200);
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  /* Add a rectangle to the stage: */
  ClutterActor *rect = clutter_rectangle_new_with_color (&actor_color);
  clutter_actor_set_size (rect, 100, 100);
  clutter_actor_set_position (rect, 20, 20);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
  clutter_actor_show (rect);

  /* Rotate it 20 degrees away from us around the x axis
   * (around its top edge)
   */
  clutter_actor_set_rotation (rect, CLUTTER_X_AXIS, -20, 0, 0, 0);


  /* Add a label to the stage: */
  ClutterActor *label = clutter_text_new_full ("Sans 12", "Some Text", &actor_color);
  clutter_actor_set_size (label, 500, 500);
  clutter_actor_set_position (label, 20, 150);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
  clutter_actor_show (label);

  /* Scale it 300% along the x axis:
   */
  clutter_actor_set_scale (label, 3.00, 1.0);

  /* Move it up and to the right: */
  clutter_actor_move_by (label, 10, -10);

  /* Move it along the z axis, further from the viewer: */
  clutter_actor_set_depth (label, -20);


  /* Show the stage: */
  clutter_actor_show (stage);

  /* Start the main loop, so we can respond to events: */
  clutter_main ();

  return EXIT_SUCCESS;

}