Code

Make stars and spirals escapable
authordvlierop2 <dvlierop2@users.sourceforge.net>
Thu, 9 Jul 2009 21:16:23 +0000 (21:16 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Thu, 9 Jul 2009 21:16:23 +0000 (21:16 +0000)
src/sp-spiral.cpp
src/spiral-context.cpp
src/star-context.cpp

index 872607c275da938770a17b1521edb441899737eb..71906fcc0c3b65d394e6333dd163c7640a7ddaed 100644 (file)
@@ -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);
 
index cd90ac1cf15362830cb1e07857100d1a7d213457..2f65b0ba9f3ea4c1f255a5a38c8aaa44d58f62a9 100644 (file)
@@ -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:
index a004426081af848b10bcbc15851afa57b04f3b60..c5eff3c6a89b3622feefa0c521349af5b8a968a7 100644 (file)
@@ -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++