Code

Don't use SP_ACTIVE_DESKTOP
[inkscape.git] / src / snapper.cpp
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         SPDesktop const *dt = _snapmanager->getDesktop();
45         double const zoom =  dt ? dt->current_zoom() : 1;
46         return _snapper_tolerance / zoom;
47 }
49 bool Inkscape::Snapper::getSnapperAlwaysSnap() const
50 {
51     return _snapper_tolerance == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
52 }
54 /**
55  *  \param s true to enable this snapper, otherwise false.
56  */
58 void Inkscape::Snapper::setEnabled(bool s)
59 {
60     _snap_enabled = s;
61 }
63 /*
64   Local Variables:
65   mode:c++
66   c-file-style:"stroustrup"
67   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
68   indent-tabs-mode:nil
69   fill-column:99
70   End:
71 */
72 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :