Code

Fix RegisteredWidgets. Due to rev 16265, widgets were no longer initialized. This...
[inkscape.git] / src / pencil-context.cpp
index 3265d87bf23b1b9a95451ca2ccc990266e0a63c6..cdadd0c713d53d04c3d31386125dd8e651ca0601 100644 (file)
@@ -197,7 +197,8 @@ static gint
 pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &bevent)
 {
     gint ret = FALSE;
-    if ( bevent.button == 1 ) {
+    SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
+    if ( bevent.button == 1  && !event_context->space_panning) {
 
         SPDrawContext *dc = SP_DRAW_CONTEXT (pc);
         SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
@@ -235,7 +236,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
                         selection->clear();
                         desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
                         SnapManager const &m = desktop->namedview->snap_manager;
-                        p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
+                        p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
                     } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
                         desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
                     }
@@ -257,8 +258,9 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev
     gint ret = FALSE;
     SPDesktop *const dt = pc->desktop;
 
-    if (mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
-        // allow middle-button scrolling
+    SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
+    if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
+        // allow scrolling
         return FALSE;
     }
 
@@ -304,7 +306,7 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev
                     p = anchor->dp;
                 } else if ((mevent.state & GDK_SHIFT_MASK) == 0) {
                     SnapManager const &m = dt->namedview->snap_manager;
-                    p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
+                    p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
                 }
                 if ( pc->npoints != 0 ) { // buttonpress may have happened before we entered draw context!
                     spdc_add_freehand_point(pc, p, mevent.state);
@@ -340,7 +342,8 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re
 {
     gint ret = FALSE;
 
-    if ( revent.button == 1 && pc->is_drawing) {
+    SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
+    if ( revent.button == 1 && pc->is_drawing && !event_context->space_panning) {
         SPDesktop *const dt = pc->desktop;
 
         pc->is_drawing = false;
@@ -402,12 +405,42 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re
             pc->grab = NULL;
         }
 
-        pc->grab = NULL;
         ret = TRUE;
     }
     return ret;
 }
 
+static void
+pencil_cancel (SPPencilContext *const pc) 
+{
+    if (pc->grab) {
+        /* Release grab now */
+        sp_canvas_item_ungrab(pc->grab, 0);
+        pc->grab = NULL;
+    }
+
+    pc->is_drawing = false;
+
+    pc->state = SP_PENCIL_CONTEXT_IDLE;
+
+    sp_curve_reset(pc->red_curve);
+    sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
+    while (pc->green_bpaths) {
+        gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
+        pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
+    }
+    sp_curve_reset(pc->green_curve);
+    if (pc->green_anchor) {
+        pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
+    }
+
+    pc->_message_context->clear();
+    pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
+
+    sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
+}
+
+
 static gint
 pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint const state)
 {
@@ -422,6 +455,25 @@ pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint con
                 ret = TRUE;
             }
             break;
+        case GDK_Escape:
+            if (pc->npoints != 0) {
+                // if drawing, cancel, otherwise pass it up for deselecting
+                if (pc->is_drawing) {
+                    pencil_cancel (pc);
+                    ret = TRUE;
+                }
+            }
+            break;
+        case GDK_z:
+        case GDK_Z:
+            if (mod_ctrl_only(state) && pc->npoints != 0) {
+                // if drawing, cancel, otherwise pass it up for undo
+                if (pc->is_drawing) {
+                    pencil_cancel (pc);
+                    ret = TRUE;
+                }
+            }
+            break;
         default:
             break;
     }