X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpencil-context.cpp;h=1088e19ed9f3a299a5d9881cc08b18776f0d8a2d;hb=164fe825526bc4275e798359a7e665a9123ae2f3;hp=3265d87bf23b1b9a95451ca2ccc990266e0a63c6;hpb=dbe32b890d08ee7a085dcee01234f24e32db5ee1;p=inkscape.git diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 3265d87bf..1088e19ed 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -21,6 +21,7 @@ #include "desktop.h" #include "desktop-handles.h" #include "selection.h" +#include "selection-chemistry.h" #include "draw-anchor.h" #include "message-stack.h" #include "message-context.h" @@ -36,6 +37,10 @@ #include "libnr/n-art-bpath.h" #include "context-fns.h" #include "sp-namedview.h" +#include "xml/repr.h" +#include "document.h" +#include "desktop-style.h" +#include "macros.h" static void sp_pencil_context_class_init(SPPencilContextClass *klass); static void sp_pencil_context_init(SPPencilContext *pc); @@ -197,7 +202,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); @@ -222,6 +228,11 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve break; default: /* Set first point of sequence */ + if (bevent.state & GDK_CONTROL_MASK) { + freehand_create_single_dot(event_context, p, "tools.freehand.pencil", bevent.state); + ret = true; + break; + } if (anchor) { p = anchor->dp; desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path")); @@ -235,7 +246,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")); } @@ -254,11 +265,18 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve static gint pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent) { + 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; + return TRUE; + } 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 +322,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 +358,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; @@ -356,7 +375,10 @@ pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &re case SP_PENCIL_CONTEXT_IDLE: /* Releasing button in idle mode means single click */ /* We have already set up start point/anchor in button_press */ - pc->state = SP_PENCIL_CONTEXT_ADDLINE; + if (!(revent.state & GDK_CONTROL_MASK)) { + // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed + pc->state = SP_PENCIL_CONTEXT_ADDLINE; + } ret = TRUE; break; case SP_PENCIL_CONTEXT_ADDLINE: @@ -402,12 +424,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 +474,32 @@ 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; + case GDK_g: + case GDK_G: + if (mod_shift_only(state)) { + sp_selection_to_guides(); + ret = true; + } + break; default: break; } @@ -504,7 +582,7 @@ spdc_finish_endpoint(SPPencilContext *const pc) } static void -spdc_add_freehand_point(SPPencilContext *pc, NR::Point p, guint state) +spdc_add_freehand_point(SPPencilContext *pc, NR::Point p, guint /*state*/) { g_assert( pc->npoints > 0 ); g_return_if_fail(unsigned(pc->npoints) < G_N_ELEMENTS(pc->p));