1 #ifndef SEEN_SNAPPER_H
2 #define SEEN_SNAPPER_H
4 /**
5 * \file src/snapper.h
6 * \brief Snapper class.
7 *
8 * Authors:
9 * Carl Hetherington <inkscape@carlh.net>
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information.
12 */
14 #include <map>
15 #include <list>
16 #include "libnr/nr-coord.h"
17 #include "libnr/nr-point.h"
18 #include "snapped-point.h"
20 struct SPNamedView;
21 struct SPItem;
23 namespace Inkscape
24 {
26 /// Parent for classes that can snap points to something
27 class Snapper
28 {
29 public:
30 Snapper() {}
31 Snapper(SPNamedView const *nv, ::NR::Coord const d);
32 virtual ~Snapper() {}
34 /// Point types to snap.
35 typedef int PointType;
36 static const PointType SNAP_POINT;
37 static const PointType BBOX_POINT;
39 typedef std::pair<PointType, NR::Point> PointWithType;
41 void setSnapTo(PointType t, bool s);
42 void setDistance(::NR::Coord d);
44 bool getSnapTo(PointType t) const;
45 ::NR::Coord getDistance() const;
47 bool willSnapSomething() const;
49 void setEnabled(bool s);
51 SnappedPoint freeSnap(PointType t,
52 NR::Point const &p,
53 SPItem const *it) const;
55 SnappedPoint freeSnap(PointType t,
56 NR::Point const &p,
57 std::list<SPItem const *> const &it) const;
59 class ConstraintLine
60 {
61 public:
62 ConstraintLine(NR::Point const &d) : _has_point(false), _direction(d) {}
63 ConstraintLine(NR::Point const &p, NR::Point const &d) : _has_point(true), _point(p), _direction(d) {}
65 bool hasPoint() const {
66 return _has_point;
67 }
69 NR::Point getPoint() const {
70 return _point;
71 }
73 NR::Point getDirection() const {
74 return _direction;
75 }
77 private:
79 bool _has_point;
80 NR::Point _point;
81 NR::Point _direction;
82 };
84 SnappedPoint constrainedSnap(PointType t,
85 NR::Point const &p,
86 ConstraintLine const &c,
87 SPItem const *it) const;
89 SnappedPoint constrainedSnap(PointType t,
90 NR::Point const &p,
91 ConstraintLine const &c,
92 std::list<SPItem const *> const &it) const;
93 protected:
94 SPNamedView const *_named_view;
96 private:
98 /**
99 * Try to snap a point to whatever this snapper is interested in. Any
100 * snap that occurs will be to the nearest "interesting" thing (e.g. a
101 * grid or guide line)
102 *
103 * \param p Point to snap (desktop coordinates).
104 * \param it Items that should not be snapped to.
105 * \return Snapped point.
106 */
107 virtual SnappedPoint _doFreeSnap(NR::Point const &p,
108 std::list<SPItem const *> const &it) const = 0;
110 /**
111 * Try to snap a point to whatever this snapper is interested in, where
112 * the snap point is constrained to lie along a specified vector from the
113 * original point.
114 *
115 * \param p Point to snap (desktop coordinates).
116 * \param c Vector to constrain the snap to.
117 * \param it Items that should not be snapped to.
118 * \return Snapped point.
119 */
120 virtual SnappedPoint _doConstrainedSnap(NR::Point const &p,
121 ConstraintLine const &c,
122 std::list<SPItem const *> const &it) const = 0;
124 ::NR::Coord _distance; ///< snap distance (desktop coordinates)
125 int _snap_to; ///< bitmap of point types that we will snap to
126 bool _enabled; ///< true if this snapper is enabled, otherwise false
127 };
129 }
131 #endif /* !SEEN_SNAPPER_H */
133 /*
134 Local Variables:
135 mode:c++
136 c-file-style:"stroustrup"
137 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
138 indent-tabs-mode:nil
139 fill-column:99
140 End:
141 */
142 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :