Code

Color Matrix Filter:
[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  *
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;
38     static const PointType SNAPPOINT_GUIDE;
40     void setSnapFrom(PointType t, bool s);
41     void setDistance(::NR::Coord d);
43     bool getSnapFrom(PointType t) const;
44     ::NR::Coord getDistance() const;
46     /**
47     *  \return true if this Snapper will snap at least one kind of point.
48     */
49     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                           bool const &first_point,                                             
56                           std::vector<NR::Point> &points_to_snap,                                                
57                           SPItem const *it) const;
59     SnappedPoint freeSnap(PointType const &t,
60                           NR::Point const &p,
61                           bool const &first_point,                                             
62                           std::vector<NR::Point> &points_to_snap,                                                
63                           std::list<SPItem const *> const &it) const;
65     class ConstraintLine
66     {
67     public:
68         ConstraintLine(NR::Point const &d) : _has_point(false), _direction(d) {}
69         ConstraintLine(NR::Point const &p, NR::Point const &d) : _has_point(true), _point(p), _direction(d) {}
71         bool hasPoint() const {
72             return _has_point;
73         }
75         NR::Point getPoint() const {
76             return _point;
77         }
79         NR::Point getDirection() const {
80             return _direction;
81         }
82         
83     private:
85         bool _has_point;
86         NR::Point _point;
87         NR::Point _direction;
88     };
90     SnappedPoint constrainedSnap(PointType const &t,
91                                  NR::Point const &p,
92                                  bool const &first_point,
93                                  std::vector<NR::Point> &points_to_snap,       
94                                  ConstraintLine const &c,
95                                  SPItem const *it) const;
97     SnappedPoint constrainedSnap(PointType const &t,
98                                  NR::Point const &p,
99                                  bool const &first_point,
100                                  std::vector<NR::Point> &points_to_snap,                                                 
101                                  ConstraintLine const &c,
102                                  std::list<SPItem const *> const &it) const;
103 protected:
104     SPNamedView const *_named_view;
105     int _snap_from; ///< bitmap of point types that we will snap from
106     bool _enabled; ///< true if this snapper is enabled, otherwise false
107     
108 private:
110     /**
111      *  Try to snap a point to whatever this snapper is interested in.  Any
112      *  snap that occurs will be to the nearest "interesting" thing (e.g. a
113      *  grid or guide line)
114      *
115      *  \param p Point to snap (desktop coordinates).
116      *  \param it Items that should not be snapped to.
117      *  \return Snapped point.
118      */
119     virtual SnappedPoint _doFreeSnap(PointType const &t,
120                                                                  NR::Point const &p,
121                                                                  bool const &first_point,                                             
122                                                                  std::vector<NR::Point> &points_to_snap,
123                                      std::list<SPItem const *> const &it) const = 0;
125     /**
126      *  Try to snap a point to whatever this snapper is interested in, where
127      *  the snap point is constrained to lie along a specified vector from the
128      *  original point.
129      *
130      *  \param p Point to snap (desktop coordinates).
131      *  \param c Vector to constrain the snap to.
132      *  \param it Items that should not be snapped to.
133      *  \return Snapped point.
134      */    
135     virtual SnappedPoint _doConstrainedSnap(PointType const &t,
136                                                                                 NR::Point const &p,
137                                                                                 bool const &first_point,
138                                                                                 std::vector<NR::Point> &points_to_snap,
139                                             ConstraintLine const &c,
140                                             std::list<SPItem const *> const &it) const = 0;
141     
142     ::NR::Coord _distance; ///< snap distance (desktop coordinates)
143 };
147 #endif /* !SEEN_SNAPPER_H */
149 /*
150   Local Variables:
151   mode:c++
152   c-file-style:"stroustrup"
153   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
154   indent-tabs-mode:nil
155   fill-column:99
156   End:
157 */
158 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :