Code

remove many unnecessary to_2geom and from_2geom calls
[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>
26 #include <2geom/forward.h>
27 #include <libnr/nr-convert2geom.h>
29 class SPGuideConstraint;
30 struct SPClipPathReference;
31 struct SPMaskReference;
32 struct SPAvoidRef;
33 struct SPPrintContext;
34 namespace Inkscape { class URIReference; }
35  
36 enum {
37     SP_EVENT_INVALID,
38     SP_EVENT_NONE,
39     SP_EVENT_ACTIVATE,
40     SP_EVENT_MOUSEOVER,
41     SP_EVENT_MOUSEOUT
42 };
44 /**
45  * Event structure.
46  *
47  * \todo This is just placeholder. Plan:
48  * We do extensible event structure, that hold applicable (ui, non-ui)
49  * data pointers. So it is up to given object/arena implementation
50  * to process correct ones in meaningful way.
51  * Also, this probably goes to SPObject base class.
52  *
53  */
54 struct SPEvent {
55     unsigned int type;
56     gpointer data;
57 };
59 class SPItemView;
61 /// SPItemView
62 struct SPItemView {
63     SPItemView *next;
64     unsigned int flags;
65     unsigned int key;
66     NRArenaItem *arenaitem;
67 };
69 /* flags */
71 #define SP_ITEM_BBOX_VISUAL 1
73 #define SP_ITEM_SHOW_DISPLAY (1 << 0)
75 /**
76  * Flag for referenced views (i.e. markers, clippaths, masks and patterns); 
77    currently unused, does the same as DISPLAY
78  */
79 #define SP_ITEM_REFERENCE_FLAGS (1 << 1)
81 class SPItemCtx;
83 /// Contains transformations to document/viewport and the viewport size.
84 struct SPItemCtx {
85     SPCtx ctx;
86     /** Item to document transformation */
87     NR::Matrix i2doc;
88     /** Viewport size */
89     NRRect vp;
90     /** Item to viewport transformation */
91     NR::Matrix i2vp;
92 };
94 /** Abstract base class for all visible shapes. */
95 struct SPItem : public SPObject {
96     enum BBoxType {
97         // legacy behavior: includes crude stroke, markers; excludes long miters, blur margin; is known to be wrong for caps
98         APPROXIMATE_BBOX, 
99         // includes only the bare path bbox, no stroke, no nothing
100         GEOMETRIC_BBOX,
101         // includes everything: correctly done stroke (with proper miters and caps), markers, filter margins (e.g. blur)
102         RENDERING_BBOX
103     };
105     unsigned int sensitive : 1;
106     unsigned int stop_paint: 1;
107     double transform_center_x;
108     double transform_center_y;
110     NR::Matrix transform;
111     
112     SPClipPathReference *clip_ref;
113     SPMaskReference *mask_ref;
114     
115     // Used for object-avoiding connectors
116     SPAvoidRef *avoidRef;
117     
118     SPItemView *display;
119     
120     std::vector<SPGuideConstraint> constraints;
121     
122     sigc::signal<void, NR::Matrix const *, SPItem *> _transformed_signal;
124     void init();    
125     bool isLocked() const;
126     void setLocked(bool lock);
127     
128     bool isHidden() const;
129     void setHidden(bool hidden);
131     bool isEvaluated() const;
132     void setEvaluated(bool visible);
133     void resetEvaluated();
134     
135     bool isHidden(unsigned display_key) const;
136     
137     bool isExplicitlyHidden() const;
138     
139     void setExplicitlyHidden(bool val);
141     void setCenter(NR::Point object_centre);
142     void unsetCenter();
143     bool isCenterSet();
144     NR::Point getCenter() const;
146     bool isVisibleAndUnlocked() const;
147     
148     bool isVisibleAndUnlocked(unsigned display_key) const;
149     
150     NR::Matrix getRelativeTransform(SPObject const *obj) const;
151     
152     void raiseOne();
153     void lowerOne();
154     void raiseToTop();
155     void lowerToBottom();
157     boost::optional<NR::Rect> getBounds(NR::Matrix const &transform, BBoxType type=APPROXIMATE_BBOX, unsigned int dkey=0) const;
159     sigc::connection _clip_ref_connection;
160     sigc::connection _mask_ref_connection;
162     sigc::connection connectTransformed(sigc::slot<void, NR::Matrix const *, SPItem *> slot)  {
163         return _transformed_signal.connect(slot);
164     }
166 private:
167     enum EvaluatedStatus
168     {
169         StatusUnknown, StatusCalculated, StatusSet
170     };
172     mutable bool _is_evaluated;
173     mutable EvaluatedStatus _evaluated_status;
174 };
176 typedef std::back_insert_iterator<std::vector<NR::Point> > SnapPointsIter;
178 /// The SPItem vtable.
179 struct SPItemClass {
180     SPObjectClass parent_class;
182     /** BBox union in given coordinate system */
183     void (* bbox) (SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
184     
185     /** Printing method. Assumes ctm is set to item affine matrix */
186     /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
187     void (* print) (SPItem *item, SPPrintContext *ctx);
188     
189     /** Give short description of item (for status display) */
190     gchar * (* description) (SPItem * item);
191     
192     NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
193     void (* hide) (SPItem *item, unsigned int key);
194     
195     /** Write to an iterator the points that should be considered for snapping
196      * as the item's `nodes'.
197      */
198     void (* snappoints) (SPItem const *item, SnapPointsIter p);
199     
200     /** Apply the transform optimally, and return any residual transformation */
201     NR::Matrix (* set_transform)(SPItem *item, NR::Matrix const &transform);
203     /** Convert the item to guidelines */
204     void (* convert_to_guides)(SPItem *item);
205     
206     /** Emit event, if applicable */
207     gint (* event) (SPItem *item, SPEvent *event);
208 };
210 /* Flag testing macros */
212 #define SP_ITEM_STOP_PAINT(i) (SP_ITEM (i)->stop_paint)
214 /* Methods */
216 void sp_item_invoke_bbox(SPItem const *item, boost::optional<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
217 void sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
218 void sp_item_invoke_bbox_full(SPItem const *item, boost::optional<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear);
219 void sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear) __attribute__ ((deprecated));
221 unsigned sp_item_pos_in_parent(SPItem *item);
223 gchar *sp_item_description(SPItem * item);
224 void sp_item_invoke_print(SPItem *item, SPPrintContext *ctx);
226 /** Shows/Hides item on given arena display list */
227 unsigned int sp_item_display_key_new(unsigned int numkeys);
228 NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
229 void sp_item_invoke_hide(SPItem *item, unsigned int key);
231 void sp_item_snappoints(SPItem const *item, bool includeItemCenter, SnapPointsIter p);
233 void sp_item_adjust_pattern(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
234 void sp_item_adjust_gradient(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
235 void sp_item_adjust_stroke(SPItem *item, gdouble ex);
236 void sp_item_adjust_stroke_width_recursive(SPItem *item, gdouble ex);
237 void sp_item_adjust_paint_recursive(SPItem *item, NR::Matrix advertized_transform, NR::Matrix t_ancestors, bool is_pattern);
238 void sp_item_adjust_livepatheffect(SPItem *item, NR::Matrix const &postmul, bool set = false);
240 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix const *transform, NR::Matrix const *adv = NULL);
241 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix const &transform, NR::Matrix const *adv = NULL, bool compensate = true);
243 void sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform);
245 void sp_item_convert_item_to_guides(SPItem *item);
247 gint sp_item_event (SPItem *item, SPEvent *event);
249 /* Utility */
251 NRArenaItem *sp_item_get_arenaitem(SPItem *item, unsigned int key);
253 void sp_item_bbox_desktop(SPItem *item, NRRect *bbox, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
254 boost::optional<NR::Rect> sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
256 Geom::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
257 Geom::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
259 Geom::Matrix sp_item_i2doc_affine(SPItem const *item);
260 Geom::Matrix sp_item_i2root_affine(SPItem const *item);
262 Geom::Matrix matrix_to_desktop (Geom::Matrix m, SPItem const *item);
263 Geom::Matrix matrix_from_desktop (Geom::Matrix m, SPItem const *item);
265 /* fixme: - these are evil, but OK */
267 /* Fill *TRANSFORM with the item-to-desktop transform.  See doc/coordinates.txt
268  * for a description of `Desktop coordinates'; though see also mental's comment
269  * at the top of that file.
270  *
271  * \return TRANSFORM.
272  */
273 Geom::Matrix sp_item_i2d_affine(SPItem const *item);
274 Geom::Matrix sp_item_i2r_affine(SPItem const *item);
275 void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &transform);
276 Geom::Matrix sp_item_dt2i_affine(SPItem const *item);
277 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
278 SPItem *sp_item_first_item_child (SPObject *obj);
280 void sp_item_convert_to_guides(SPItem *item);
282 #endif
284 /*
285   Local Variables:
286   mode:c++
287   c-file-style:"stroustrup"
288   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
289   indent-tabs-mode:nil
290   fill-column:99
291   End:
292 */
293 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :