1 #define __SNAPPREFERENCES_CPP__
3 /**
4 * \file snap-preferences.cpp
5 * \brief Storing of snapping preferences
6 *
7 * Authors:
8 * Diederik van Lierop <mail@diedenrezi.nl>
9 *
10 * Copyright (C) 2008 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include "inkscape.h"
16 #include "snap-preferences.h"
18 Inkscape::SnapPreferences::PointType const Inkscape::SnapPreferences::SNAPPOINT_NODE = 0x1;
19 Inkscape::SnapPreferences::PointType const Inkscape::SnapPreferences::SNAPPOINT_BBOX = 0x2;
20 Inkscape::SnapPreferences::PointType const Inkscape::SnapPreferences::SNAPPOINT_GUIDE = 0x4;
23 Inkscape::SnapPreferences::SnapPreferences() :
24 _include_item_center(false),
25 _snap_enabled_globally(true),
26 _snap_postponed_globally(false)
27 {
28 setSnapFrom(SNAPPOINT_BBOX | SNAPPOINT_NODE, true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
29 }
31 /*
32 * The snappers have too many parameters to adjust individually. Therefore only
33 * two snapping modes are presented to the user: snapping bounding box corners (to
34 * other bounding boxes, grids or guides), and/or snapping nodes (to other nodes,
35 * paths, grids or guides). To select either of these modes (or both), use the
36 * methods defined below: setSnapModeBBox() and setSnapModeNode().
37 *
38 * */
41 void Inkscape::SnapPreferences::setSnapModeBBox(bool enabled)
42 {
43 if (enabled) {
44 _snap_from |= Inkscape::SnapPreferences::SNAPPOINT_BBOX;
45 } else {
46 _snap_from &= ~Inkscape::SnapPreferences::SNAPPOINT_BBOX;
47 }
48 }
50 bool Inkscape::SnapPreferences::getSnapModeBBox() const
51 {
52 return (_snap_from & Inkscape::SnapPreferences::SNAPPOINT_BBOX);
53 }
55 void Inkscape::SnapPreferences::setSnapModeNode(bool enabled)
56 {
57 if (enabled) {
58 _snap_from |= Inkscape::SnapPreferences::SNAPPOINT_NODE;
59 } else {
60 _snap_from &= ~Inkscape::SnapPreferences::SNAPPOINT_NODE;
61 }
62 }
64 bool Inkscape::SnapPreferences::getSnapModeNode() const
65 {
66 return (_snap_from & Inkscape::SnapPreferences::SNAPPOINT_NODE);
67 }
69 bool Inkscape::SnapPreferences::getSnapModeBBoxOrNodes() const
70 {
71 return (_snap_from & (Inkscape::SnapPreferences::SNAPPOINT_BBOX | Inkscape::SnapPreferences::SNAPPOINT_NODE) );
72 }
74 bool Inkscape::SnapPreferences::getSnapModeAny() const
75 {
76 return (_snap_from != 0);
77 }
79 void Inkscape::SnapPreferences::setSnapModeGuide(bool enabled)
80 {
81 if (enabled) {
82 _snap_from |= Inkscape::SnapPreferences::SNAPPOINT_GUIDE;
83 } else {
84 _snap_from &= ~Inkscape::SnapPreferences::SNAPPOINT_GUIDE;
85 }
86 }
88 bool Inkscape::SnapPreferences::getSnapModeGuide() const
89 {
90 return (_snap_from & Inkscape::SnapPreferences::SNAPPOINT_GUIDE);
91 }
93 /**
94 * Turn on/off snapping of specific point types.
95 * \param t Point type.
96 * \param s true to snap to this point type, otherwise false;
97 */
98 void Inkscape::SnapPreferences::setSnapFrom(PointType t, bool s)
99 {
100 if (s) {
101 _snap_from |= t;
102 } else {
103 _snap_from &= ~t;
104 }
105 }
107 /**
108 * \param t Point type.
109 * \return true if snapper will snap this type of point, otherwise false.
110 */
111 bool Inkscape::SnapPreferences::getSnapFrom(PointType t) const
112 {
113 return (_snap_from & t);
114 }
116 /*
117 Local Variables:
118 mode:c++
119 c-file-style:"stroustrup"
120 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
121 indent-tabs-mode:nil
122 fill-column:99
123 End:
124 */
125 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :