From: dvlierop2 Date: Thu, 9 Jul 2009 21:16:23 +0000 (+0000) Subject: Make stars and spirals escapable X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6cf09988babf3a59ea36c6a48fba90177699a4c3;p=inkscape.git Make stars and spirals escapable --- diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 872607c27..71906fcc0 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -493,7 +493,7 @@ sp_spiral_position_set (SPSpiral *spiral, spiral->cy = cy; spiral->exp = exp; spiral->revo = revo; - spiral->rad = MAX (rad, 0.001); + spiral->rad = MAX (rad, 0.0); spiral->arg = arg; spiral->t0 = CLAMP(t0, 0.0, 0.999); diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index cd90ac1cf..2f65b0ba9 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -52,6 +52,7 @@ static gint sp_spiral_context_root_handler(SPEventContext *event_context, GdkEve static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point p, guint state); static void sp_spiral_finish(SPSpiralContext *sc); +static void sp_spiral_cancel(SPSpiralContext *sc); static SPEventContextClass *parent_class; @@ -320,9 +321,14 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) } break; case GDK_Escape: - sp_desktop_selection(desktop)->clear(); - //TODO: make dragging escapable by Esc - break; + if (dragging) { + dragging = false; + sp_event_context_snap_window_closed(event_context); + // if drawing, cancel, otherwise pass it up for deselecting + sp_spiral_cancel(sc); + ret = TRUE; + } + break; case GDK_space: if (dragging) { @@ -331,7 +337,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) dragging = false; sp_event_context_snap_window_closed(event_context); if (!event_context->within_tolerance) { - // we've been dragging, finish the rect + // we've been dragging, finish the spiral sp_spiral_finish(sc); } // do not return true, so that space would work switching to selector @@ -440,8 +446,13 @@ sp_spiral_finish(SPSpiralContext *sc) sc->_message_context->clear(); if (sc->item != NULL) { - SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; - SPSpiral *spiral = SP_SPIRAL(sc->item); + SPSpiral *spiral = SP_SPIRAL(sc->item); + if (spiral->rad == 0) { + sp_spiral_cancel(sc); // Don't allow the creating of zero sized spiral, for example when the start and and point snap to the snap grid point + return; + } + + SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; sp_shape_set_shape(SP_SHAPE(spiral)); SP_OBJECT(spiral)->updateRepr(SP_OBJECT_WRITE_EXT); @@ -456,6 +467,27 @@ sp_spiral_finish(SPSpiralContext *sc) } } +static void sp_spiral_cancel(SPSpiralContext *sc) +{ + SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; + + sp_desktop_selection(desktop)->clear(); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); + + if (sc->item != NULL) { + SP_OBJECT(sc->item)->deleteObject(); + sc->item = NULL; + } + + sc->within_tolerance = false; + sc->xp = 0; + sc->yp = 0; + sc->item_to_select = NULL; + + sp_canvas_end_forced_full_redraws(desktop->canvas); + + sp_document_cancel(sp_desktop_document(desktop)); +} /* Local Variables: diff --git a/src/star-context.cpp b/src/star-context.cpp index a00442608..c5eff3c6a 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -56,6 +56,7 @@ static gint sp_star_context_root_handler (SPEventContext *ec, GdkEvent *event); static void sp_star_drag (SPStarContext * sc, Geom::Point p, guint state); static void sp_star_finish (SPStarContext * sc); +static void sp_star_cancel(SPStarContext * sc); static SPEventContextClass * parent_class; @@ -332,10 +333,14 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent } break; case GDK_Escape: - sp_desktop_selection(desktop)->clear(); - //TODO: make dragging escapable by Esc - break; - + if (dragging) { + dragging = false; + sp_event_context_snap_window_closed(event_context); + // if drawing, cancel, otherwise pass it up for deselecting + sp_star_cancel(sc); + ret = TRUE; + } + break; case GDK_space: if (dragging) { sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), @@ -343,7 +348,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent dragging = false; sp_event_context_snap_window_closed(event_context); if (!event_context->within_tolerance) { - // we've been dragging, finish the rect + // we've been dragging, finish the star sp_star_finish(sc); } // do not return true, so that space would work switching to selector @@ -452,7 +457,13 @@ sp_star_finish (SPStarContext * sc) sc->_message_context->clear(); if (sc->item != NULL) { - SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; + SPStar *star = SP_STAR(sc->item); + if (star->r[1] == 0) { + sp_star_cancel(sc); // Don't allow the creating of zero sized arc, for example when the start and and point snap to the snap grid point + return; + } + + SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; SPObject *object = SP_OBJECT(sc->item); sp_shape_set_shape(SP_SHAPE(sc->item)); @@ -469,6 +480,28 @@ sp_star_finish (SPStarContext * sc) } } +static void sp_star_cancel(SPStarContext *sc) +{ + SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; + + sp_desktop_selection(desktop)->clear(); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); + + if (sc->item != NULL) { + SP_OBJECT(sc->item)->deleteObject(); + sc->item = NULL; + } + + sc->within_tolerance = false; + sc->xp = 0; + sc->yp = 0; + sc->item_to_select = NULL; + + sp_canvas_end_forced_full_redraws(desktop->canvas); + + sp_document_cancel(sp_desktop_document(desktop)); +} + /* Local Variables: mode:c++