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 _snap_to_itemnode(true), _snap_to_itempath(true),
28 _snap_to_bboxnode(true), _snap_to_bboxpath(true),
29 _snap_to_page_border(false),
30 _strict_snapping(true)
31 {
32 setSnapFrom(SNAPPOINT_BBOX | SNAPPOINT_NODE, true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
33 }
35 /*
36 * The snappers have too many parameters to adjust individually. Therefore only
37 * two snapping modes are presented to the user: snapping bounding box corners (to
38 * other bounding boxes, grids or guides), and/or snapping nodes (to other nodes,
39 * paths, grids or guides). To select either of these modes (or both), use the
40 * methods defined below: setSnapModeBBox() and setSnapModeNode().
41 *
42 * */
45 void Inkscape::SnapPreferences::setSnapModeBBox(bool enabled)
46 {
47 if (enabled) {
48 _snap_from |= Inkscape::SnapPreferences::SNAPPOINT_BBOX;
49 } else {
50 _snap_from &= ~Inkscape::SnapPreferences::SNAPPOINT_BBOX;
51 }
52 }
54 bool Inkscape::SnapPreferences::getSnapModeBBox() const
55 {
56 return (_snap_from & Inkscape::SnapPreferences::SNAPPOINT_BBOX);
57 }
59 void Inkscape::SnapPreferences::setSnapModeNode(bool enabled)
60 {
61 if (enabled) {
62 _snap_from |= Inkscape::SnapPreferences::SNAPPOINT_NODE;
63 } else {
64 _snap_from &= ~Inkscape::SnapPreferences::SNAPPOINT_NODE;
65 }
66 }
68 bool Inkscape::SnapPreferences::getSnapModeNode() const
69 {
70 return (_snap_from & Inkscape::SnapPreferences::SNAPPOINT_NODE);
71 }
73 bool Inkscape::SnapPreferences::getSnapModeBBoxOrNodes() const
74 {
75 return (_snap_from & (Inkscape::SnapPreferences::SNAPPOINT_BBOX | Inkscape::SnapPreferences::SNAPPOINT_NODE) );
76 }
78 bool Inkscape::SnapPreferences::getSnapModeAny() const
79 {
80 return (_snap_from != 0);
81 }
83 void Inkscape::SnapPreferences::setSnapModeGuide(bool enabled)
84 {
85 if (enabled) {
86 _snap_from |= Inkscape::SnapPreferences::SNAPPOINT_GUIDE;
87 } else {
88 _snap_from &= ~Inkscape::SnapPreferences::SNAPPOINT_GUIDE;
89 }
90 }
92 bool Inkscape::SnapPreferences::getSnapModeGuide() const
93 {
94 return (_snap_from & Inkscape::SnapPreferences::SNAPPOINT_GUIDE);
95 }
97 /**
98 * Turn on/off snapping of specific point types.
99 * \param t Point type.
100 * \param s true to snap to this point type, otherwise false;
101 */
102 void Inkscape::SnapPreferences::setSnapFrom(PointType t, bool s)
103 {
104 if (s) {
105 _snap_from |= t;
106 } else {
107 _snap_from &= ~t;
108 }
109 }
111 /**
112 * \param t Point type.
113 * \return true if snapper will snap this type of point, otherwise false.
114 */
115 bool Inkscape::SnapPreferences::getSnapFrom(PointType t) const
116 {
117 return (_snap_from & t);
118 }
120 /*
121 Local Variables:
122 mode:c++
123 c-file-style:"stroustrup"
124 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
125 indent-tabs-mode:nil
126 fill-column:99
127 End:
128 */
129 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :