Code

Sketch out new bbox API
[inkscape.git] / src / sp-item.h
1 #ifndef __SP_ITEM_H__
2 #define __SP_ITEM_H__
4 /** \file
5  * Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx, SPItemClass, SPEvent.
6  */
8 /*
9  * Authors:
10  *   Lauris Kaplinski <lauris@kaplinski.com>
11  *   bulia byak <buliabyak@users.sf.net>
12  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
13  *
14  * Copyright (C) 1999-2006 authors
15  * Copyright (C) 2001-2002 Ximian, Inc.
16  * Copyright (C) 2004 Monash University
17  *
18  * Released under GNU GPL, read the file 'COPYING' for more information
19  */
20 #include <vector>
22 #include "display/nr-arena-forward.h"
23 #include "sp-object.h"
24 #include <libnr/nr-matrix.h>
25 #include <libnr/nr-rect.h>
27 class SPGuideConstraint;
28 struct SPClipPathReference;
29 struct SPMaskReference;
30 struct SPAvoidRef;
31 struct SPPrintContext;
32 namespace Inkscape { class URIReference; }
33  
34 enum {
35     SP_EVENT_INVALID,
36     SP_EVENT_NONE,
37     SP_EVENT_ACTIVATE,
38     SP_EVENT_MOUSEOVER,
39     SP_EVENT_MOUSEOUT
40 };
42 /**
43  * Event structure.
44  *
45  * \todo This is just placeholder. Plan:
46  * We do extensible event structure, that hold applicable (ui, non-ui)
47  * data pointers. So it is up to given object/arena implementation
48  * to process correct ones in meaningful way.
49  * Also, this probably goes to SPObject base class.
50  *
51  */
52 struct SPEvent {
53     unsigned int type;
54     gpointer data;
55 };
57 class SPItemView;
59 /// SPItemView
60 struct SPItemView {
61     SPItemView *next;
62     unsigned int flags;
63     unsigned int key;
64     NRArenaItem *arenaitem;
65 };
67 /* flags */
69 #define SP_ITEM_BBOX_VISUAL 1
71 #define SP_ITEM_SHOW_DISPLAY (1 << 0)
73 /**
74  * Flag for referenced views (i.e. clippaths, masks and patterns); always display
75  */
76 #define SP_ITEM_REFERENCE_FLAGS SP_ITEM_SHOW_DISPLAY
78 class SPItemCtx;
80 /// Contains transformations to document/viewport and the viewport size.
81 struct SPItemCtx {
82     SPCtx ctx;
83     /** Item to document transformation */
84     NR::Matrix i2doc;
85     /** Viewport size */
86     NRRect vp;
87     /** Item to viewport transformation */
88     NR::Matrix i2vp;
89 };
91 /** Abstract base class for all visible shapes. */
92 struct SPItem : public SPObject {
93     enum BBoxType {
94         APPROXIMATE_BBOX,
95         GEOMETRIC_BBOX,
96         RENDERING_BBOX
97     };
99     unsigned int sensitive : 1;
100     unsigned int stop_paint: 1;
101     double transform_center_x;
102     double transform_center_y;
104     NR::Matrix transform;
105     
106     SPClipPathReference *clip_ref;
107     SPMaskReference *mask_ref;
108     
109     // Used for object-avoiding connectors
110     SPAvoidRef *avoidRef;
111     
112     SPItemView *display;
113     
114     std::vector<SPGuideConstraint> constraints;
115     
116     sigc::signal<void, NR::Matrix const *, SPItem *> _transformed_signal;
118     void init();    
119     bool isLocked() const;
120     void setLocked(bool lock);
121     
122     bool isHidden() const;
123     void setHidden(bool hidden);
125     bool isEvaluated() const;
126     void setEvaluated(bool visible);
127     void resetEvaluated();
128     
129     bool isHidden(unsigned display_key) const;
130     
131     bool isExplicitlyHidden() const;
132     
133     void setExplicitlyHidden(bool val);
135     void setCenter(NR::Point object_centre);
136     void unsetCenter();
137     bool isCenterSet();
138     NR::Point getCenter();
140     bool isVisibleAndUnlocked() const;
141     
142     bool isVisibleAndUnlocked(unsigned display_key) const;
143     
144     NR::Matrix getRelativeTransform(SPObject const *obj) const;
145     
146     void raiseOne();
147     void lowerOne();
148     void raiseToTop();
149     void lowerToBottom();
151     NR::Rect invokeBbox(NR::Matrix const &transform) const;
152     NR::Maybe<NR::Rect> getBBox(BBoxType type, NR::Matrix const &transform, unsigned int dkey=0) const;
154     sigc::connection _clip_ref_connection;
155     sigc::connection _mask_ref_connection;
157     sigc::connection connectTransformed(sigc::slot<void, NR::Matrix const *, SPItem *> slot)  {
158         return _transformed_signal.connect(slot);
159     }
161 private:
162     enum EvaluatedStatus
163     {
164         StatusUnknown, StatusCalculated, StatusSet
165     };
167     mutable bool _is_evaluated;
168     mutable EvaluatedStatus _evaluated_status;
169 };
171 typedef std::back_insert_iterator<std::vector<NR::Point> > SnapPointsIter;
173 /// The SPItem vtable.
174 struct SPItemClass {
175     SPObjectClass parent_class;
177     /** BBox union in given coordinate system */
178     void (* bbox) (SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
179     
180     /** Printing method. Assumes ctm is set to item affine matrix */
181     /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
182     void (* print) (SPItem *item, SPPrintContext *ctx);
183     
184     /** Give short description of item (for status display) */
185     gchar * (* description) (SPItem * item);
186     
187     NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
188     void (* hide) (SPItem *item, unsigned int key);
189     
190     /** Write to an iterator the points that should be considered for snapping
191      * as the item's `nodes'.
192      */
193     void (* snappoints) (SPItem const *item, SnapPointsIter p);
194     
195     /** Apply the transform optimally, and return any residual transformation */
196     NR::Matrix (* set_transform)(SPItem *item, NR::Matrix const &transform);
197     
198     /** Emit event, if applicable */
199     gint (* event) (SPItem *item, SPEvent *event);
200 };
202 /* Flag testing macros */
204 #define SP_ITEM_STOP_PAINT(i) (SP_ITEM (i)->stop_paint)
206 /* Methods */
208 void sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear);
209 void sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear);
211 unsigned sp_item_pos_in_parent(SPItem *item);
213 gchar *sp_item_description(SPItem * item);
214 void sp_item_invoke_print(SPItem *item, SPPrintContext *ctx);
216 /** Shows/Hides item on given arena display list */
217 unsigned int sp_item_display_key_new(unsigned int numkeys);
218 NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
219 void sp_item_invoke_hide(SPItem *item, unsigned int key);
221 void sp_item_snappoints(SPItem const *item, SnapPointsIter p);
223 void sp_item_adjust_pattern(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
224 void sp_item_adjust_gradient(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
225 void sp_item_adjust_stroke(SPItem *item, gdouble ex);
226 void sp_item_adjust_stroke_width_recursive(SPItem *item, gdouble ex);
227 void sp_item_adjust_paint_recursive(SPItem *item, NR::Matrix advertized_transform, NR::Matrix t_ancestors, bool is_pattern);
229 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NRMatrix const *transform, NR::Matrix const *adv = NULL);
230 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix const &transform, NR::Matrix const *adv = NULL, bool compensate = true);
232 void sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform);
234 gint sp_item_event (SPItem *item, SPEvent *event);
236 /* Utility */
238 NRArenaItem *sp_item_get_arenaitem(SPItem *item, unsigned int key);
240 void sp_item_bbox_desktop(SPItem *item, NRRect *bbox) __attribute__ ((deprecated));
241 NR::Rect sp_item_bbox_desktop(SPItem *item);
243 NR::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
244 NR::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
246 NR::Matrix sp_item_i2doc_affine(SPItem const *item);
247 NR::Matrix sp_item_i2root_affine(SPItem const *item);
249 NR::Matrix matrix_to_desktop (NR::Matrix m, SPItem const *item);
250 NR::Matrix matrix_from_desktop (NR::Matrix m, SPItem const *item);
252 /* fixme: - these are evil, but OK */
254 /* Fill *TRANSFORM with the item-to-desktop transform.  See doc/coordinates.txt
255  * for a description of `Desktop coordinates'; though see also mental's comment
256  * at the top of that file.
257  *
258  * \return TRANSFORM.
259  */
260 NR::Matrix sp_item_i2d_affine(SPItem const *item);
261 NR::Matrix sp_item_i2r_affine(SPItem const *item);
262 void sp_item_set_i2d_affine(SPItem *item, NR::Matrix const &transform);
263 NR::Matrix sp_item_dt2i_affine(SPItem const *item);
264 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
265 SPItem *sp_item_first_item_child (SPObject *obj);
267 #endif
269 /*
270   Local Variables:
271   mode:c++
272   c-file-style:"stroustrup"
273   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
274   indent-tabs-mode:nil
275   fill-column:99
276   End:
277 */
278 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :