79f30fa3ce4eb7bea27517b97f6eab8e2b5c66e6
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 /**
18 * Construct new Snapper for named view.
19 * \param nv Named view.
20 * \param d Snap tolerance.
21 */
22 Inkscape::Snapper::Snapper(SnapManager const *sm, Geom::Coord const t) :
23 _snapmanager(sm),
24 _snap_enabled(true),
25 _snapper_tolerance(std::max(t, 1.0))
26 {
27 g_assert(_snapmanager != NULL);
28 }
30 /**
31 * Set snap tolerance.
32 * \param d New snap tolerance (desktop coordinates)
33 */
34 void Inkscape::Snapper::setSnapperTolerance(Geom::Coord const d)
35 {
36 _snapper_tolerance = std::max(d, 1.0);
37 }
39 /**
40 * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels
41 */
42 Geom::Coord Inkscape::Snapper::getSnapperTolerance() const
43 {
44 return _snapper_tolerance / SP_ACTIVE_DESKTOP->current_zoom();
45 }
47 bool Inkscape::Snapper::getSnapperAlwaysSnap() const
48 {
49 return _snapper_tolerance == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
50 }
52 /**
53 * \param s true to enable this snapper, otherwise false.
54 */
56 void Inkscape::Snapper::setEnabled(bool s)
57 {
58 _snap_enabled = s;
59 }
61 /*
62 Local Variables:
63 mode:c++
64 c-file-style:"stroustrup"
65 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
66 indent-tabs-mode:nil
67 fill-column:99
68 End:
69 */
70 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :