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 <2geom/matrix.h>
25 #include <libnr/nr-rect.h>
26 #include <2geom/forward.h>
27 #include <libnr/nr-convert2geom.h>
28 #include <snap-preferences.h>
29 #include <snapped-point.h>
31 class SPGuideConstraint;
32 struct SPClipPathReference;
33 struct SPMaskReference;
34 struct SPAvoidRef;
35 struct SPPrintContext;
36 namespace Inkscape { class URIReference; }
38 enum {
39 SP_EVENT_INVALID,
40 SP_EVENT_NONE,
41 SP_EVENT_ACTIVATE,
42 SP_EVENT_MOUSEOVER,
43 SP_EVENT_MOUSEOUT
44 };
46 /**
47 * Event structure.
48 *
49 * \todo This is just placeholder. Plan:
50 * We do extensible event structure, that hold applicable (ui, non-ui)
51 * data pointers. So it is up to given object/arena implementation
52 * to process correct ones in meaningful way.
53 * Also, this probably goes to SPObject base class.
54 *
55 */
56 struct SPEvent {
57 unsigned int type;
58 gpointer data;
59 };
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 /// Contains transformations to document/viewport and the viewport size.
82 struct SPItemCtx {
83 SPCtx ctx;
84 /** Item to document transformation */
85 Geom::Matrix i2doc;
86 /** Viewport size */
87 NRRect vp;
88 /** Item to viewport transformation */
89 Geom::Matrix i2vp;
90 };
92 /** Abstract base class for all visible shapes. */
93 struct SPItem : public SPObject {
94 enum BBoxType {
95 // legacy behavior: includes crude stroke, markers; excludes long miters, blur margin; is known to be wrong for caps
96 APPROXIMATE_BBOX,
97 // includes only the bare path bbox, no stroke, no nothing
98 GEOMETRIC_BBOX,
99 // includes everything: correctly done stroke (with proper miters and caps), markers, filter margins (e.g. blur)
100 RENDERING_BBOX
101 };
103 unsigned int sensitive : 1;
104 unsigned int stop_paint: 1;
105 double transform_center_x;
106 double transform_center_y;
108 Geom::Matrix transform;
110 SPClipPathReference *clip_ref;
111 SPMaskReference *mask_ref;
113 // Used for object-avoiding connectors
114 SPAvoidRef *avoidRef;
116 SPItemView *display;
118 std::vector<SPGuideConstraint> constraints;
120 sigc::signal<void, Geom::Matrix const *, SPItem *> _transformed_signal;
122 void init();
123 bool isLocked() const;
124 void setLocked(bool lock);
126 bool isHidden() const;
127 void setHidden(bool hidden);
129 bool isEvaluated() const;
130 void setEvaluated(bool visible);
131 void resetEvaluated();
133 bool isHidden(unsigned display_key) const;
135 bool isExplicitlyHidden() const;
137 void setExplicitlyHidden(bool val);
139 void setCenter(Geom::Point object_centre);
140 void unsetCenter();
141 bool isCenterSet();
142 Geom::Point getCenter() const;
144 bool isVisibleAndUnlocked() const;
146 bool isVisibleAndUnlocked(unsigned display_key) const;
148 Geom::Matrix getRelativeTransform(SPObject const *obj) const;
150 void raiseOne();
151 void lowerOne();
152 void raiseToTop();
153 void lowerToBottom();
155 Geom::OptRect getBounds(Geom::Matrix const &transform, BBoxType type=APPROXIMATE_BBOX, unsigned int dkey=0) const;
157 sigc::connection _clip_ref_connection;
158 sigc::connection _mask_ref_connection;
160 sigc::connection connectTransformed(sigc::slot<void, Geom::Matrix const *, SPItem *> slot) {
161 return _transformed_signal.connect(slot);
162 }
164 private:
165 enum EvaluatedStatus
166 {
167 StatusUnknown, StatusCalculated, StatusSet
168 };
170 mutable bool _is_evaluated;
171 mutable EvaluatedStatus _evaluated_status;
172 };
174 typedef std::vector<std::pair<Geom::Point, int> > SnapPointsWithType; // int is either of these enums: Inkscape::SnapTargetType or Inkscape::SnapSourceType
176 /// The SPItem vtable.
177 struct SPItemClass {
178 SPObjectClass parent_class;
180 /** BBox union in given coordinate system */
181 void (* bbox) (SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
183 /** Printing method. Assumes ctm is set to item affine matrix */
184 /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
185 void (* print) (SPItem *item, SPPrintContext *ctx);
187 /** Give short description of item (for status display) */
188 gchar * (* description) (SPItem * item);
190 NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
191 void (* hide) (SPItem *item, unsigned int key);
193 /** Write to an iterator the points that should be considered for snapping
194 * as the item's `nodes'.
195 */
196 void (* snappoints) (SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
198 /** Apply the transform optimally, and return any residual transformation */
199 Geom::Matrix (* set_transform)(SPItem *item, Geom::Matrix const &transform);
201 /** Convert the item to guidelines */
202 void (* convert_to_guides)(SPItem *item);
204 /** Emit event, if applicable */
205 gint (* event) (SPItem *item, SPEvent *event);
206 };
208 /* Flag testing macros */
210 #define SP_ITEM_STOP_PAINT(i) (SP_ITEM (i)->stop_paint)
212 /* Methods */
214 void sp_item_invoke_bbox(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
215 void sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
216 void sp_item_invoke_bbox_full(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear);
217 void sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear) __attribute__ ((deprecated));
219 unsigned sp_item_pos_in_parent(SPItem *item);
221 gchar *sp_item_description(SPItem * item);
222 void sp_item_invoke_print(SPItem *item, SPPrintContext *ctx);
224 /** Shows/Hides item on given arena display list */
225 unsigned int sp_item_display_key_new(unsigned int numkeys);
226 NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
227 void sp_item_invoke_hide(SPItem *item, unsigned int key);
229 void sp_item_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
231 void sp_item_adjust_pattern(SPItem *item, /* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
232 void sp_item_adjust_gradient(SPItem *item, /* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
233 void sp_item_adjust_stroke(SPItem *item, gdouble ex);
234 void sp_item_adjust_stroke_width_recursive(SPItem *item, gdouble ex);
235 void sp_item_adjust_paint_recursive(SPItem *item, Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern);
236 void sp_item_adjust_livepatheffect(SPItem *item, Geom::Matrix const &postmul, bool set = false);
238 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv = NULL, bool compensate = true);
240 void sp_item_set_item_transform(SPItem *item, Geom::Matrix const &transform);
242 void sp_item_convert_item_to_guides(SPItem *item);
244 gint sp_item_event (SPItem *item, SPEvent *event);
246 /* Utility */
248 NRArenaItem *sp_item_get_arenaitem(SPItem *item, unsigned int key);
250 void sp_item_bbox_desktop(SPItem *item, NRRect *bbox, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
251 Geom::OptRect sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
253 Geom::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
254 Geom::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
256 Geom::Matrix sp_item_i2doc_affine(SPItem const *item);
258 /* fixme: - these are evil, but OK */
260 /* Fill *TRANSFORM with the item-to-desktop transform. See doc/coordinates.txt
261 * for a description of `Desktop coordinates'; though see also mental's comment
262 * at the top of that file.
263 *
264 * \return TRANSFORM.
265 */
266 Geom::Matrix sp_item_i2d_affine(SPItem const *item);
267 void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &transform);
268 Geom::Matrix sp_item_dt2i_affine(SPItem const *item);
269 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
270 SPItem *sp_item_first_item_child (SPObject *obj);
272 void sp_item_convert_to_guides(SPItem *item);
274 #endif
276 /*
277 Local Variables:
278 mode:c++
279 c-file-style:"stroustrup"
280 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
281 indent-tabs-mode:nil
282 fill-column:99
283 End:
284 */
285 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :