Code

When snapping to a bounding box, flash that bounding box together with the snap indicator
[inkscape.git] / src / snap-candidate.h
1 #ifndef SEEN_SNAP_CANDIDATE_H
2 #define SEEN_SNAP_CANDIDATE_H
4 /**
5  * \file snap-candidate.h
6  * \brief some utility classes to store various kinds of snap candidates.
7  *
8  * Authors:
9  *   Diederik van Lierop <mail@diedenrezi.nl>
10  *
11  * Copyright (C) 2010 Authors
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 //#include "snapped-point.h"
17 struct SPItem; // forward declaration
19 namespace Inkscape {
21 enum SnapTargetType {
22     SNAPTARGET_UNDEFINED = 0,
23     SNAPTARGET_GRID,
24     SNAPTARGET_GRID_INTERSECTION,
25     SNAPTARGET_GUIDE,
26     SNAPTARGET_GUIDE_INTERSECTION,
27     SNAPTARGET_GUIDE_ORIGIN,
28     SNAPTARGET_GRID_GUIDE_INTERSECTION,
29     SNAPTARGET_NODE_SMOOTH,
30     SNAPTARGET_NODE_CUSP,
31     SNAPTARGET_LINE_MIDPOINT,
32     SNAPTARGET_OBJECT_MIDPOINT,
33     SNAPTARGET_ROTATION_CENTER,
34     SNAPTARGET_HANDLE,
35     SNAPTARGET_PATH,
36     SNAPTARGET_PATH_INTERSECTION,
37     SNAPTARGET_BBOX_CORNER,
38     SNAPTARGET_BBOX_EDGE,
39     SNAPTARGET_BBOX_EDGE_MIDPOINT,
40     SNAPTARGET_BBOX_MIDPOINT,
41     SNAPTARGET_PAGE_BORDER,
42     SNAPTARGET_PAGE_CORNER,
43     SNAPTARGET_CONVEX_HULL_CORNER,
44     SNAPTARGET_ELLIPSE_QUADRANT_POINT,
45     SNAPTARGET_CENTER, // of ellipse
46     SNAPTARGET_CORNER, // of image or of rectangle
47     SNAPTARGET_TEXT_BASELINE,
48     SNAPTARGET_CONSTRAINED_ANGLE
49 };
51 enum SnapSourceType {
52     SNAPSOURCE_UNDEFINED = 0,
53     SNAPSOURCE_BBOX_CORNER,
54     SNAPSOURCE_BBOX_MIDPOINT,
55     SNAPSOURCE_BBOX_EDGE_MIDPOINT,
56     SNAPSOURCE_NODE_SMOOTH,
57     SNAPSOURCE_NODE_CUSP,
58     SNAPSOURCE_LINE_MIDPOINT,
59     SNAPSOURCE_OBJECT_MIDPOINT,
60     SNAPSOURCE_ROTATION_CENTER,
61     SNAPSOURCE_HANDLE,
62     SNAPSOURCE_PATH_INTERSECTION,
63     SNAPSOURCE_GUIDE,
64     SNAPSOURCE_GUIDE_ORIGIN,
65     SNAPSOURCE_CONVEX_HULL_CORNER,
66     SNAPSOURCE_ELLIPSE_QUADRANT_POINT,
67     SNAPSOURCE_CENTER, // of ellipse
68     SNAPSOURCE_CORNER, // of image or of rectangle
69     SNAPSOURCE_TEXT_BASELINE
70 };
72 /// Class to store data for points which are snap candidates, either as a source or as a target
73 class SnapCandidatePoint
74 {
75 public:
76     SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num, Inkscape::SnapTargetType const target, Geom::OptRect const &bbox)
77         : _point(point),
78         _source_type(source),
79         _target_type(target),
80         _source_num(source_num),
81         _target_bbox(bbox)
82     {
83     };
85     SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, Inkscape::SnapTargetType const target)
86         : _point(point),
87         _source_type(source),
88         _target_type(target)
89     {
90         _source_num = 0;
91         _target_bbox = Geom::OptRect();
92     }
94     SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num = 0)
95         : _point(point),
96         _source_type(source),
97         _target_type(Inkscape::SNAPTARGET_UNDEFINED),
98         _source_num(source_num)
99     {
100         _target_bbox = Geom::OptRect();
101     }
103     inline Geom::Point const & getPoint() const {return _point;}
104     inline Inkscape::SnapSourceType getSourceType() const {return _source_type;}
105     inline Inkscape::SnapTargetType getTargetType() const {return _target_type;}
106     inline long getSourceNum() const {return _source_num;}
107     inline Geom::OptRect const getTargetBBox() const {return _target_bbox;}
109 private:
110     // Coordinates of the point
111     Geom::Point _point;
113     // If this SnapCandidatePoint is a snap source, then _source_type must be defined. If it
114     // is a snap target, then _target_type must be defined. If it's yet unknown whether it will
115     // be a source or target, then both may be defined
116     Inkscape::SnapSourceType _source_type;
117     Inkscape::SnapTargetType _target_type;
119     //Sequence number of the source point within the set of points that is to be snapped. Starting at zero
120     long _source_num;
122     // If this is a target and it belongs to a bounding box, e.g. when the target type is
123     // SNAPTARGET_BBOX_EDGE_MIDPOINT, then _target_bbox stores the relevant bounding box
124     Geom::OptRect _target_bbox;
125 };
127 class SnapCandidateItem
129 public:
130     SnapCandidateItem(SPItem* item, bool clip_or_mask, Geom::Matrix additional_affine)
131         : item(item), clip_or_mask(clip_or_mask), additional_affine(additional_affine) {}
132     ~SnapCandidateItem() {};
134     SPItem* item;        // An item that is to be considered for snapping to
135     bool clip_or_mask;    // If true, then item refers to a clipping path or a mask
137     /* To find out the absolute position of a clipping path or mask, we not only need to know
138      * the transformation of the clipping path or mask itself, but also the transformation of
139      * the object to which the clip or mask is being applied; that transformation is stored here
140      */
141     Geom::Matrix additional_affine;
145 class SnapCandidatePath
148 public:
149     SnapCandidatePath(Geom::PathVector* path, SnapTargetType target, Geom::OptRect bbox, bool edited = false)
150         : path_vector(path), target_type(target), target_bbox(bbox), currently_being_edited(edited) {};
151     ~SnapCandidatePath() {};
153     Geom::PathVector* path_vector;
154     SnapTargetType target_type;
155     Geom::OptRect target_bbox;
156     bool currently_being_edited; // true for the path that's currently being edited in the node tool (if any)
158 };
160 } // end of namespace Inkscape
162 #endif /* !SEEN_SNAP_CANDIDATE_H */