diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp
index 328c011ff9fb24b4d4dfccff7bdfce0b3b72251a..a873eb6fcb9a84e383c68e006e1ee2040b13a7e9 100644 (file)
--- a/src/pencil-context.cpp
+++ b/src/pencil-context.cpp
#include "document.h"
#include "desktop-style.h"
#include "macros.h"
#include "document.h"
#include "desktop-style.h"
#include "macros.h"
+#include "display/sp-canvas.h"
#include "display/curve.h"
#include "livarot/Path.h"
#include "display/curve.h"
#include "livarot/Path.h"
@@ -235,6 +236,15 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
return TRUE;
}
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 */
Geom::Point const button_w(bevent.x, bevent.y);
/* Find desktop coordinates */
@@ -254,13 +264,14 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
default:
/* Set first point of sequence */
SnapManager &m = desktop->namedview->snap_manager;
default:
/* Set first point of sequence */
SnapManager &m = desktop->namedview->snap_manager;
- m.setup(desktop);
if (bevent.state & GDK_CONTROL_MASK) {
if (bevent.state & GDK_CONTROL_MASK) {
+ m.setup(desktop);
if (!(bevent.state & GDK_SHIFT_MASK)) {
m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE);
}
spdc_create_single_dot(event_context, p, "/tools/freehand/pencil", bevent.state);
if (!(bevent.state & GDK_SHIFT_MASK)) {
m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE);
}
spdc_create_single_dot(event_context, p, "/tools/freehand/pencil", bevent.state);
+ m.unSetup();
ret = true;
break;
}
ret = true;
break;
}
@@ -268,7 +279,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
p = anchor->dp;
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
} else {
p = anchor->dp;
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
} else {
-
+ m.setup(desktop);
if (!(bevent.state & GDK_SHIFT_MASK)) {
// 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
if (!(bevent.state & GDK_SHIFT_MASK)) {
// 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
@@ -280,6 +291,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE);
}
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE);
}
+ m.unSetup();
}
pc->sa = anchor;
spdc_set_startpoint(pc, p);
}
pc->sa = anchor;
spdc_set_startpoint(pc, p);
@@ -364,15 +376,18 @@ 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]);
}
/* 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;
}
if ( pc->npoints != 0) { // buttonpress may have happened before we entered draw context!
if (anchor) {
p = anchor->dp;
}
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;
}
spdc_add_freehand_point(pc, p, mevent.state);
ret = TRUE;
}
@@ -395,11 +410,16 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev
pc->_message_context->clear();
pc->anchor_statusbar = false;
}
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));
+ m.unSetup();
}
break;
}
}
break;
}
@@ -464,7 +484,15 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re
/// \todo fixme: Clean up what follows (Lauris)
if (anchor) {
p = anchor->dp;
/// \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 */
pc->ea = anchor;
/* Write curves to object */
pc->red_curve_is_valid = false;
if (in_svg_plane(p)) {
pc->p[pc->npoints++] = p;
pc->red_curve_is_valid = false;
if (in_svg_plane(p)) {
pc->p[pc->npoints++] = p;
- pc->ps.push_back(p);
}
}
}
}
fill-column:99
End:
*/
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 :