drawing-item.cpp revision 28f74a03fc1d9ebe507ee0c8f6c361c06c2ea27e
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Canvas item belonging to an SVG drawing element.
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Krzysztof KosiĆski <tweenk.pl@gmail.com>
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Copyright (C) 2011 Authors
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen * Released under GNU GPL, read the file 'COPYING' for more information
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * @class DrawingItem
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * SVG drawing item for display.
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen * This was previously known as NRArenaItem. It represents the renderable
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * portion of the SVG document. Typically this is created by the SP tree,
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen * in particular the show() virtual function.
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen * @section ObjectLifetime Object lifetime
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Deleting a DrawingItem will cause all of its children to be deleted as well.
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * This can lead to nasty surprises if you hold references to things
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen * which are children of what is being deleted. Therefore, in the SP tree,
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * you always need to delete the item views of children before deleting
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen * the view of the parent. Do not call delete on things returned from show()
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen * - this will cause dangling pointers inside the SPItem and lead to a crash.
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen * Use the corresponing hide() method.
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Outside of the SP tree, you should not use any references after the root node
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * has been deleted.
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix// , _renders_opacity(0)
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix //if (!_children.empty()) {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // g_warning("Removing item with children");
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // remove from the set of cached items and delete cache
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix setCached(false, true);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // remove this item from parent's children list
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // due to the effect of clearChildren(), this only happens for the top-level deleted item
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix ChildrenList::iterator ithis = _parent->_children.iterator_to(*this);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // we cannot call setClip(NULL) or setMask(NULL),
7655c8b8ffe3674dd7e7c74f450fb7194943c0deJon A. Cruz // because that would be an endless loop
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen _parent->_markForUpdate(STATE_ALL, false);
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilix // initially I wanted to return NULL if we are a clip or mask child,
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen // but the previous behavior was just to return the parent regardless of child type
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix/// Returns true if item is among the descendants. Will return false if item == this.
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix for (DrawingItem *i = item->_parent; i; i = i->_parent) {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix if (i == this) return true;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix/// Delete all regular children of this item (not mask or clip).
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // prevent children from referencing the parent during deletion
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // this way, children won't try to remove themselves from a list
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // from which they have already been removed by clear_and_dispose
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix/// Set the incremental transform for this item
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixDrawingItem::setTransform(Geom::Affine const &new_trans)
if (_transform) {
_visible = v;
_sensitive = s;
if (cache_env) return;
if (cached) {
delete _cache;
delete _clip;
if (item) {
delete _mask;
if (item) {
if (!_parent) return;
DrawingItem::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset)
_propagate_state = 0;
_background_accumulate = true;
if (_transform) {
if (_clip) {
if (outline) {
if (_mask) {
if (outline) {
if (_has_cache_iterator) {
_has_cache_iterator = false;
_has_cache_iterator = true;
if (_cache) {
delete _cache;
struct MaskLuminanceToAlpha {
DrawingItem::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags, DrawingItem *stop_at)
if (outline) {
return RENDER_OK;
if (_cached) {
if (_cache) {
if (cl) {
bool needs_intermediate_rendering = false;
if (_clip) {
if (_mask) {
bool rendered = false;
if (bg_root) {
rendered = true;
if (!rendered) {
return render_result;
if (!carea) return;
if (_clip) {
if (_mask) {
if (!_canClip()) return;
if (!_visible) return;
if (_clip) {
if (_clip) {
return NULL;
return NULL;
if (_clip) {
if (_mask) {
return NULL;
if (!dirty) return;
if (i != this && i->_filter) {
if (i->_cache) {
if (i->_background_accumulate) {
bkg_root = i;
if (bkg_root) {
if (propagate) {
if (_parent) {
if (!_filter) {
delete _filter;
_background_new = true;
_background_new = false;
if (_mask) {
return score;