Code

handle the case of no filter primitives
[inkscape.git] / src / pen-context.cpp
index 03a993f827b48bd42ad7ce56c710b1969950ff65..0f8a4204a928b19217d7138eb31138e82466feb2 100644 (file)
@@ -63,6 +63,8 @@ static gint pen_handle_2button_press(SPPenContext *const pc);
 static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event);
 static void spdc_reset_colors(SPPenContext *pc);
 
+static void pen_disable_events(SPPenContext *const pc);
+static void pen_enable_events(SPPenContext *const pc);
 
 static NR::Point pen_drag_origin_w(0, 0);
 static bool pen_within_tolerance = false;
@@ -135,6 +137,8 @@ sp_pen_context_init(SPPenContext *pc)
     pc->c1 = NULL;
     pc->cl0 = NULL;
     pc->cl1 = NULL;
+    
+    pc->events_disabled = 0;
 }
 
 /**
@@ -216,6 +220,8 @@ pen_cancel (SPPenContext *const pc)
     sp_canvas_item_hide(pc->cl1);
     pc->_message_context->clear();
     pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
+
+    sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
 }
 
 /**
@@ -329,6 +335,11 @@ sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event)
  */
 static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent)
 {
+    if (pc->events_disabled) {
+        // skip event processing if events are disabled
+        return FALSE;
+    }
+
     gint ret = FALSE;
     if (bevent.button == 1) {
 
@@ -467,6 +478,11 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
         // allow middle-button scrolling
         return FALSE;
     }
+    
+    if (pc->events_disabled) {
+        // skip motion events if pen events are disabled
+        return FALSE;
+    }
 
     NR::Point const event_w(mevent.x,
                             mevent.y);
@@ -583,6 +599,11 @@ pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
 static gint
 pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
 {
+    if (pc->events_disabled) {
+        // skip event processing if events are disabled
+        return FALSE;
+    }
+
     gint ret = FALSE;
     if ( revent.button == 1 ) {
 
@@ -923,13 +944,7 @@ pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
         case GDK_Delete:
         case GDK_KP_Delete:
             if (sp_curve_is_empty(pc->green_curve)) {
-                /* Same as cancel */
-                pc->state = SP_PEN_CONTEXT_STOP;
-                spdc_reset_colors(pc);
-                sp_canvas_item_hide(pc->c0);
-                sp_canvas_item_hide(pc->c1);
-                sp_canvas_item_hide(pc->cl0);
-                sp_canvas_item_hide(pc->cl1);
+                pen_cancel (pc);
                 ret = TRUE;
             } else {
                 /* Reset red curve */
@@ -948,7 +963,11 @@ pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
                     break;
                 }
                 pc->p[0] = p[e - 2].c(3);
-                pc->p[1] = p[e - 1].c(1);
+                if (p[e - 1].code == NR_CURVETO) {
+                    pc->p[1] = p[e - 1].c(1);
+                } else {
+                    pc->p[1] = pc->p[0];
+                }
                 NR::Point const pt(( pc->npoints < 4
                                      ? p[e - 1].c(3)
                                      : pc->p[3] ));
@@ -1003,6 +1022,8 @@ spdc_pen_set_initial_point(SPPenContext *const pc, NR::Point const p)
     pc->p[1] = p;
     pc->npoints = 2;
     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
+
+    sp_canvas_force_full_redraw_after_interruptions(pc->desktop->canvas, 5);
 }
 
 static void
@@ -1027,6 +1048,7 @@ spdc_pen_set_subsequent_point(SPPenContext *const pc, NR::Point const p, bool st
         sp_curve_lineto(pc->red_curve, p);
         is_curve = false;
     }
+
     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
 
     if (statusbar) {
@@ -1124,6 +1146,8 @@ spdc_pen_finish_segment(SPPenContext *const pc, NR::Point const p, guint const s
 static void
 spdc_pen_finish(SPPenContext *const pc, gboolean const closed)
 {
+    pen_disable_events(pc);
+    
     SPDesktop *const desktop = pc->desktop;
     pc->_message_context->clear();
     desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished"));
@@ -1144,8 +1168,24 @@ spdc_pen_finish(SPPenContext *const pc, gboolean const closed)
     if (pc->green_anchor) {
         pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
     }
+
+
+    sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
+
+    pen_enable_events(pc);
+}
+
+static void
+pen_disable_events(SPPenContext *const pc) {
+  pc->events_disabled++;
 }
 
+static void
+pen_enable_events(SPPenContext *const pc) {
+  g_return_if_fail(pc->events_disabled != 0);
+  
+  pc->events_disabled--;
+}
 
 /*
   Local Variables: