Code

When expecting mouse clicks for a LPE in pen context, don't concatenate with or conti...
authorcilix42 <cilix42@users.sourceforge.net>
Thu, 12 Jun 2008 13:23:48 +0000 (13:23 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Thu, 12 Jun 2008 13:23:48 +0000 (13:23 +0000)
src/draw-context.cpp
src/pen-context.cpp
src/pen-context.h

index de030c7d5f69583f7b09e5a327576446b1806f80..a79be9fe7075db1705ef5050b64aed7637363546 100644 (file)
@@ -138,6 +138,8 @@ sp_draw_context_dispose(GObject *object)
         dc->selection = NULL;
     }
 
+    dc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
+
     spdc_free_colors(dc);
 
     G_OBJECT_CLASS(draw_parent_class)->dispose(object);
@@ -252,6 +254,9 @@ spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
 {
     using namespace Inkscape::LivePathEffect;
 
+    if (!SP_IS_PEN_CONTEXT(dc))
+        return;
+
     if (item) {
         if (prefs_get_int_attribute("tools.freehand", "spiro-spline-mode", 0)) {
             Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
@@ -259,7 +264,9 @@ spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
         }
         if (dc->waiting_LPE_type != INVALID_LPE) {
             Effect::createAndApply(dc->waiting_LPE_type, dc->desktop->doc(), item);
+            dc->waiting_LPE_type = INVALID_LPE;
         }
+        SP_PEN_CONTEXT(dc)->polylines_only = false;
     }
 }
 
index 1091408b36904ba863106624b5aae012f00926b2..56594bb6dda102a1d39233a72da3ec5132bfba91 100644 (file)
@@ -42,7 +42,6 @@
 #include "helper/units.h"
 #include "macros.h"
 #include "context-fns.h"
-#include "live_effects/effect.h"
 
 static void sp_pen_context_class_init(SPPenContextClass *klass);
 static void sp_pen_context_init(SPPenContext *pc);
@@ -147,6 +146,7 @@ sp_pen_context_init(SPPenContext *pc)
     pc->events_disabled = 0;
 
     pc->polylines_only = false;
+    pc->waiting_LPE = NULL;
 }
 
 /**
@@ -179,6 +179,7 @@ sp_pen_context_dispose(GObject *object)
     G_OBJECT_CLASS(pen_parent_class)->dispose(object);
 
     pc->polylines_only = false;
+    pc->waiting_LPE = NULL;
     if (pc->expecting_clicks_for_LPE > 0) {
         // we received too few clicks to sanely set the parameter path so we remove the LPE from the item
         sp_lpe_item_remove_current_path_effect(pc->waiting_item, false);
@@ -385,8 +386,8 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
 
     gint ret = FALSE;
     if (bevent.button == 1 && !event_context->space_panning
-        && pc->expecting_clicks_for_LPE != 1) { // when the last click for a waiting LPE occurs we want to finish the path
-
+        // when the last click for a waiting LPE occurs we want to finish the path
+        && pc->expecting_clicks_for_LPE != 1) {
 
         if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) {
             return TRUE;
@@ -427,28 +428,28 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
                                 break;
                             }
 
+                            // TODO: Perhaps it would be nicer to rearrange the following case
+                            // distinction so that the case of a waiting LPE is treated separately
+
                             /* Set start anchor */
                             pc->sa = anchor;
                             NR::Point p;
-                            if (anchor) {
-
-                                /* Adjust point to anchor if needed */
+                            if (anchor && !sp_pen_context_has_waiting_LPE(pc)) {
+                                /* Adjust point to anchor if needed; if we have a waiting LPE, we need
+                                   a fresh path to be created so don't continue an existing one */
                                 p = anchor->dp;
                                 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
-
                             } else {
-
                                 // This is the first click of a new curve; deselect item so that
                                 // this curve is not combined with it (unless it is drawn from its
                                 // anchor, which is handled by the sibling branch above)
                                 Inkscape::Selection * const selection = sp_desktop_selection(desktop);
-                                if (!(bevent.state & GDK_SHIFT_MASK)) {
-
+                                if (!(bevent.state & GDK_SHIFT_MASK) || sp_pen_context_has_waiting_LPE(pc)) {
+                                    /* if we have a waiting LPE, we need a fresh path to be created
+                                       so don't append to an existing one */
                                     selection->clear();
                                     desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
-
                                 } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
-
                                     desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
                                 }
 
@@ -521,6 +522,10 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
         }
     }
 
+    if (pc->expecting_clicks_for_LPE) {
+        --pc->expecting_clicks_for_LPE;
+    }
+
     return ret;
 }
 
@@ -776,23 +781,21 @@ pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
 
     // TODO: can we be sure that the path was created correctly?
     // TODO: should we offer an option to collect the clicks in a list?
-    if (pc->expecting_clicks_for_LPE > 0) {
-        --pc->expecting_clicks_for_LPE;
-
-        if (pc->expecting_clicks_for_LPE == 0) {
-            pc->polylines_only = false;
+    if (pc->expecting_clicks_for_LPE == 0 && sp_pen_context_has_waiting_LPE(pc)) {
+        pc->polylines_only = false;
 
-            SPEventContext *ec = SP_EVENT_CONTEXT(pc);
-            Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
+        SPEventContext *ec = SP_EVENT_CONTEXT(pc);
+        Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
 
-            if (pc->waiting_LPE) {
-                // we have an already created LPE waiting for a path
-                pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem()));
-                selection->add(SP_OBJECT(pc->waiting_item));
-            } else {
-                // the case that we need to create a new LPE and apply it to the just-drawn path is
-                // handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp
-            }
+        if (pc->waiting_LPE) {
+            // we have an already created LPE waiting for a path
+            pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem()));
+            selection->add(SP_OBJECT(pc->waiting_item));
+            pc->waiting_LPE = NULL;
+            pc->polylines_only = false;
+        } else {
+            // the case that we need to create a new LPE and apply it to the just-drawn path is
+            // handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp
         }
     }
 
index fb5c2237154c5cc8384e9177cd4df17c97c7b75c..68a2665e0dd21d1f1aa619a19a1f41247e058f62 100644 (file)
@@ -6,12 +6,7 @@
  */
 
 #include "draw-context.h"
-
-namespace Inkscape {
-namespace LivePathEffect {
-class Effect;
-}
-}
+#include "live_effects/effect.h"
 
 #define SP_TYPE_PEN_CONTEXT (sp_pen_context_get_type())
 #define SP_PEN_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_PEN_CONTEXT, SPPenContext))
@@ -59,6 +54,12 @@ struct SPPenContextClass : public SPEventContextClass { };
 
 GType sp_pen_context_get_type();
 
+inline bool sp_pen_context_has_waiting_LPE(SPPenContext *pc) {
+    // note: waiting_LPE_type is defined in SPDrawContext
+    return (pc->waiting_LPE != NULL ||
+            pc->waiting_LPE_type != Inkscape::LivePathEffect::INVALID_LPE);
+}
+
 
 #endif /* !SEEN_PEN_CONTEXT_H */