Code

51b5e7680542d9c61471cbb9fc2dea60b4f48fd1
[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 "libnr/nr-values.h"
16 #include "libnr/nr-point-fns.h"
17 #include "sp-namedview.h"
18 #include "sp-guide.h"
20 Inkscape::GuideSnapper::GuideSnapper(SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d)
21 {
23 }
25 Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point const &p) const
26 {
27     LineList s;
29     if ( NULL == _named_view || ThisSnapperMightSnap() == false) {
30         return s;
31     }
33     for (GSList const *l = _named_view->guides; l != NULL; l = l->next) {
34         SPGuide const *g = SP_GUIDE(l->data);
36         /* We assume here that guides are horizontal or vertical */
37         if (g->normal == component_vectors[NR::X]) {
38             s.push_back(std::make_pair(NR::X, g->position));
39         } else {
40             s.push_back(std::make_pair(NR::Y, g->position));
41         }
42     }
44     return s;
45 }
47 /**
48  *  \return true if this Snapper will snap at least one kind of point.
49  */
50 bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const
51 {
52     return _named_view == NULL ? false : (_enabled && _snap_from != 0 && _named_view->showguides);
53 }
55 void Inkscape::GuideSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const
56 {
57         SnappedInfiniteLine dummy = SnappedInfiniteLine(snapped_point, snapped_distance, normal_to_line, point_on_line);
58         sc.guide_lines.push_back(dummy);
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 :