drawing-item.h revision d1bde559850436556ebee2e70e10f1cfc8aff636
044d712d4d03f8354962d54e47cfac2346a69ccccilix/**
044d712d4d03f8354962d54e47cfac2346a69ccccilix * @file
044d712d4d03f8354962d54e47cfac2346a69ccccilix * @brief Canvas item belonging to an SVG drawing element
044d712d4d03f8354962d54e47cfac2346a69ccccilix *//*
044d712d4d03f8354962d54e47cfac2346a69ccccilix * Authors:
044d712d4d03f8354962d54e47cfac2346a69ccccilix * Krzysztof KosiƄski <tweenk.pl@gmail.com>
044d712d4d03f8354962d54e47cfac2346a69ccccilix *
044d712d4d03f8354962d54e47cfac2346a69ccccilix * Copyright (C) 2011 Authors
044d712d4d03f8354962d54e47cfac2346a69ccccilix * Released under GNU GPL, read the file 'COPYING' for more information
044d712d4d03f8354962d54e47cfac2346a69ccccilix */
044d712d4d03f8354962d54e47cfac2346a69ccccilix
044d712d4d03f8354962d54e47cfac2346a69ccccilix#ifndef SEEN_INKSCAPE_DISPLAY_DRAWING_ITEM_H
044d712d4d03f8354962d54e47cfac2346a69ccccilix#define SEEN_INKSCAPE_DISPLAY_DRAWING_ITEM_H
044d712d4d03f8354962d54e47cfac2346a69ccccilix
044d712d4d03f8354962d54e47cfac2346a69ccccilix#include <exception>
044d712d4d03f8354962d54e47cfac2346a69ccccilix#include <boost/intrusive/list.hpp>
044d712d4d03f8354962d54e47cfac2346a69ccccilix#include <2geom/rect.h>
044d712d4d03f8354962d54e47cfac2346a69ccccilix#include <2geom/affine.h>
63c37c52d614c3cde7913cf23a0f79040ed2e318Jabiertxof
044d712d4d03f8354962d54e47cfac2346a69ccccilixclass NRArena;
044d712d4d03f8354962d54e47cfac2346a69ccccilixclass SPStyle;
044d712d4d03f8354962d54e47cfac2346a69ccccilixvoid nr_arena_set_cache_limit(NRArena *, Geom::OptIntRect const &);
044d712d4d03f8354962d54e47cfac2346a69ccccilix
57678273bfa80d2feb4fa17ac25818f277f5c684cilixnamespace Inkscape {
57678273bfa80d2feb4fa17ac25818f277f5c684cilix
6b03b973a8d36d45d5345ba1013db10df1c7a5cecilixtypedef ::NRArena Drawing;
6b03b973a8d36d45d5345ba1013db10df1c7a5cecilixclass DrawingContext;
57678273bfa80d2feb4fa17ac25818f277f5c684cilixclass DrawingCache;
57678273bfa80d2feb4fa17ac25818f277f5c684cilixclass DrawingItem;
63c37c52d614c3cde7913cf23a0f79040ed2e318Jabiertxofnamespace Filters { class Filter; }
044d712d4d03f8354962d54e47cfac2346a69ccccilix
044d712d4d03f8354962d54e47cfac2346a69ccccilixstruct UpdateContext {
044d712d4d03f8354962d54e47cfac2346a69ccccilix Geom::Affine ctm;
044d712d4d03f8354962d54e47cfac2346a69ccccilix};
a39c187369a59e887255e3f704a3ababf2b10678Johan B. C. Engelen
044d712d4d03f8354962d54e47cfac2346a69ccccilixclass InvalidItemException : public std::exception {
044d712d4d03f8354962d54e47cfac2346a69ccccilix virtual const char *what() const throw() {
044d712d4d03f8354962d54e47cfac2346a69ccccilix return "Invalid item in drawing";
57678273bfa80d2feb4fa17ac25818f277f5c684cilix }
6b03b973a8d36d45d5345ba1013db10df1c7a5cecilix};
6b03b973a8d36d45d5345ba1013db10df1c7a5cecilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelentypedef boost::intrusive::list_base_hook<> ChildrenListHook;
57678273bfa80d2feb4fa17ac25818f277f5c684cilix
e44b9de426cfa07c598fda61d214dc053a0706ddcilixclass DrawingItem
f2604687c203c022c4a9715f34e34253a7ff0e75Johan B. C. Engelen : public ChildrenListHook
e44b9de426cfa07c598fda61d214dc053a0706ddcilix{
044d712d4d03f8354962d54e47cfac2346a69ccccilixpublic:
6b03b973a8d36d45d5345ba1013db10df1c7a5cecilix enum RenderFlags {
6b03b973a8d36d45d5345ba1013db10df1c7a5cecilix RENDER_DEFAULT = 0,
044d712d4d03f8354962d54e47cfac2346a69ccccilix RENDER_CACHE_ONLY = 1,
044d712d4d03f8354962d54e47cfac2346a69ccccilix RENDER_BYPASS_CACHE = 2
044d712d4d03f8354962d54e47cfac2346a69ccccilix };
57678273bfa80d2feb4fa17ac25818f277f5c684cilix enum StateFlags {
57678273bfa80d2feb4fa17ac25818f277f5c684cilix STATE_NONE = 0,
57678273bfa80d2feb4fa17ac25818f277f5c684cilix STATE_BBOX = (1<<0), // geometric bounding box is up-to-date
57678273bfa80d2feb4fa17ac25818f277f5c684cilix STATE_DRAWBOX = (1<<1), // visual bounding box is up-to-date
d4200d96d8369f38efb722b04869b360388eeb80cilix STATE_CACHE = (1<<2), // cache extents and clean area are up-to-date
d4200d96d8369f38efb722b04869b360388eeb80cilix STATE_PICK = (1<<3), // can process pick requests
d4200d96d8369f38efb722b04869b360388eeb80cilix STATE_RENDER = (1<<4), // can be rendered
57678273bfa80d2feb4fa17ac25818f277f5c684cilix STATE_ALL = (1<<5)-1
044d712d4d03f8354962d54e47cfac2346a69ccccilix };
044d712d4d03f8354962d54e47cfac2346a69ccccilix typedef boost::intrusive::list<DrawingItem> ChildrenList;
044d712d4d03f8354962d54e47cfac2346a69ccccilix
044d712d4d03f8354962d54e47cfac2346a69ccccilix DrawingItem(Drawing *drawing);
044d712d4d03f8354962d54e47cfac2346a69ccccilix virtual ~DrawingItem();
044d712d4d03f8354962d54e47cfac2346a69ccccilix
044d712d4d03f8354962d54e47cfac2346a69ccccilix Geom::OptIntRect geometricBounds() const { return _bbox; }
044d712d4d03f8354962d54e47cfac2346a69ccccilix Geom::OptIntRect visualBounds() const { return _drawbox; }
044d712d4d03f8354962d54e47cfac2346a69ccccilix Geom::OptRect itemBounds() const { return _item_bbox; }
044d712d4d03f8354962d54e47cfac2346a69ccccilix Geom::Affine ctm() const { return _ctm; }
044d712d4d03f8354962d54e47cfac2346a69ccccilix Geom::Affine transform() const { return _transform ? *_transform : Geom::identity(); }
044d712d4d03f8354962d54e47cfac2346a69ccccilix Drawing *drawing() const { return _drawing; }
044d712d4d03f8354962d54e47cfac2346a69ccccilix DrawingItem *parent() const;
044d712d4d03f8354962d54e47cfac2346a69ccccilix
044d712d4d03f8354962d54e47cfac2346a69ccccilix void appendChild(DrawingItem *item);
044d712d4d03f8354962d54e47cfac2346a69ccccilix void prependChild(DrawingItem *item);
044d712d4d03f8354962d54e47cfac2346a69ccccilix void clearChildren();
044d712d4d03f8354962d54e47cfac2346a69ccccilix
044d712d4d03f8354962d54e47cfac2346a69ccccilix bool visible() const { return _visible; }
044d712d4d03f8354962d54e47cfac2346a69ccccilix void setVisible(bool v);
bool sensitive() const { return _sensitive; }
void setSensitive(bool v);
bool cached() const { return _cached; }
void setCached(bool c);
void setOpacity(float opacity);
void setTransform(Geom::Affine const &trans);
void setClip(DrawingItem *item);
void setMask(DrawingItem *item);
void setZOrder(unsigned z);
void setItemBounds(Geom::OptRect const &bounds);
void setKey(unsigned key) { _key = key; }
unsigned key() const { return _key; }
void setData(void *data) { _user_data = data; }
void *data() const { return _user_data; }
void update(Geom::IntRect const &area = Geom::IntRect::infinite(), UpdateContext const &ctx = UpdateContext(), unsigned flags = STATE_ALL, unsigned reset = 0);
void render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags = 0);
void clip(DrawingContext &ct, Geom::IntRect const &area);
DrawingItem *pick(Geom::Point const &p, double delta, bool sticky);
protected:
void _renderOutline(DrawingContext &ct, Geom::IntRect const &area, unsigned flags);
void _markForUpdate(unsigned state, bool propagate);
void _markForRendering();
void _setStyleCommon(SPStyle *&_style, SPStyle *style);
virtual unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx,
unsigned flags, unsigned reset) { return 0; }
virtual void _renderItem(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) {}
virtual void _clipItem(DrawingContext &ct, Geom::IntRect const &area) {}
virtual DrawingItem *_pickItem(Geom::Point const &p, double delta) { return NULL; }
virtual bool _canClip() { return false; }
Drawing *_drawing;
DrawingItem *_parent;
ChildrenList _children;
unsigned _key; ///< Some SPItems can have more than one NRArenaItem;
/// this value is a hack used to distinguish between them
float _opacity;
Geom::Affine *_transform; ///< Incremental transform from parent to this item's coords
Geom::Affine _ctm; ///< Total transform from item coords to display coords
Geom::OptIntRect _bbox; ///< Bounding box in display (pixel) coords
Geom::OptIntRect _drawbox; ///< Bounding box enlarged by filters, shrinked by clips and masks
Geom::OptRect _item_bbox; ///< Bounding box in item coordinates
DrawingItem *_clip;
DrawingItem *_mask;
Inkscape::Filters::Filter *_filter;
void *_user_data; ///< Used to associate DrawingItems with SPItems that created them
DrawingCache *_cache;
unsigned _state : 8;
unsigned _visible : 1;
unsigned _sensitive : 1; ///< Whether this item responds to events
unsigned _cached : 1; ///< Whether the rendering is stored for reuse
unsigned _propagate : 1; ///< Whether to call update for all children on next update
//unsigned _renders_opacity : 1; ///< Whether object needs temporary surface for opacity
unsigned _clip_child : 1; ///< If set, this is not a child of _parent, but a clipping path
unsigned _mask_child : 1; ///< If set, this is not a child of _parent, but a mask
unsigned _pick_children : 1; ///< For groups: if true, children are returned from pick(),
/// otherwise the group is returned
// temporary hacks until I rewrite NRArena to Inkscape::Drawing
friend class NRArena;
friend void ::nr_arena_set_cache_limit(NRArena *, Geom::OptIntRect const &);
};
struct DeleteDisposer {
void operator()(DrawingItem *item) { delete item; }
};
} // end namespace Inkscape
#endif // !SEEN_INKSCAPE_DISPLAY_DRAWING_ITEM_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :