Code

Pot and Dutch translation update
[inkscape.git] / src / pen-context.cpp
index bb52b1950cd2e3661bbe7b9642271173b6be1cee..6778d4bcc90b95cbcdd387f978dc40d52163205d 100644 (file)
@@ -476,6 +476,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
                                     SnapManager &m = desktop->namedview->snap_manager;
                                     m.setup(desktop);
                                     m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE);
+                                    m.unSetup();
                                 }
                               spdc_create_single_dot(event_context, p, "/tools/freehand/pen", bevent.state);
                               ret = TRUE;
@@ -633,6 +634,7 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
                         SnapManager &m = dt->namedview->snap_manager;
                         m.setup(dt);
                         m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE));
+                        m.unSetup();
                     }
                     break;
                 case SP_PEN_CONTEXT_CONTROL:
@@ -657,10 +659,11 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
 
                         if (!anchor) {   /* Snap node only if not hitting anchor */
                             spdc_endpoint_snap(pc, p, mevent.state);
+                            spdc_pen_set_subsequent_point(pc, p, true, mevent.state);
+                        } else {
+                            spdc_pen_set_subsequent_point(pc, anchor->dp, false, mevent.state);
                         }
 
-                        spdc_pen_set_subsequent_point(pc, p, !anchor, mevent.state);
-
                         if (anchor && !pc->anchor_statusbar) {
                             pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
                             pc->anchor_statusbar = true;
@@ -682,6 +685,7 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
                             SnapManager &m = dt->namedview->snap_manager;
                             m.setup(dt);
                             m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE));
+                            m.unSetup();
                         }
                     }
                     break;
@@ -708,6 +712,7 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
                         SnapManager &m = dt->namedview->snap_manager;
                         m.setup(dt);
                         m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE));
+                        m.unSetup();
                     }
                     break;
             }
@@ -1169,6 +1174,7 @@ pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
                 sp_canvas_item_hide(pc->cl1);
                 pc->state = SP_PEN_CONTEXT_POINT;
                 spdc_pen_set_subsequent_point(pc, pt, true);
+                pen_last_paraxial_dir = !pen_last_paraxial_dir;
                 ret = TRUE;
             }
             break;
@@ -1254,16 +1260,20 @@ spdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point const p, bool
     bool is_curve;
     pc->red_curve->moveto(pc->p[0]);
     if (pc->polylines_paraxial && !statusbar) {
-        // we are drawing horizontal/vertical lines and hit an anchor; draw an L-shaped path
-        Geom::Point intermed = p;
-        pen_set_to_nearest_horiz_vert(pc, intermed, status, false);
-        pc->red_curve->lineto(intermed);
+        // we are drawing horizontal/vertical lines and hit an anchor;
+        Geom::Point const origin = pc->p[0];
+        // if the previous point and the anchor are not aligned either horizontally or vertically...
+        if ((abs(p[Geom::X] - origin[Geom::X]) > 1e-9) && (abs(p[Geom::Y] - origin[Geom::Y]) > 1e-9)) {
+            // ...then we should draw an L-shaped path, consisting of two paraxial segments
+            Geom::Point intermed = p;
+            pen_set_to_nearest_horiz_vert(pc, intermed, status, false);
+            pc->red_curve->lineto(intermed);
+        }
         pc->red_curve->lineto(p);
         is_curve = false;
     } else {
         // one of the 'regular' modes
-        if (pc->p[1] != pc->p[0])
-        {
+        if (pc->p[1] != pc->p[0]) {
             pc->red_curve->curveto(pc->p[1], p, p);
             is_curve = true;
         } else {
@@ -1331,6 +1341,7 @@ spdc_pen_finish_segment(SPPenContext *const pc, Geom::Point const p, guint const
     if (pc->polylines_paraxial) {
         pen_last_paraxial_dir = pen_next_paraxial_direction(pc, p, pc->p[0], state);
     }
+
     ++pc->num_clicks;
 
     if (!pc->red_curve->is_empty()) {
@@ -1430,7 +1441,11 @@ static int pen_next_paraxial_direction(const SPPenContext *const pc,
      * horizontal or vertical segment; for all subsequent mouse clicks, we use the direction
      * orthogonal to the last one; pressing Shift toggles the direction
      */
-    if (pc->num_clicks == 0) {
+    // num_clicks is not reliable because spdc_pen_finish_segment is sometimes called too early
+    // (on first mouse release), in which case num_clicks immediately becomes 1.
+    // if (pc->num_clicks == 0) {
+
+    if (pc->green_curve->is_empty()) {
         // first mouse click
         double dist_h = fabs(pt[Geom::X] - origin[Geom::X]);
         double dist_v = fabs(pt[Geom::Y] - origin[Geom::Y]);
@@ -1445,7 +1460,7 @@ static int pen_next_paraxial_direction(const SPPenContext *const pc,
 
 void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state, bool snap)
 {
-    Geom::Point const &origin = pc->p[0];
+    Geom::Point const origin = pc->p[0];
 
     int next_dir = pen_next_paraxial_direction(pc, pt, origin, state);
 
@@ -1459,7 +1474,7 @@ void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt
         }
     } else {
         // Create a horizontal or vertical constraint line
-        Inkscape::Snapper::ConstraintLine cl(origin, next_dir ? Geom::Point(0, 1) : Geom::Point(1, 0));
+        Inkscape::Snapper::SnapConstraint cl(origin, next_dir ? Geom::Point(0, 1) : Geom::Point(1, 0));
 
         // Snap along the constraint line; if we didn't snap then still the constraint will be applied
         SnapManager &m = pc->desktop->namedview->snap_manager;
@@ -1470,6 +1485,7 @@ void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt
 
         m.setup(pc->desktop, true, selection->singleItem());
         m.constrainedSnapReturnByRef(pt, Inkscape::SNAPSOURCE_NODE_HANDLE, cl);
+        m.unSetup();
     }
 }
 
@@ -1482,4 +1498,4 @@ void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :