Code

Indent support for XSLT extensions output.
[inkscape.git] / src / guide-snapper.cpp
1 /**
2  *  \file guide-snapper.cpp
3  *  \brief Snapping things to guides.
4  *
5  * Authors:
6  *   Lauris Kaplinski <lauris@kaplinski.com>
7  *   Frank Felfe <innerspace@iname.com>
8  *   Carl Hetherington <inkscape@carlh.net>
9  *
10  * Copyright (C) 1999-2002 Authors
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "sp-namedview.h"
16 #include "desktop.h"
17 #include "sp-guide.h"
19 Inkscape::GuideSnapper::GuideSnapper(SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d)
20 {
22 }
24 /**
25  *  \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels
26  */
27 Geom::Coord Inkscape::GuideSnapper::getSnapperTolerance() const
28 {
29     SPDesktop const *dt = _snapmanager->getDesktop();
30     double const zoom =  dt ? dt->current_zoom() : 1;
31     return _snapmanager->snapprefs.getGuideTolerance() / zoom;
32 }
34 bool Inkscape::GuideSnapper::getSnapperAlwaysSnap() const
35 {
36     return _snapmanager->snapprefs.getGuideTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
37 }
39 Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Point const &/*p*/) const
40 {
41     LineList s;
43     if ( NULL == _snapmanager->getNamedView() || ThisSnapperMightSnap() == false) {
44         return s;
45     }
47     SPGuide const *guide_to_ignore = _snapmanager->getGuideToIgnore();
49     for (GSList const *l = _snapmanager->getNamedView()->guides; l != NULL; l = l->next) {
50         SPGuide const *g = SP_GUIDE(l->data);
51         if (g != guide_to_ignore) {
52             s.push_back(std::make_pair(g->normal_to_line, g->point_on_line));
53         }
54     }
56     return s;
57 }
59 /**
60  *  \return true if this Snapper will snap at least one kind of point.
61  */
62 bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const
63 {
64     if (_snapmanager->getNamedView() == NULL) {
65         return false;
66     }
68     return (_snap_enabled && _snapmanager->snapprefs.getSnapToGuides() && _snapmanager->getNamedView()->showguides);
69 }
71 void Inkscape::GuideSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, long source_num, Geom::Point const normal_to_line, Geom::Point const point_on_line) const
72 {
73     SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, source_num, Inkscape::SNAPTARGET_GUIDE, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
74     sc.guide_lines.push_back(dummy);
75 }
77 void Inkscape::GuideSnapper::_addSnappedLinesOrigin(SnappedConstraints &sc, Geom::Point const origin, Geom::Coord const snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const
78 {
79     SnappedPoint dummy = SnappedPoint(origin, source, source_num, Inkscape::SNAPTARGET_GUIDE_ORIGIN, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), constrained_snap, true);
80     sc.points.push_back(dummy);
81 }
84 void Inkscape::GuideSnapper::_addSnappedPoint(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const
85 {
86     SnappedPoint dummy = SnappedPoint(snapped_point, source, source_num, Inkscape::SNAPTARGET_GUIDE, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), constrained_snap, true);
87     sc.points.push_back(dummy);
88 }
90 /*
91   Local Variables:
92   mode:c++
93   c-file-style:"stroustrup"
94   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
95   indent-tabs-mode:nil
96   fill-column:99
97   End:
98 */
99 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :