Code

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