#include <papyrus/group.h>
Inheritance diagram for Papyrus::Group:
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.
Group contain an ordered set of shapes
Public Types | |
typedef PapyrusSmartPointer< Group > | pointer |
typedef std::list< Drawable::pointer > | Layer |
A layer is a list of child items. | |
typedef std::map< int, Layer > | Layers |
Layers are drawn starting for the lowest numbered layer to the highest layer. | |
Public Member Functions | |
virtual bool | add (Drawable::pointer item, int layer=0, bool drawing_only=false) |
Adds a child to a given layer. | |
virtual bool | remove (Drawable::pointer object) |
Removes the object from the group. | |
virtual bool | remove (Drawable *object) |
The main purpose of this method is so that a child may use the this pointer to remove itself on destruction. | |
virtual bool | clear () |
Clears all layers and children from the group. | |
virtual bool | raise (Drawable::pointer item, int steps=1) |
Raises the item up n steps in its layer. | |
virtual bool | raise_to_top (Drawable::pointer item) |
Raises the item up to the top of its layer. | |
virtual bool | lower (Drawable::pointer item, int steps=1) |
Lowers the item down n steps in its layer. | |
virtual bool | lower_to_bottom (Drawable::pointer item) |
Lowers the item up to the bottom of its layer. | |
virtual bool | move_to_layer (int layer, Drawable::pointer item) |
Moves an item to a specific layer. | |
size_t | size () const |
Returns the number of children in the group. | |
const Layers & | layers () const |
Returns the layers in this group. | |
const Layer & | layer (int l) const throw (std::out_of_range) |
Returns the requested layer l or throws std::out_of_range if the layer doesn't exist. | |
bool | has_layer (int l) |
True if this group has layer l. | |
virtual bool | inside (double x, double y) |
Overrides parent method for determining whether (x,y) is inside the drawable. | |
virtual std::vector< Drawable::pointer > | select (double x, double y, unsigned depth=1) |
sigc::signal< void, Drawable::pointer > & | signal_child_added () |
sigc::signal< void, Drawable::pointer > & | signal_child_removed () |
virtual bool | is_group () |
PAPYRUS_CLASS_NAME ("Group") | |
PAPYRUS_CLONE_METHOD (Group) | |
Static Public Member Functions | |
static pointer | create () |
Protected Types | |
typedef std::map< Drawable::pointer, sigc::connection > | Connections |
Protected Member Functions | |
virtual void | on_child_changed (Drawable::pointer child) |
Virtual method called when a child is changed. | |
virtual void | update_extents () |
Virtual method that recalculates the extents and emits the changed signal. | |
void | on_child_need_redraw (double x, double y, double w, double h, Drawable::pointer child) |
virtual void | draw (Cairo::RefPtr< Cairo::Context > cairo) |
virtual void | rebuild_extents () |
Protected Attributes | |
Layers | m_layers |
size_t | m_size |
Connections | m_redraw_connections |
Connections | m_changed_connections |
sigc::signal< void, Drawable::pointer > | m_signal_child_added |
sigc::signal< void, Drawable::pointer > | m_signal_child_removed |
Friends | |
class | Canvas |
typedef std::list<Drawable::pointer> Papyrus::Group::Layer |
A layer is a list of child items.
The children are drawn starting with the last item in the list, proceeding forward to the first item. Thus, the first item in the list will be drawn on top of all 'lower' items.
bool Papyrus::Group::add | ( | Drawable::pointer | item, | |
int | layer = 0 , |
|||
bool | drawing_only = false | |||
) | [virtual] |
Adds a child to a given layer.
Layer 0 is the default layer. Layers are drawn from the most negative to the most positive. Thus, layer 0 is on top of layer -1, and layer 1 is on top of layer 0.
bool Papyrus::Group::raise | ( | Drawable::pointer | item, | |
int | steps = 1 | |||
) | [virtual] |
Raises the item up n steps in its layer.
If steps < 0, the effect is a lower operation.
bool Papyrus::Group::lower | ( | Drawable::pointer | item, | |
int | steps = 1 | |||
) | [virtual] |
Lowers the item down n steps in its layer.
If steps < 0, the effect is a raise operation.
bool Papyrus::Group::lower_to_bottom | ( | Drawable::pointer | item | ) | [virtual] |
Lowers the item up to the bottom of its layer.
Returns true if the item is lowered or already at the bottom, and false if the item cannot be found.
bool Papyrus::Group::move_to_layer | ( | int | layer, | |
Drawable::pointer | item | |||
) | [virtual] |
Moves an item to a specific layer.
The item must already be in this group or no action will be taken.
const Group::Layer & Papyrus::Group::layer | ( | int | l | ) | const throw (std::out_of_range) |
Returns the requested layer l or throws std::out_of_range if the layer doesn't exist.
To avoid throwing an error, check has_layer() before calling.
bool Papyrus::Group::inside | ( | double | x, | |
double | y | |||
) | [virtual] |
Overrides parent method for determining whether (x,y) is inside the drawable.
If the group itself is selectable, performs a simple extents test. If the group is not selectable, performs a test on each of the children, returning true if any of the children are selectable.
Reimplemented from Papyrus::Drawable.
void Papyrus::Group::on_child_changed | ( | Drawable::pointer | child | ) | [protected, virtual] |
Virtual method called when a child is changed.
Parameters indicate which child changed and contain hint as to which aspect of the child changed.
When a child is added, the child's changed signal is actually connected to the private proxy method, which in turn calls the virtual method. This allows children to implement their own behavior by reimplementing this method without worrying about modifying the add() or remove() methods.
void Papyrus::Group::update_extents | ( | ) | [protected, virtual] |
Virtual method that recalculates the extents and emits the changed signal.
Children should reimplement this method if they need to perform special behavior when an event occurs that could effect the extents, and that behavior needs to take place before the signal is emitted.