Code

Warning and whitespace cleanup
[inkscape.git] / src / snapper.h
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     private:
94         bool _has_point;
95         NR::Point _point;
96         NR::Point _direction;
97     };
99     virtual void constrainedSnap(SnappedConstraints &/*sc*/,
100                                  PointType const &/*t*/,
101                                  NR::Point const &/*p*/,
102                                  bool const &/*first_point*/,
103                                  NR::Maybe<NR::Rect> const &/*bbox_to_snap*/,
104                                  ConstraintLine const &/*c*/,
105                                  std::vector<SPItem const *> const */*it*/) const {};
107 protected:
108     SPNamedView const *_named_view;
109     int _snap_from; ///< bitmap of point types that we will snap from
110     bool _snap_enabled; ///< true if this snapper is enabled, otherwise false
112 private:
113     NR::Coord _snapper_tolerance;   ///< snap tolerance in desktop coordinates
114                                     // must be private to enforce the usage of getTolerance(), which retrieves
115                                     // the tolerance in screen pixels (making it zoom independent)
117 };
121 #endif /* !SEEN_SNAPPER_H */
123 /*
124   Local Variables:
125   mode:c++
126   c-file-style:"stroustrup"
127   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
128   indent-tabs-mode:nil
129   fill-column:99
130   End:
131 */
132 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :