~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/snapped-point.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef SEEN_SNAPPEDPOINT_H
 
2
#define SEEN_SNAPPEDPOINT_H
 
3
 
 
4
/**
 
5
 *    \file src/snapped-point.h
 
6
 *    \brief SnappedPoint class.
 
7
 *
 
8
 *    Authors:
 
9
 *      Mathieu Dimanche <mdimanche@free.fr>
 
10
 *      Diederik van Lierop <mail@diedenrezi.nl>
 
11
 *
 
12
 *    Released under GNU GPL, read the file 'COPYING' for more information.
 
13
 */
 
14
 
 
15
#include <vector>
 
16
#include <list>
 
17
#include <libnr/nr-values.h> //Because of NR_HUGE
 
18
#include <2geom/geom.h>
 
19
 
 
20
namespace Inkscape
 
21
{
 
22
 
 
23
enum SnapTargetType {
 
24
    SNAPTARGET_UNDEFINED = 0,
 
25
    SNAPTARGET_GRID,
 
26
    SNAPTARGET_GRID_INTERSECTION,
 
27
    SNAPTARGET_GUIDE,
 
28
    SNAPTARGET_GUIDE_INTERSECTION,
 
29
    SNAPTARGET_GRID_GUIDE_INTERSECTION,
 
30
    SNAPTARGET_NODE_SMOOTH,
 
31
    SNAPTARGET_NODE_CUSP,
 
32
    SNAPTARGET_LINE_MIDPOINT,
 
33
    SNAPTARGET_OBJECT_MIDPOINT,
 
34
    SNAPTARGET_ROTATION_CENTER,
 
35
    SNAPTARGET_HANDLE,
 
36
    SNAPTARGET_PATH,
 
37
    SNAPTARGET_PATH_INTERSECTION,
 
38
    SNAPTARGET_BBOX_CORNER,
 
39
    SNAPTARGET_BBOX_EDGE,
 
40
    SNAPTARGET_BBOX_EDGE_MIDPOINT,
 
41
    SNAPTARGET_BBOX_MIDPOINT,
 
42
    SNAPTARGET_GRADIENTS_PARENT_BBOX,
 
43
    SNAPTARGET_PAGE_BORDER,
 
44
    SNAPTARGET_PAGE_CORNER,
 
45
    SNAPTARGET_CONVEX_HULL_CORNER,
 
46
    SNAPTARGET_ELLIPSE_QUADRANT_POINT,
 
47
    SNAPTARGET_CENTER, // of ellipse
 
48
    SNAPTARGET_CORNER, // of image or of rectangle
 
49
    SNAPTARGET_TEXT_BASELINE
 
50
};
 
51
 
 
52
enum SnapSourceType {
 
53
    SNAPSOURCE_UNDEFINED = 0,
 
54
    SNAPSOURCE_BBOX_CORNER,
 
55
    SNAPSOURCE_BBOX_MIDPOINT,
 
56
    SNAPSOURCE_BBOX_EDGE_MIDPOINT,
 
57
    SNAPSOURCE_NODE_SMOOTH,
 
58
    SNAPSOURCE_NODE_CUSP,
 
59
    SNAPSOURCE_LINE_MIDPOINT,
 
60
    SNAPSOURCE_OBJECT_MIDPOINT,
 
61
    SNAPSOURCE_ROTATION_CENTER,
 
62
    SNAPSOURCE_HANDLE,
 
63
    SNAPSOURCE_PATH_INTERSECTION,
 
64
    SNAPSOURCE_GUIDE,
 
65
    SNAPSOURCE_GUIDE_ORIGIN,
 
66
    SNAPSOURCE_CONVEX_HULL_CORNER,
 
67
    SNAPSOURCE_ELLIPSE_QUADRANT_POINT,
 
68
    SNAPSOURCE_CENTER, // of ellipse
 
69
    SNAPSOURCE_CORNER, // of image or of rectangle
 
70
    SNAPSOURCE_TEXT_BASELINE
 
71
};
 
72
 
 
73
 
 
74
/// Class describing the result of an attempt to snap.
 
75
class SnappedPoint
 
76
{
 
77
 
 
78
public:
 
79
    SnappedPoint();
 
80
    SnappedPoint(Geom::Point const &p, SnapSourceType const &source, 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);
 
81
    SnappedPoint(Geom::Point const &p, SnapSourceType const &source, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &fully_constrained);
 
82
    ~SnappedPoint();
 
83
 
 
84
    Geom::Coord getSnapDistance() const {return _distance;}
 
85
    void setSnapDistance(Geom::Coord const d) {_distance = d;}
 
86
    Geom::Coord getTolerance() const {return _tolerance;}
 
87
    bool getAlwaysSnap() const {return _always_snap;}
 
88
    Geom::Coord getSecondSnapDistance() const {return _second_distance;}
 
89
    void setSecondSnapDistance(Geom::Coord const d) {_second_distance = d;}
 
90
    Geom::Coord getSecondTolerance() const {return _second_tolerance;}
 
91
    bool getSecondAlwaysSnap() const {return _second_always_snap;}
 
92
    Geom::Coord getPointerDistance() const {return _pointer_distance;}
 
93
    void setPointerDistance(Geom::Coord const d) {_pointer_distance = d;}
 
94
 
 
95
    /* This is the preferred method to find out which point we have snapped
 
96
     * to, because it only returns a point if snapping has actually occurred
 
97
     * (by overwriting p)
 
98
     */
 
99
    void getPoint(Geom::Point &p) const;
 
100
 
 
101
    /* This method however always returns a point, even if no snapping
 
102
     * has occurred; A check should be implemented in the calling code
 
103
     * to check for snapping. Use this method only when really needed, e.g.
 
104
     * when the calling code is trying to snap multiple points and must
 
105
     * determine itself which point is most appropriate
 
106
     */
 
107
    Geom::Point getPoint() const {return _point;}
 
108
 
 
109
    bool getAtIntersection() const {return _at_intersection;}
 
110
    bool getFullyConstrained() const {return _fully_constrained;}
 
111
    bool getSnapped() const {return _distance < NR_HUGE;}
 
112
    Geom::Point getTransformation() const {return _transformation;}
 
113
    void setTransformation(Geom::Point const t) {_transformation = t;}
 
114
    void setTarget(SnapTargetType const target) {_target = target;}
 
115
    SnapTargetType getTarget() const {return _target;}
 
116
    void setSource(SnapSourceType const source) {_source = source;}
 
117
        SnapSourceType getSource() const {return _source;}
 
118
 
 
119
    bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;
 
120
 
 
121
    /*void dump() const {
 
122
        std::cout << "_point              = " << _point << std::endl;
 
123
        std::cout << "_source             = " << _source << std::endl;
 
124
        std::cout << "_target             = " << _target << std::endl;
 
125
        std::cout << "_at_intersection    = " << _at_intersection << std::endl;
 
126
        std::cout << "_fully_constrained  = " << _fully_constrained << std::endl;
 
127
        std::cout << "_distance           = " << _distance << std::endl;
 
128
        std::cout << "_tolerance          = " << _tolerance << std::endl;
 
129
        std::cout << "_always_snap        = " << _always_snap << std::endl;
 
130
        std::cout << "_second_distance    = " << _second_distance << std::endl;
 
131
        std::cout << "_second_tolerance   = " << _second_tolerance << std::endl;
 
132
        std::cout << "_second_always_snap = " << _second_always_snap << std::endl;
 
133
        std::cout << "_transformation     = " << _transformation << std::endl;
 
134
        std::cout << "_pointer_distance   = " << _pointer_distance << std::endl;
 
135
    }*/
 
136
 
 
137
protected:
 
138
    Geom::Point _point; // Location of the snapped point
 
139
    SnapSourceType _source; // Describes what snapped
 
140
    SnapTargetType _target; // Describes to what we've snapped to
 
141
    bool _at_intersection; // If true, the snapped point is at an intersection
 
142
    bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained".
 
143
                            // When snapping to a line however, the snap is only partly constrained (i.e. only in one dimension)
 
144
 
 
145
    /* Distance from original point to snapped point. If the snapped point is at
 
146
       an intersection of e.g. two lines, then this is the distance to the closest
 
147
       line */
 
148
    Geom::Coord _distance;
 
149
    /* The snapping tolerance in screen pixels (depends on zoom)*/
 
150
    Geom::Coord _tolerance;
 
151
    /* If true then "Always snap" is on */
 
152
    bool _always_snap;
 
153
 
 
154
    /* If the snapped point is at an intersection of e.g. two lines, then this is
 
155
       the distance to the fartest line */
 
156
    Geom::Coord _second_distance;
 
157
    /* The snapping tolerance in screen pixels (depends on zoom)*/
 
158
    Geom::Coord _second_tolerance;
 
159
    /* If true then "Always snap" is on */
 
160
    bool _second_always_snap;
 
161
    /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
 
162
    Geom::Point _transformation;
 
163
    /* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */
 
164
    Geom::Coord _pointer_distance;
 
165
};
 
166
 
 
167
}// end of namespace Inkscape
 
168
 
 
169
bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
 
170
 
 
171
#endif /* !SEEN_SNAPPEDPOINT_H */
 
172
 
 
173
/*
 
174
  Local Variables:
 
175
  mode:c++
 
176
  c-file-style:"stroustrup"
 
177
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
178
  indent-tabs-mode:nil
 
179
  fill-column:99
 
180
  End:
 
181
*/
 
182
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :