Code

New 'zigzag' (polylines) mode in pen tool
authorcilix42 <cilix42@users.sourceforge.net>
Thu, 31 Jul 2008 12:43:10 +0000 (12:43 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Thu, 31 Jul 2008 12:43:10 +0000 (12:43 +0000)
src/draw-context.cpp
src/pen-context.cpp
src/widgets/toolbox.cpp

index e067e4545e531ddb70db4a4fac3473742590cb1c..c7676be9ef08cdf9ed150919f14bde7ac03a3dfc 100644 (file)
@@ -278,7 +278,7 @@ spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
     using namespace Inkscape::LivePathEffect;
 
     if (item && SP_IS_LPE_ITEM(item)) {
-        if (prefs_get_int_attribute(tool_name(dc), "freehand-mode", 0)) {
+        if (prefs_get_int_attribute(tool_name(dc), "freehand-mode", 0) == 1) {
             Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
         }
 
@@ -368,7 +368,7 @@ spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
             dc->waiting_LPE_type = INVALID_LPE;
         }
         if (SP_IS_PEN_CONTEXT(dc)) {
-            SP_PEN_CONTEXT(dc)->polylines_only = false;
+            SP_PEN_CONTEXT(dc)->polylines_only = (prefs_get_int_attribute("tools.freehand.pen", "freehand-mode", 0) == 2);
         }
     }
 }
index 46ae695fb14f2dcdc537f4a15e3d6f4270f91840..58dbc3cc370bb284898f5974fb9d8beb830755fc 100644 (file)
@@ -145,7 +145,7 @@ sp_pen_context_init(SPPenContext *pc)
     
     pc->events_disabled = 0;
 
-    pc->polylines_only = false;
+    pc->polylines_only = prefs_get_int_attribute("tools.freehand.pen", "freehand-mode", 0);
     pc->waiting_LPE = NULL;
 }
 
@@ -178,8 +178,6 @@ 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);
@@ -783,7 +781,7 @@ 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 && sp_pen_context_has_waiting_LPE(pc)) {
-        pc->polylines_only = false;
+        pc->polylines_only = prefs_get_int_attribute("tools.freehand.pen", "freehand-mode", 0);
 
         SPEventContext *ec = SP_EVENT_CONTEXT(pc);
         Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
@@ -793,7 +791,7 @@ pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
             pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem()));
             selection->add(SP_OBJECT(pc->waiting_item));
             pc->waiting_LPE = NULL;
-            pc->polylines_only = false;
+            pc->polylines_only = prefs_get_int_attribute("tools.freehand.pen", "freehand-mode", 0);
         } 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 b62ecb0b2b959a6c3f9c3696199ade8d58d4dfb2..9dfb0c2496543a4c07209a0c594699e65f5c88e7 100644 (file)
@@ -66,7 +66,7 @@
 
 #include "connector-context.h"
 #include "node-context.h"
-#include "draw-context.h"
+#include "pen-context.h"
 #include "shape-editor.h"
 #include "tweak-context.h"
 #include "sp-rect.h"
@@ -3279,7 +3279,15 @@ freehand_tool_name(GObject *dataKludge)
 
 static void sp_pc_freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl)
 {
-    prefs_set_int_attribute(freehand_tool_name(tbl), "freehand-mode", ege_select_one_action_get_active(act));
+    gint mode = ege_select_one_action_get_active(act);
+
+    prefs_set_int_attribute(freehand_tool_name(tbl), "freehand-mode", mode);
+
+    SPDesktop *desktop = (SPDesktop *) g_object_get_data(tbl, "desktop");
+    if (SP_IS_PEN_CONTEXT(desktop->event_context)) {
+        SPPenContext *pc = SP_PEN_CONTEXT(desktop->event_context);
+        pc->polylines_only = (mode == 2);
+    }
 }
 
 static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
@@ -3307,6 +3315,15 @@ static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* ho
                                 2, "spiro_splines_mode",
                                 -1 );
 
+            if (!tool_is_pencil) {
+                gtk_list_store_append( model, &iter );
+                gtk_list_store_set( model, &iter,
+                                    0, _("Zigzag"),
+                                    1, _("Create a sequence of straight line segments"),
+                                    2, "polylines_mode",
+                                    -1 );
+            }
+
             EgeSelectOneAction* act = ege_select_one_action_new(tool_is_pencil ?
                                                                 "FreehandModeActionPencil" :
                                                                 "FreehandModeActionPen",