X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsnapped-point.h;h=b50207429ab81c8ee2d6d3b0d87f515348acc10a;hb=1e25a603bad48b0bb68458f31c1c6e551a466bd2;hp=147922b2f9933c43c32df86f1f28dd790115a87e;hpb=e1da05d7d6b8a6d4ddbca0fd1d7e633a84b2c1cf;p=inkscape.git diff --git a/src/snapped-point.h b/src/snapped-point.h index 147922b2f..b50207429 100644 --- a/src/snapped-point.h +++ b/src/snapped-point.h @@ -7,6 +7,7 @@ * * Authors: * Mathieu Dimanche + * Diederik van Lierop * * Released under GNU GPL, read the file 'COPYING' for more information. */ @@ -15,26 +16,98 @@ #include #include "libnr/nr-coord.h" #include "libnr/nr-point.h" +#include namespace Inkscape { - + +enum SnapTargetType { + SNAPTARGET_UNDEFINED, + SNAPTARGET_GRID, + SNAPTARGET_GRID_INTERSECTION, + SNAPTARGET_GUIDE, + SNAPTARGET_GUIDE_INTERSECTION, + SNAPTARGET_GRID_GUIDE_INTERSECTION, + SNAPTARGET_NODE, + SNAPTARGET_PATH, + SNAPTARGET_PATH_INTERSECTION, + SNAPTARGET_BBOX_CORNER, + SNAPTARGET_BBOX_EDGE, + SNAPTARGET_GRADIENT +}; + /// Class describing the result of an attempt to snap. class SnappedPoint { + public: SnappedPoint(); - SnappedPoint(::NR::Point p, ::NR::Coord d, bool at_intersection = false); + SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, bool const &fully_constrained, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2); + SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &fully_constrained); ~SnappedPoint(); - NR::Coord getDistance() const; - NR::Point getPoint() const; + Geom::Coord getSnapDistance() const {return _distance;} + void setSnapDistance(Geom::Coord const d) {_distance = d;} + Geom::Coord getTolerance() const {return _tolerance;} + bool getAlwaysSnap() const {return _always_snap;} + Geom::Coord getSecondSnapDistance() const {return _second_distance;} + void setSecondSnapDistance(Geom::Coord const d) {_second_distance = d;} + Geom::Coord getSecondTolerance() const {return _second_tolerance;} + bool getSecondAlwaysSnap() const {return _second_always_snap;} + Geom::Coord getPointerDistance() const {return _pointer_distance;} + void setPointerDistance(Geom::Coord const d) {_pointer_distance = d;} + + /* This is the preferred method to find out which point we have snapped + * to, because it only returns a point if snapping has actually occured + * (by overwriting p) + */ + void getPoint(Geom::Point &p) const; + + /* This method however always returns a point, even if no snapping + * has occured; A check should be implemented in the calling code + * to check for snapping. Use this method only when really needed, e.g. + * when the calling code is trying to snap multiple points and must + * determine itself which point is most appropriate + */ + Geom::Point getPoint() const {return _point;} + bool getAtIntersection() const {return _at_intersection;} + bool getFullyConstrained() const {return _fully_constrained;} + bool getSnapped() const {return _distance < NR_HUGE;} + Geom::Point getTransformation() const {return _transformation;} + void setTransformation(Geom::Point const t) {_transformation = t;} + void setTarget(SnapTargetType const target) {_target = target;} + SnapTargetType getTarget() {return _target;} + + bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const; protected: - NR::Coord _distance; - NR::Point _point; - bool _at_intersection; + Geom::Point _point; // Location of the snapped point + SnapTargetType _target; // Describes to what we've snapped to + bool _at_intersection; // If true, the snapped point is at an intersection + bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained". + // When snapping to a line however, the snap is only partly constrained (i.e. only in one dimension) + + /* Distance from original point to snapped point. If the snapped point is at + an intersection of e.g. two lines, then this is the distance to the closest + line */ + Geom::Coord _distance; + /* The snapping tolerance in screen pixels (depends on zoom)*/ + Geom::Coord _tolerance; + /* If true then "Always snap" is on */ + bool _always_snap; + + /* If the snapped point is at an intersection of e.g. two lines, then this is + the distance to the fartest line */ + Geom::Coord _second_distance; + /* The snapping tolerance in screen pixels (depends on zoom)*/ + Geom::Coord _second_tolerance; + /* If true then "Always snap" is on */ + bool _second_always_snap; + /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */ + Geom::Point _transformation; + /* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */ + Geom::Coord _pointer_distance; }; }