From c4aa590bedcf358acf15bdf0d8134ae99e3be167 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 23 Jan 2010 14:36:56 +0100 Subject: Remove redundancy from snapping API (type of snapsource no longer has to be specified explicitly) (bzr r9014) --- src/pencil-context.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index d6050ba04..acdd4d6e5 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -253,13 +253,13 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve break; default: /* Set first point of sequence */ - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); if (bevent.state & GDK_CONTROL_MASK) { if (!(bevent.state & GDK_SHIFT_MASK)) { - m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE); - } + m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); + } spdc_create_single_dot(event_context, p, "/tools/freehand/pencil", bevent.state); ret = true; break; @@ -270,15 +270,15 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve } else { if (!(bevent.state & GDK_SHIFT_MASK)) { - // This is the first click of a new curve; deselect item so that + // This is the first click of a new curve; deselect item so that // this curve is not combined with it (unless it is drawn from its // anchor, which is handled by the sibling branch above) selection->clear(); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path")); - m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE); + m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) { desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path")); - m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE); + m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); } } pc->sa = anchor; @@ -295,9 +295,9 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve static gint pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent) { - SPDesktop *const dt = pc->desktop; + SPDesktop *const dt = pc->desktop; - if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { + if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point pc->is_drawing = false; @@ -356,9 +356,9 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev /* We may be idle or already freehand */ if ( mevent.state & GDK_BUTTON1_MASK && pc->is_drawing ) { if (pc->state == SP_PENCIL_CONTEXT_IDLE) { - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(event_context); } - pc->state = SP_PENCIL_CONTEXT_FREEHAND; + pc->state = SP_PENCIL_CONTEXT_FREEHAND; if ( !pc->sa && !pc->green_anchor ) { /* Create green anchor */ @@ -373,8 +373,8 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev } if ( pc->npoints != 0) { // buttonpress may have happened before we entered draw context! - spdc_add_freehand_point(pc, p, mevent.state); - ret = TRUE; + spdc_add_freehand_point(pc, p, mevent.state); + ret = TRUE; } if (anchor && !pc->anchor_statusbar) { -- cgit v1.2.3 From e52fb9fac3f1bbd924c0ca3b6b5e214a095d44af Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 30 Jan 2010 23:04:33 +0100 Subject: Finally introducing the pre-snap indicator (bzr r9034) --- src/pencil-context.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index acdd4d6e5..5aa9efbd9 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -295,7 +295,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve static gint pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent) { - SPDesktop *const dt = pc->desktop; + SPDesktop *const dt = pc->desktop; if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; @@ -395,6 +395,11 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev pc->_message_context->clear(); pc->anchor_statusbar = false; } + if (sp_event_context_knot_mouseover(pc)) { + SnapManager &m = dt->namedview->snap_manager; + m.setup(dt); + m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); + } } break; } -- cgit v1.2.3 From cebb89f6ad97feaf9016502d113776f6f2c8de14 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Thu, 4 Feb 2010 22:53:33 +0100 Subject: Don't discard first point in pencil's freehand mode, and add a missing return statement Fixed bugs: - https://launchpad.net/bugs/452174 (bzr r9052) --- src/pencil-context.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 5aa9efbd9..328c011ff 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -622,6 +622,7 @@ spdc_set_startpoint(SPPencilContext *const pc, Geom::Point const p) pc->red_curve_is_valid = false; if (in_svg_plane(p)) { pc->p[pc->npoints++] = p; + pc->ps.push_back(p); } } -- cgit v1.2.3 From 195208c56145d9b9673aff0bb2f8795f5bc6fe22 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 6 Feb 2010 15:59:28 +0100 Subject: Tiny bit of refactoring (inverting some logic) (bzr r9059) --- src/pencil-context.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 328c011ff..f18174457 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -364,10 +364,6 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev /* Create green anchor */ pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, pc->p[0]); } - /** \todo - * fixme: I am not sure whether we want to snap to anchors - * in middle of freehand (Lauris) - */ if (anchor) { p = anchor->dp; } @@ -395,7 +391,7 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev pc->_message_context->clear(); pc->anchor_statusbar = false; } - if (sp_event_context_knot_mouseover(pc)) { + if (!sp_event_context_knot_mouseover(pc)) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); -- cgit v1.2.3 From 1937613529e308fee9f57c3740a155d56acdd710 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 7 Feb 2010 22:01:50 +0100 Subject: Pencil tool: fix drawing when starting a new freehand path on top of the pre-snap indicator, and snap the end-point of the freehand path (bzr r9065) --- src/pencil-context.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index f18174457..f6bb82743 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -235,6 +235,15 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve return TRUE; } + if (!pc->grab) { + /* Grab mouse, so release will not pass unnoticed */ + pc->grab = SP_CANVAS_ITEM(desktop->acetate); + sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK ), + NULL, bevent.time); + } + Geom::Point const button_w(bevent.x, bevent.y); /* Find desktop coordinates */ @@ -391,11 +400,15 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev pc->_message_context->clear(); pc->anchor_statusbar = false; } - if (!sp_event_context_knot_mouseover(pc)) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); - m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); - } + } + + // Show the pre-snap indicator to communicate to the user where we would snap to if he/she were to + // a) press the mousebutton to start a freehand drawing, or + // b) release the mousebutton to finish a freehand drawing + if (!sp_event_context_knot_mouseover(pc)) { + SnapManager &m = dt->namedview->snap_manager; + m.setup(dt); + m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); } break; } @@ -460,7 +473,15 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re /// \todo fixme: Clean up what follows (Lauris) if (anchor) { p = anchor->dp; + } else { + Geom::Point p_end = p; + spdc_endpoint_snap(pc, p_end, revent.state); + if (p_end != p) { + // then we must have snapped! + spdc_add_freehand_point(pc, p_end, revent.state); + } } + pc->ea = anchor; /* Write curves to object */ -- cgit v1.2.3 From e8b563dedd295eca73cde7c5e14a7af5fb105ba0 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Mon, 8 Feb 2010 21:39:21 +0100 Subject: Second attempt at fixing LP452174 (first node in freehand is ignored) Fixed bugs: - https://launchpad.net/bugs/452174 (bzr r9068) --- src/pencil-context.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index f6bb82743..9f9c187f3 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -378,6 +378,13 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev } if ( pc->npoints != 0) { // buttonpress may have happened before we entered draw context! + if (pc->ps.size() == 0) { + // Only in freehand mode we have to add the first point also to pc->ps (apparently) + // - We cannot add this point in spdc_set_startpoint, because we only need it for freehand + // - We cannot do this in the button press handler because at that point we don't know yet + // wheter we're going into freehand mode or not + pc->ps.push_back(pc->p[0]); + } spdc_add_freehand_point(pc, p, mevent.state); ret = TRUE; } @@ -639,7 +646,6 @@ spdc_set_startpoint(SPPencilContext *const pc, Geom::Point const p) pc->red_curve_is_valid = false; if (in_svg_plane(p)) { pc->p[pc->npoints++] = p; - pc->ps.push_back(p); } } -- cgit v1.2.3