Code

Fix self-snapping when dragging the transformation center of a selection containing...
[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 #include "snap-enums.h"
19 struct SPItem; // forward declaration
21 namespace Inkscape {
23 /// Class to store data for points which are snap candidates, either as a source or as a target
24 class SnapCandidatePoint
25 {
26 public:
27     SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num, Inkscape::SnapTargetType const target, Geom::OptRect const &bbox)
28         : _point(point),
29         _source_type(source),
30         _target_type(target),
31         _source_num(source_num),
32         _target_bbox(bbox)
33     {
34     };
36     SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, Inkscape::SnapTargetType const target)
37         : _point(point),
38         _source_type(source),
39         _target_type(target)
40     {
41         _source_num = 0;
42         _target_bbox = Geom::OptRect();
43     }
45     SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source)
46         : _point(point),
47         _source_type(source),
48         _target_type(Inkscape::SNAPTARGET_UNDEFINED),
49         _source_num(0)
50     {
51         _target_bbox = Geom::OptRect();
52     }
54     inline Geom::Point const & getPoint() const {return _point;}
55     inline Inkscape::SnapSourceType getSourceType() const {return _source_type;}
56     inline Inkscape::SnapTargetType getTargetType() const {return _target_type;}
57     inline long getSourceNum() const {return _source_num;}
58     void setSourceNum(long num) {_source_num = num;}
59     inline Geom::OptRect const getTargetBBox() const {return _target_bbox;}
61 private:
62     // Coordinates of the point
63     Geom::Point _point;
65     // If this SnapCandidatePoint is a snap source, then _source_type must be defined. If it
66     // is a snap target, then _target_type must be defined. If it's yet unknown whether it will
67     // be a source or target, then both may be defined
68     Inkscape::SnapSourceType _source_type;
69     Inkscape::SnapTargetType _target_type;
71     //Sequence number of the source point within the set of points that is to be snapped. Starting at zero
72     long _source_num;
74     // If this is a target and it belongs to a bounding box, e.g. when the target type is
75     // SNAPTARGET_BBOX_EDGE_MIDPOINT, then _target_bbox stores the relevant bounding box
76     Geom::OptRect _target_bbox;
77 };
79 class SnapCandidateItem
80 {
81 public:
82     SnapCandidateItem(SPItem* item, bool clip_or_mask, Geom::Matrix additional_affine)
83         : item(item), clip_or_mask(clip_or_mask), additional_affine(additional_affine) {}
84     ~SnapCandidateItem() {};
86     SPItem* item;        // An item that is to be considered for snapping to
87     bool clip_or_mask;    // If true, then item refers to a clipping path or a mask
89     /* To find out the absolute position of a clipping path or mask, we not only need to know
90      * the transformation of the clipping path or mask itself, but also the transformation of
91      * the object to which the clip or mask is being applied; that transformation is stored here
92      */
93     Geom::Matrix additional_affine;
94 }
95 ;
97 class SnapCandidatePath
98 {
100 public:
101     SnapCandidatePath(Geom::PathVector* path, SnapTargetType target, Geom::OptRect bbox, bool edited = false)
102         : path_vector(path), target_type(target), target_bbox(bbox), currently_being_edited(edited) {};
103     ~SnapCandidatePath() {};
105     Geom::PathVector* path_vector;
106     SnapTargetType target_type;
107     Geom::OptRect target_bbox;
108     bool currently_being_edited; // true for the path that's currently being edited in the node tool (if any)
110 };
112 } // end of namespace Inkscape
114 #endif /* !SEEN_SNAP_CANDIDATE_H */