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(SPNamedView const *nv, ::NR::Coord const d);
31 virtual ~Snapper() {}
33 /// Point types to snap.
34 typedef int PointType;
35 static const PointType SNAP_POINT;
36 static const PointType BBOX_POINT;
38 typedef std::pair<PointType, NR::Point> PointWithType;
40 void setSnapTo(PointType t, bool s);
41 void setDistance(::NR::Coord d);
43 bool getSnapTo(PointType t) const;
44 ::NR::Coord getDistance() const;
46 bool willSnapSomething() const;
48 SnappedPoint freeSnap(PointType t,
49 NR::Point const &p,
50 SPItem const *it) const;
52 SnappedPoint freeSnap(PointType t,
53 NR::Point const &p,
54 std::list<SPItem const *> const &it) const;
56 SnappedPoint constrainedSnap(PointType t,
57 NR::Point const &p,
58 NR::Point const &c,
59 SPItem const *it) const;
61 SnappedPoint constrainedSnap(PointType t,
62 NR::Point const &p,
63 NR::Point const &c,
64 std::list<SPItem const *> const &it) const;
65 protected:
66 SPNamedView const *_named_view;
68 private:
70 /**
71 * Try to snap a point to whatever this snapper is interested in. Any
72 * snap that occurs will be to the nearest "interesting" thing (e.g. a
73 * grid or guide line)
74 *
75 * \param p Point to snap (desktop coordinates).
76 * \param it Items that should not be snapped to.
77 * \return Snapped point.
78 */
79 virtual SnappedPoint _doFreeSnap(NR::Point const &p,
80 std::list<SPItem const *> const &it) const = 0;
82 /**
83 * Try to snap a point to whatever this snapper is interested in, where
84 * the snap point is constrained to lie along a specified vector from the
85 * original point.
86 *
87 * \param p Point to snap (desktop coordinates).
88 * \param c Vector to constrain the snap to.
89 * \param it Items that should not be snapped to.
90 * \return Snapped point.
91 */
92 virtual SnappedPoint _doConstrainedSnap(NR::Point const &p,
93 NR::Point const &c,
94 std::list<SPItem const *> const &it) const = 0;
96 ::NR::Coord _distance; ///< snap distance (desktop coordinates)
97 int _snap_to; ///< bitmap of point types that we will snap to
98 };
100 }
102 #endif /* !SEEN_SNAPPER_H */
104 /*
105 Local Variables:
106 mode:c++
107 c-file-style:"stroustrup"
108 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
109 indent-tabs-mode:nil
110 fill-column:99
111 End:
112 */
113 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :