1440f64c7b44d53748c1d608834ae540d8ffe25e
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 SNAPPOINT_NODE;
37 static const PointType SNAPPOINT_BBOX;
39 void setSnapFrom(PointType t, bool s);
40 void setDistance(::NR::Coord d);
42 bool getSnapFrom(PointType t) const;
43 ::NR::Coord getDistance() const;
45 /**
46 * \return true if this Snapper will snap at least one kind of point.
47 */
48 virtual bool ThisSnapperMightSnap() const {return (_enabled && _snap_from != 0);} // will likely be overridden by derived classes
51 void setEnabled(bool s);
53 SnappedPoint freeSnap(PointType const &t,
54 NR::Point const &p,
55 SPItem const *it) const;
57 SnappedPoint freeSnap(PointType const &t,
58 NR::Point const &p,
59 std::list<SPItem const *> const &it) const;
61 class ConstraintLine
62 {
63 public:
64 ConstraintLine(NR::Point const &d) : _has_point(false), _direction(d) {}
65 ConstraintLine(NR::Point const &p, NR::Point const &d) : _has_point(true), _point(p), _direction(d) {}
67 bool hasPoint() const {
68 return _has_point;
69 }
71 NR::Point getPoint() const {
72 return _point;
73 }
75 NR::Point getDirection() const {
76 return _direction;
77 }
79 private:
81 bool _has_point;
82 NR::Point _point;
83 NR::Point _direction;
84 };
86 SnappedPoint constrainedSnap(PointType const &t,
87 NR::Point const &p,
88 ConstraintLine const &c,
89 SPItem const *it) const;
91 SnappedPoint constrainedSnap(PointType const &t,
92 NR::Point const &p,
93 ConstraintLine const &c,
94 std::list<SPItem const *> const &it) const;
95 protected:
96 SPNamedView const *_named_view;
97 int _snap_from; ///< bitmap of point types that we will snap from
98 bool _enabled; ///< true if this snapper is enabled, otherwise false
100 private:
102 /**
103 * Try to snap a point to whatever this snapper is interested in. Any
104 * snap that occurs will be to the nearest "interesting" thing (e.g. a
105 * grid or guide line)
106 *
107 * \param p Point to snap (desktop coordinates).
108 * \param it Items that should not be snapped to.
109 * \return Snapped point.
110 */
111 virtual SnappedPoint _doFreeSnap(PointType const &t,
112 NR::Point const &p,
113 std::list<SPItem const *> const &it) const = 0;
115 /**
116 * Try to snap a point to whatever this snapper is interested in, where
117 * the snap point is constrained to lie along a specified vector from the
118 * original point.
119 *
120 * \param p Point to snap (desktop coordinates).
121 * \param c Vector to constrain the snap to.
122 * \param it Items that should not be snapped to.
123 * \return Snapped point.
124 */
125 virtual SnappedPoint _doConstrainedSnap(PointType const &t,
126 NR::Point const &p,
127 ConstraintLine const &c,
128 std::list<SPItem const *> const &it) const = 0;
130 ::NR::Coord _distance; ///< snap distance (desktop coordinates)
131 };
133 }
135 #endif /* !SEEN_SNAPPER_H */
137 /*
138 Local Variables:
139 mode:c++
140 c-file-style:"stroustrup"
141 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
142 indent-tabs-mode:nil
143 fill-column:99
144 End:
145 */
146 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :