~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/snap.h

  • Committer: Diederik van Lierop
  • Date: 2010-01-09 21:14:38 UTC
  • Revision ID: diederik_van_lierop_mail_at-sign_diedenrezi_dot_nl-20100109211438-ciqi6nxmir7zvv6x
Refactoring the snapping API (making it easier to maintain and understand for the devs)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 *
21
21
 * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
22
22
 * Copyright (C) 2000-2002 Lauris Kaplinski
23
 
 * Copyright (C) 2000-2009 Authors
 
23
 * Copyright (C) 2000-2010 Authors
24
24
 *
25
25
 * Released under GNU GPL, read the file 'COPYING' for more information
26
26
 */
69
69
    void setup(SPDesktop const *desktop,
70
70
            bool snapindicator = true,
71
71
            SPItem const *item_to_ignore = NULL,
72
 
            std::vector<std::pair<Geom::Point, int> > *unselected_nodes = NULL,
 
72
            std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes = NULL,
73
73
            SPGuide *guide_to_ignore = NULL);
74
74
 
75
75
    void setup(SPDesktop const *desktop,
76
76
            bool snapindicator,
77
77
            std::vector<SPItem const *> &items_to_ignore,
78
 
            std::vector<std::pair<Geom::Point, int> > *unselected_nodes = NULL,
 
78
            std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes = NULL,
79
79
            SPGuide *guide_to_ignore = NULL);
80
80
 
81
81
    // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a
83
83
    void freeSnapReturnByRef(Inkscape::SnapPreferences::PointType point_type,
84
84
                                Geom::Point &p,
85
85
                                Inkscape::SnapSourceType const source_type,
86
 
                                long source_num = 0,
87
86
                                Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
88
87
 
89
 
 
90
 
    Inkscape::SnappedPoint freeSnap(Inkscape::SnapPreferences::PointType point_type,
91
 
                                    Geom::Point const &p,
92
 
                                    Inkscape::SnapSourceType const &source_type,
93
 
                                    long source_num = 0,
 
88
    Inkscape::SnappedPoint freeSnap(Inkscape::SnapPreferences::PointType const point_type,
 
89
                                    Inkscape::SnapCandidatePoint const &p,
94
90
                                    Geom::OptRect const &bbox_to_snap = Geom::OptRect() ) const;
95
91
 
96
92
    Geom::Point multipleOfGridPitch(Geom::Point const &t) const;
101
97
                                    Geom::Point &p,
102
98
                                    Inkscape::SnapSourceType const source_type,
103
99
                                    Inkscape::Snapper::ConstraintLine const &constraint,
104
 
                                    long source_num = 0,
105
100
                                    Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
106
101
 
107
 
    Inkscape::SnappedPoint constrainedSnap(Inkscape::SnapPreferences::PointType point_type,
108
 
                                           Geom::Point const &p,
109
 
                                           Inkscape::SnapSourceType const &source_type,
 
102
    Inkscape::SnappedPoint constrainedSnap(Inkscape::SnapPreferences::PointType const point_type,
 
103
                                           Inkscape::SnapCandidatePoint const &p,
110
104
                                           Inkscape::Snapper::ConstraintLine const &constraint,
111
 
                                           long source_num = 0,
112
105
                                           Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
113
106
 
114
107
    void guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal, SPGuideDragType drag_type) const;
115
108
    void guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) const;
116
109
 
117
110
    Inkscape::SnappedPoint freeSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
118
 
                                               std::vector<std::pair<Geom::Point, int> > const &p,
 
111
                                               std::vector<Inkscape::SnapCandidatePoint> const &p,
119
112
                                               Geom::Point const &pointer,
120
113
                                               Geom::Point const &tr) const;
121
114
 
122
115
    Inkscape::SnappedPoint constrainedSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
123
 
                                                      std::vector<std::pair<Geom::Point, int> > const &p,
 
116
                                                      std::vector<Inkscape::SnapCandidatePoint> const &p,
124
117
                                                      Geom::Point const &pointer,
125
118
                                                      Inkscape::Snapper::ConstraintLine const &constraint,
126
119
                                                      Geom::Point const &tr) const;
127
120
 
128
121
    Inkscape::SnappedPoint freeSnapScale(Inkscape::SnapPreferences::PointType point_type,
129
 
                                         std::vector<std::pair<Geom::Point, int> > const &p,
 
122
                                         std::vector<Inkscape::SnapCandidatePoint> const &p,
130
123
                                         Geom::Point const &pointer,
131
124
                                         Geom::Scale const &s,
132
125
                                         Geom::Point const &o) const;
133
126
 
134
127
    Inkscape::SnappedPoint constrainedSnapScale(Inkscape::SnapPreferences::PointType point_type,
135
 
                                                std::vector<std::pair<Geom::Point, int> > const &p,
 
128
                                                std::vector<Inkscape::SnapCandidatePoint> const &p,
136
129
                                                Geom::Point const &pointer,
137
130
                                                Geom::Scale const &s,
138
131
                                                Geom::Point const &o) const;
139
132
 
140
133
    Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::SnapPreferences::PointType point_type,
141
 
                                                  std::vector<std::pair<Geom::Point, int> > const &p,
 
134
                                                  std::vector<Inkscape::SnapCandidatePoint> const &p,
142
135
                                                  Geom::Point const &pointer,
143
136
                                                  Geom::Coord const &s,
144
137
                                                  Geom::Point const &o,
146
139
                                                  bool uniform) const;
147
140
 
148
141
    Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::SnapPreferences::PointType point_type,
149
 
                                               std::vector<std::pair<Geom::Point, int> > const &p,
 
142
                                               std::vector<Inkscape::SnapCandidatePoint> const &p,
150
143
                                               Geom::Point const &pointer,
151
144
                                               Inkscape::Snapper::ConstraintLine const &constraint,
152
145
                                               Geom::Point const &s, // s[0] = skew factor, s[1] = scale factor
167
160
 
168
161
    bool getSnapIndicator() const {return _snapindicator;}
169
162
 
170
 
    Inkscape::SnappedPoint findBestSnap(Geom::Point const &p, Inkscape::SnapSourceType const source_type, SnappedConstraints &sc, bool constrained, bool noCurves = false) const;
 
163
    Inkscape::SnappedPoint findBestSnap(Inkscape::SnapCandidatePoint const &p, SnappedConstraints const &sc, bool constrained, bool noCurves = false) const;
171
164
 
172
165
protected:
173
166
    SPNamedView const *_named_view;
178
171
    SPGuide *_guide_to_ignore; ///< A guide that should not be snapped to, e.g. the guide that is currently being dragged
179
172
    SPDesktop const *_desktop;
180
173
    bool _snapindicator; ///< When true, an indicator will be drawn at the position that was being snapped to
181
 
    std::vector<std::pair<Geom::Point, int> > *_unselected_nodes; ///< Nodes of the path that is currently being edited and which have not been selected and which will therefore be stationary. Only these nodes will be considered for snapping to. Of each unselected node both the position (Geom::Point) and the type (Inkscape::SnapTargetType) will be stored
 
174
    std::vector<Inkscape::SnapCandidatePoint> *_unselected_nodes; ///< Nodes of the path that is currently being edited and which have not been selected and which will therefore be stationary. Only these nodes will be considered for snapping to. Of each unselected node both the position (Geom::Point) and the type (Inkscape::SnapTargetType) will be stored
182
175
    //TODO: Make _unselected_nodes type safe; in the line above int is used for Inkscape::SnapTargetType, but if I remember
183
176
    //correctly then in other cases the int is being used for Inkscape::SnapSourceType, or for both. How to make
184
177
    //this type safe?
185
178
 
186
179
    Inkscape::SnappedPoint _snapTransformed(Inkscape::SnapPreferences::PointType type,
187
 
                                            std::vector<std::pair<Geom::Point, int> > const &points,
 
180
                                            std::vector<Inkscape::SnapCandidatePoint> const &points,
188
181
                                            Geom::Point const &pointer,
189
182
                                            bool constrained,
190
183
                                            Inkscape::Snapper::ConstraintLine const &constraint,
194
187
                                            Geom::Dim2 dim,
195
188
                                            bool uniform) const;
196
189
 
197
 
    Geom::Point _transformPoint(std::pair<Geom::Point, int> const &p,
 
190
    Geom::Point _transformPoint(Inkscape::SnapCandidatePoint const &p,
198
191
                                            Transformation const transformation_type,
199
192
                                            Geom::Point const &transformation,
200
193
                                            Geom::Point const &origin,
201
194
                                            Geom::Dim2 const dim,
202
195
                                            bool const uniform) const;
203
196
 
204
 
    void _displaySnapsource(Inkscape::SnapPreferences::PointType point_type, std::pair<Geom::Point, int> const &p) const;
 
197
    void _displaySnapsource(Inkscape::SnapPreferences::PointType point_type, Inkscape::SnapCandidatePoint const &p) const;
205
198
};
206
199
 
207
200
#endif /* !SEEN_SNAP_H */