From: dvlierop2 Date: Wed, 8 Jul 2009 20:48:55 +0000 (+0000) Subject: Don't create rectangles that have a zero x or y dimension. When snapping for example... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=baf409c2522ef70bf08798c4795d7e9c2dbf79f5;p=inkscape.git Don't create rectangles that have a zero x or y dimension. When snapping for example to the same point twice then just cancel the rect creation (Fixes bug #375975). And while we're at it, make the rectangle tool escapeable by pressing esc. See also rev. #21706 which was similar but applied to ellipses instead. --- diff --git a/src/rect-context.cpp b/src/rect-context.cpp index c05f00759..51b5f2e85 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -57,6 +57,7 @@ static gint sp_rect_context_item_handler(SPEventContext *event_context, SPItem * static void sp_rect_drag(SPRectContext &rc, Geom::Point const pt, guint state); static void sp_rect_finish(SPRectContext *rc); +static void sp_rect_cancel(SPRectContext *rc); static SPEventContextClass *parent_class; @@ -372,9 +373,14 @@ static gint sp_rect_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_rect_cancel(rc); + ret = TRUE; + } + break; case GDK_space: if (dragging) { @@ -503,9 +509,13 @@ static void sp_rect_finish(SPRectContext *rc) rc->_message_context->clear(); if ( rc->item != NULL ) { - SPDesktop * desktop; + SPRect *rect = SP_RECT(rc->item); + if (rect->width.computed == 0 || rect->height.computed == 0) { + sp_rect_cancel(rc); // Don't allow the creating of zero sized rectangle, for example when the start and and point snap to the snap grid point + return; + } - desktop = SP_EVENT_CONTEXT_DESKTOP(rc); + SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(rc); SP_OBJECT(rc->item)->updateRepr(); @@ -519,6 +529,29 @@ static void sp_rect_finish(SPRectContext *rc) } } +static void sp_rect_cancel(SPRectContext *rc) +{ + SPDesktop *desktop = SP_EVENT_CONTEXT(rc)->desktop; + + sp_desktop_selection(desktop)->clear(); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); + + if (rc->item != NULL) { + SP_OBJECT(rc->item)->deleteObject(); + rc->item = NULL; + } + + rc->within_tolerance = false; + rc->xp = 0; + rc->yp = 0; + rc->item_to_select = NULL; + + sp_canvas_end_forced_full_redraws(desktop->canvas); + + sp_document_cancel(sp_desktop_document(desktop)); +} + + /* Local Variables: mode:c++