Code

more unreffing temporary styles properly
[inkscape.git] / src / pen-context.cpp
index 96140a06cd2b7c2cd0f3d4ed181d742c826fcafb..5a60a7b5250fddaa621a1f116f5d2422a30d0be1 100644 (file)
@@ -30,7 +30,6 @@
 #include "sp-path.h"
 
 #include "pixmaps/cursor-pen.xpm"
-#include "pixmaps/cursor-pen.pixbuf"
 #include "display/canvas-bpath.h"
 #include "display/sp-ctrlline.h"
 #include "display/sodipodi-ctrl.h"
@@ -60,7 +59,7 @@ static void spdc_pen_finish(SPPenContext *pc, gboolean closed);
 static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent);
 static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent);
 static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent);
-static gint pen_handle_2button_press(SPPenContext *const pc);
+static gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent);
 static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event);
 static void spdc_reset_colors(SPPenContext *pc);
 
@@ -127,11 +126,6 @@ sp_pen_context_init(SPPenContext *pc)
     SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
 
     event_context->cursor_shape = cursor_pen_xpm;
-    event_context->cursor_pixbuf = gdk_pixbuf_new_from_inline(
-            -1,
-            cursor_pen_pixbuf,
-            FALSE,
-            NULL);  
     event_context->hot_x = 4;
     event_context->hot_y = 4;
 
@@ -227,7 +221,7 @@ pen_cancel (SPPenContext *const pc)
     pc->_message_context->clear();
     pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
 
-    //sp_canvas_clear_forced_full_redraws(pc->desktop->canvas);
+    sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
 }
 
 /**
@@ -314,7 +308,7 @@ sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event)
             break;
 
         case GDK_2BUTTON_PRESS:
-            ret = pen_handle_2button_press(pc);
+            ret = pen_handle_2button_press(pc, event->button);
             break;
 
         case GDK_KEY_PRESS:
@@ -346,24 +340,24 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
         return FALSE;
     }
 
+    SPDrawContext * const dc = SP_DRAW_CONTEXT(pc);
+    SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
+    NR::Point const event_w(bevent.x, bevent.y);
+    NR::Point const event_dt(desktop->w2d(event_w));
+
     gint ret = FALSE;
     if (bevent.button == 1) {
 
-        SPDrawContext * const dc = SP_DRAW_CONTEXT(pc);
-        SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
-
         if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) {
             return TRUE;
         }
 
-        NR::Point const event_w(bevent.x, bevent.y);
         pen_drag_origin_w = event_w;
         pen_within_tolerance = true;
 
         /* Test whether we hit any anchor. */
         SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w);
 
-        NR::Point const event_dt(desktop->w2d(event_w));
         switch (pc->mode) {
             case SP_PEN_CONTEXT_MODE_CLICK:
                 /* In click mode we add point on release */
@@ -464,7 +458,16 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
         }
     } else if (bevent.button == 3) {
         if (pc->npoints != 0) {
-            spdc_pen_finish(pc, FALSE);
+
+            spdc_pen_finish_segment(pc, event_dt, bevent.state);
+            if (pc->green_closed) {
+                // finishing at the start anchor, close curve
+                spdc_pen_finish(pc, TRUE);
+            } else {
+                // finishing at some other anchor, finish curve but not close
+                spdc_pen_finish(pc, FALSE);
+            }
+
             ret = TRUE;
         }
     }
@@ -716,10 +719,10 @@ pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
 }
 
 static gint
-pen_handle_2button_press(SPPenContext *const pc)
+pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent)
 {
     gint ret = FALSE;
-    if (pc->npoints != 0) {
+    if (pc->npoints != 0 && bevent.button != 2) {
         spdc_pen_finish(pc, FALSE);
         ret = TRUE;
     }
@@ -1028,6 +1031,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
@@ -1036,8 +1041,6 @@ spdc_pen_set_subsequent_point(SPPenContext *const pc, NR::Point const p, bool st
     g_assert( pc->npoints != 0 );
     /* todo: Check callers to see whether 2 <= npoints is guaranteed. */
 
-    //sp_canvas_force_full_redraws(pc->desktop->canvas, 4);
-
     pc->p[2] = p;
     pc->p[3] = p;
     pc->p[4] = p;
@@ -1175,7 +1178,8 @@ spdc_pen_finish(SPPenContext *const pc, gboolean const closed)
         pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
     }
 
-    //sp_canvas_clear_forced_full_redraws(desktop->canvas);
+
+    sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
 
     pen_enable_events(pc);
 }