1 /**
2 * \file src/snapper.cpp
3 * \brief Snapper class.
4 *
5 * Authors:
6 * Carl Hetherington <inkscape@carlh.net>
7 * Diederik van Lierop <mail@diedenrezi.nl>
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information.
10 */
12 #include "libnr/nr-values.h"
13 #include "sp-namedview.h"
14 #include "inkscape.h"
15 #include "desktop.h"
17 Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_BBOX = 0x1;
18 Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_NODE = 0x2;
19 Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_GUIDE = 0x4;
21 /**
22 * Construct new Snapper for named view.
23 * \param nv Named view.
24 * \param d Snap tolerance.
25 */
26 Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const t) : _named_view(nv), _snap_enabled(true), _snapper_tolerance(t)
27 {
28 g_assert(_named_view != NULL);
29 g_assert(SP_IS_NAMEDVIEW(_named_view));
31 setSnapFrom(SNAPPOINT_BBOX | SNAPPOINT_NODE, true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
32 }
34 /**
35 * Set snap tolerance.
36 * \param d New snap tolerance (desktop coordinates)
37 */
38 void Inkscape::Snapper::setSnapperTolerance(NR::Coord const d)
39 {
40 _snapper_tolerance = d;
41 }
43 /**
44 * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels
45 */
46 NR::Coord Inkscape::Snapper::getSnapperTolerance() const
47 {
48 return _snapper_tolerance / SP_ACTIVE_DESKTOP->current_zoom();
49 }
51 bool Inkscape::Snapper::getSnapperAlwaysSnap() const
52 {
53 return _snapper_tolerance == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
54 }
56 /**
57 * Turn on/off snapping of specific point types.
58 * \param t Point type.
59 * \param s true to snap to this point type, otherwise false;
60 */
61 void Inkscape::Snapper::setSnapFrom(PointType t, bool s)
62 {
63 if (s) {
64 _snap_from |= t;
65 } else {
66 _snap_from &= ~t;
67 }
68 }
70 /**
71 * \param t Point type.
72 * \return true if snapper will snap this type of point, otherwise false.
73 */
74 bool Inkscape::Snapper::getSnapFrom(PointType t) const
75 {
76 return (_snap_from & t);
77 }
79 /**
80 * \param s true to enable this snapper, otherwise false.
81 */
83 void Inkscape::Snapper::setEnabled(bool s)
84 {
85 _snap_enabled = s;
86 }
88 /*
89 Local Variables:
90 mode:c++
91 c-file-style:"stroustrup"
92 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
93 indent-tabs-mode:nil
94 fill-column:99
95 End:
96 */
97 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :