Code

enable motion hints for non-freehand actions
[inkscape.git] / src / snapped-point.h
1 #ifndef SEEN_SNAPPEDPOINT_H
2 #define SEEN_SNAPPEDPOINT_H
4 /**
5  *    \file src/snapped-point.h
6  *    \brief SnappedPoint class.
7  *
8  *    Authors:
9  *      Mathieu Dimanche <mdimanche@free.fr>
10  *      Diederik van Lierop <mail@diedenrezi.nl>
11  *
12  *    Released under GNU GPL, read the file 'COPYING' for more information.
13  */
15 #include <vector>
16 #include <list>
17 #include "libnr/nr-coord.h"
18 #include "libnr/nr-point.h"
19 #include <libnr/nr-values.h>
21 namespace Inkscape
22 {
24 enum SnapTargetType {
25     SNAPTARGET_UNDEFINED,
26     SNAPTARGET_GRID,
27     SNAPTARGET_GRID_INTERSECTION,
28     SNAPTARGET_GUIDE,
29     SNAPTARGET_GUIDE_INTERSECTION,
30     SNAPTARGET_GRID_GUIDE_INTERSECTION,
31     SNAPTARGET_NODE,
32     SNAPTARGET_PATH,
33     SNAPTARGET_PATH_INTERSECTION,
34     SNAPTARGET_BBOX_CORNER,
35     SNAPTARGET_BBOX_EDGE,
36     SNAPTARGET_GRADIENT
37 };
38     
39 /// Class describing the result of an attempt to snap.
40 class SnappedPoint
41 {
43 public:
44     SnappedPoint();
45     SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a, bool const &at_intersection, NR::Coord const &d2, NR::Coord const &t2, bool const &a2);
46     SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a);
47     ~SnappedPoint();
49     NR::Coord getDistance() const;
50     void setDistance(NR::Coord const d) {_distance = d;}
51     NR::Coord getTolerance() const;
52     bool getAlwaysSnap() const;
53     NR::Coord getSecondDistance() const;
54     NR::Coord getSecondTolerance() const;
55     bool getSecondAlwaysSnap() const;
56     
57     /* This is the preferred method to find out which point we have snapped,
58      * to because it only returns a point if snapping has actually occured
59      * (by overwriting p)
60      */ 
61     void getPoint(NR::Point &p) const;
62     
63     /* This method however always returns a point, even if no snapping
64      * has occured; A check should be implemented in the calling code
65      * to check for snapping. Use this method only when really needed, e.g.
66      * when the calling code is trying to snap multiple points and must
67      * determine itself which point is most appropriate
68      */  
69     NR::Point getPoint() const {return _point;}
70      
71     bool getAtIntersection() const {return _at_intersection;}
72     bool getSnapped() const {return _distance < NR_HUGE;}
73     NR::Point getTransformation() const {return _transformation;}
74     void setTransformation(NR::Point const t) {_transformation = t;}
75     void setTarget(SnapTargetType const target) {_target = target;}
76     SnapTargetType getTarget() {return _target;}
77     
78 protected:
79     NR::Point _point; // Location of the snapped point
80     SnapTargetType _target; // Describes to what we've snapped to
81     bool _at_intersection; // If true, the snapped point is at an intersection 
82     
83     /* Distance from original point to snapped point. If the snapped point is at
84        an intersection of e.g. two lines, then this is the distance to the closest
85        line */    
86     NR::Coord _distance; 
87     /* The snapping tolerance in screen pixels (depends on zoom)*/  
88     NR::Coord _tolerance;
89     /* If true then "Always snap" is on */
90     bool _always_snap;
91     
92     /* If the snapped point is at an intersection of e.g. two lines, then this is
93        the distance to the fartest line */    
94     NR::Coord _second_distance;
95     /* The snapping tolerance in screen pixels (depends on zoom)*/
96     NR::Coord _second_tolerance;
97     /* If true then "Always snap" is on */
98     bool _second_always_snap;
99     /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
100     NR::Point _transformation;
101 };    
105 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
108 #endif /* !SEEN_SNAPPEDPOINT_H */
110 /*
111   Local Variables:
112   mode:c++
113   c-file-style:"stroustrup"
114   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
115   indent-tabs-mode:nil
116   fill-column:99
117   End:
118 */
119 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :