Code

More infrastructure to have waiting LPEs that are freshly created and applied to...
authorcilix42 <cilix42@users.sourceforge.net>
Thu, 12 Jun 2008 13:23:30 +0000 (13:23 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Thu, 12 Jun 2008 13:23:30 +0000 (13:23 +0000)
src/draw-context.cpp
src/draw-context.h
src/pen-context.cpp
src/pen-context.h

index 4d60cda050e87ec78a70a6f4aa96077dba6e1839..de030c7d5f69583f7b09e5a327576446b1806f80 100644 (file)
@@ -115,7 +115,7 @@ sp_draw_context_init(SPDrawContext *dc)
     dc->green_color = 0x00ff007f;
     dc->red_curve_is_valid = false;
 
-    dc->waiting_LPE = Inkscape::LivePathEffect::INVALID_LPE;
+    dc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
 
     new (&dc->sel_changed_connection) sigc::connection();
     new (&dc->sel_modified_connection) sigc::connection();
@@ -245,20 +245,20 @@ sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
 
 /*
  * If we have an item and a waiting LPE, apply the effect to the item
+ * (spiro spline mode is treated separately)
  */
 void
 spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
 {
     using namespace Inkscape::LivePathEffect;
 
-    // TODO: sort this out as soon as we use automatic LPE application for other things than spiro mode, too
     if (item) {
         if (prefs_get_int_attribute("tools.freehand", "spiro-spline-mode", 0)) {
             Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
             return;
         }
-        if (dc->waiting_LPE != INVALID_LPE) {
-            Effect::createAndApply(dc->waiting_LPE, dc->desktop->doc(), item);
+        if (dc->waiting_LPE_type != INVALID_LPE) {
+            Effect::createAndApply(dc->waiting_LPE_type, dc->desktop->doc(), item);
         }
     }
 }
@@ -270,6 +270,8 @@ spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
 static void
 spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
 {
+    // note: in draw context, selection_changed() is only called when a new item was created;
+    // otherwise the following function call would yield wrong results
     spdc_check_for_and_apply_waiting_LPE(dc, sel->singleItem());
 
     if (dc->attach) {
index c1166dcbd0fed2b516f6891365bf284dc24c0c19..afdec1981bd22512f660c9d9a064b040b8a21a63 100644 (file)
@@ -70,7 +70,7 @@ struct SPDrawContext : public SPEventContext{
     SPDrawAnchor *ea;
 
     /* type of the LPE that is to be applied automatically to a finished path (if any) */
-    Inkscape::LivePathEffect::EffectType waiting_LPE;
+    Inkscape::LivePathEffect::EffectType waiting_LPE_type;
 
     sigc::connection sel_changed_connection;
     sigc::connection sel_modified_connection;
index 4616c04ae9735eb5c3d586464918a6d2e93a3f6d..1091408b36904ba863106624b5aae012f00926b2 100644 (file)
@@ -785,8 +785,14 @@ pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
             SPEventContext *ec = SP_EVENT_CONTEXT(pc);
             Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
 
-            pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem()));
-            selection->add(SP_OBJECT(pc->waiting_item));
+            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
+            }
         }
     }
 
index 3e4e9092405c059a73eb3565341c4b9f8d7eee9c..fb5c2237154c5cc8384e9177cd4df17c97c7b75c 100644 (file)
@@ -46,7 +46,7 @@ struct SPPenContext : public SPDrawContext {
     bool polylines_only;
 
     unsigned int expecting_clicks_for_LPE; // if positive, finish the path after this many clicks
-    Inkscape::LivePathEffect::Effect *waiting_LPE;
+    Inkscape::LivePathEffect::Effect *waiting_LPE; // if NULL, waiting_LPE_type in SPDrawContext is taken into account
     SPLPEItem *waiting_item;
 
     SPCanvasItem *c0, *c1, *cl0, *cl1;