Groups

A group is a container for ordered collections of shapes, with the shapes at the top (front of the container) drawn last and the shapes at the bottom drawn first (end of the container).

The current implementation is very simplistic, and doesn't even try to do anything smart like taking into account occlusion or anything else. Instead all objects are simply drawn and it is left to cairo to take care of efficiency. At the current time there are no plans to improve this behavior, since it runs 'fast enough' for now.

Groups are also useful since transforms upon the group are also applied to the contained objects. Thus, scaling, translating or rotating a group has the same effect as performing those operations upon each member of the group.

The following contains an example that adds several shapes to a group, then rotates the entire group by 45 degrees counter-clockwise.

group.png

Group and shapes drawn by example code below

Group::pointer example_group(bool fill, bool outline) {
  // Create a group to contain several shapes
  Papyrus::Group::pointer group = Papyrus::Group::create( );

  // Create some shapes to add to the group
  Papyrus::Rectangle::pointer rectangle = example_rectangle( fill, outline );
  Papyrus::Circle::pointer circle = example_circle( fill, outline );
  Papyrus::Arc::pointer arc = example_arc( fill, outline );

  // Add the shapes to the group
  group->add( rectangle );
  group->add( circle );
  group->add( arc );

  // Translate the shapes so they don't necessarily overlap
  rectangle->set_xywh(0, -60, 50, 30);
  circle->set_translate(40, 20);
  circle->set_radius(25);
  arc->set_translate(0, 20);

  // Rotate the entire group by 45 degrees counter-clockwise
  group->rotate(-M_PI_4);

  return group;
}

Generated on Sun Mar 11 10:01:28 2007 by  doxygen 1.5.1