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 * Diederik van Lierop <mail@diedenrezi.nl>
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information.
13 */
15 #include <map>
16 #include <list>
17 #include "libnr/nr-coord.h"
18 #include "libnr/nr-point.h"
19 #include "libnr/nr-maybe.h"
21 #include "snapped-point.h"
22 #include "snapped-line.h"
24 struct SnappedConstraints {
25 std::list<Inkscape::SnappedPoint> points;
26 std::list<Inkscape::SnappedLineSegment> lines;
27 std::list<Inkscape::SnappedLine> grid_lines;
28 std::list<Inkscape::SnappedLine> guide_lines;
29 };
31 struct SPNamedView;
32 struct SPItem;
34 namespace Inkscape
35 {
37 /// Parent for classes that can snap points to something
38 class Snapper
39 {
40 public:
41 Snapper() {}
42 Snapper(SPNamedView const *nv, ::NR::Coord const d);
43 virtual ~Snapper() {}
45 /// Point types to snap.
46 typedef int PointType;
47 static const PointType SNAPPOINT_NODE;
48 static const PointType SNAPPOINT_BBOX;
49 static const PointType SNAPPOINT_GUIDE;
51 void setSnapFrom(PointType t, bool s);
52 bool getSnapFrom(PointType t) const;
54 void setSnapperTolerance(NR::Coord t);
55 NR::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
56 bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance
58 /**
59 * \return true if this Snapper will snap at least one kind of point.
60 */
61 virtual bool ThisSnapperMightSnap() const {return (_snap_enabled && _snap_from != 0);} // will likely be overridden by derived classes
63 void setEnabled(bool s);
64 bool getEnabled() const {return _snap_enabled;}
66 virtual void freeSnap(SnappedConstraints &/*sc*/,
67 PointType const &/*t*/,
68 NR::Point const &/*p*/,
69 bool const &/*first_point*/,
70 NR::Maybe<NR::Rect> const &/*bbox_to_snap*/,
71 std::vector<SPItem const *> const */*it*/,
72 std::vector<NR::Point> */*unselected_nodes*/) const {};
74 class ConstraintLine
75 {
76 public:
77 ConstraintLine(NR::Point const &d) : _has_point(false), _direction(d) {}
78 ConstraintLine(NR::Point const &p, NR::Point const &d) : _has_point(true), _point(p), _direction(d) {}
80 bool hasPoint() const {
81 return _has_point;
82 }
84 NR::Point getPoint() const {
85 return _point;
86 }
88 NR::Point getDirection() const {
89 return _direction;
90 }
92 void setPoint(NR::Point const &p) {
93 _point = p;
94 _has_point = true;
95 }
97 private:
99 bool _has_point;
100 NR::Point _point;
101 NR::Point _direction;
102 };
104 virtual void constrainedSnap(SnappedConstraints &/*sc*/,
105 PointType const &/*t*/,
106 NR::Point const &/*p*/,
107 bool const &/*first_point*/,
108 NR::Maybe<NR::Rect> const &/*bbox_to_snap*/,
109 ConstraintLine const &/*c*/,
110 std::vector<SPItem const *> const */*it*/) const {};
112 protected:
113 SPNamedView const *_named_view;
114 int _snap_from; ///< bitmap of point types that we will snap from
115 bool _snap_enabled; ///< true if this snapper is enabled, otherwise false
117 private:
118 NR::Coord _snapper_tolerance; ///< snap tolerance in desktop coordinates
119 // must be private to enforce the usage of getTolerance(), which retrieves
120 // the tolerance in screen pixels (making it zoom independent)
122 };
124 }
126 #endif /* !SEEN_SNAPPER_H */
128 /*
129 Local Variables:
130 mode:c++
131 c-file-style:"stroustrup"
132 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
133 indent-tabs-mode:nil
134 fill-column:99
135 End:
136 */
137 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :