Containers

Some clutter actors implement the Clutter::Container interface. These actors can contain child actors and may position them in relation to each other, for instance in a list or a table formation. In addition, transformations or property changes may be applied to all children. Child actors can be added to a container with the Clutter::Container::add_actor() method.

The main Clutter::Stage is itself a container, allowing it to contain all the child actors. The only other container in core Cluttermm is Clutter::Group, which can contain child actors, with positions relative to the parent Clutter::Group. Scaling, rotation and clipping of the group applies to the child actors, which can simplify your code.

Additional Clutter containers can be found in the Tidy toolkit library. See also the Implementing Containers section.

Clutter::Container class reference

Clutter::Group class reference

Example

The following example shows the use of the Clutter::Group container, with two child actors being rotated together.

Figure 5.3. Group

Group

Source code

File: main.cc

#include <cluttermm.h>

int main(int argc, char** argv)
{
  Clutter::init(&argc, &argv);

  // Get the stage and set its size and color:
  const Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
  stage->set_size(200, 200);
  stage->set_color(Clutter::Color(0, 0, 0, 0xFF)); // black

  // Add a group to the stage:
  const Glib::RefPtr<Clutter::Group> group = Clutter::Group::create();
  group->set_position(40, 40);
  stage->add_actor(group);
  group->show();

  const Clutter::Color actor_color (0xFF, 0xFF, 0xFF, 0x99);

  // Add a rectangle to the group:
  const Glib::RefPtr<Clutter::Rectangle>
    rect = Clutter::Rectangle::create(actor_color);
  rect->set_size(50, 50);
  rect->set_position(0, 0);
  group->add_actor(rect);
  rect->show();

  // Add a label to the group:
  const Glib::RefPtr<Clutter::Text>
    label = Clutter::Text::create("Sans 9", "Some Text", actor_color);
  label->set_position(0, 60);
  group->add_actor (label);
  label->show();

  // Scale the group 120% along the x axis:
  group->set_scale(3.00, 1.0);

  // Rotate it around the z axis:
  group->set_rotation(Clutter::Z_AXIS, 10, 0, 0, 0);

  // Show the stage:
  stage->show();

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

  return 0;
}