Code

First shot at a dropdown selector for various shapes in pen/pencil tool, along the...
authorcilix42 <cilix42@users.sourceforge.net>
Thu, 3 Jul 2008 09:40:20 +0000 (09:40 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Thu, 3 Jul 2008 09:40:20 +0000 (09:40 +0000)
TODO: more paths for the dropdown, read them from a separate file; show images for the choices, not text

src/draw-context.cpp
src/live_effects/lpe-patternalongpath.h
src/live_effects/parameter/path.cpp
src/live_effects/parameter/path.h
src/widgets/toolbox.cpp

index ce6ccc0e48effd5798b81b2a0662208b31a75bce..d54ccc7788dc1fb092cb41cccaf69c628cb71d2f 100644 (file)
@@ -41,6 +41,7 @@
 #include "snap.h"
 #include "sp-path.h"
 #include "sp-namedview.h"
+#include "live_effects/lpe-patternalongpath.h"
 
 static void sp_draw_context_class_init(SPDrawContextClass *klass);
 static void sp_draw_context_init(SPDrawContext *dc);
@@ -245,6 +246,19 @@ sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
     return ret;
 }
 
+static void
+spdc_paste_curve_as_param_path(const SPCurve *c, SPDrawContext *dc, SPItem *item)
+{
+    using namespace Inkscape::LivePathEffect;
+
+    // TODO: Don't paste path if nothing is on the clipboard
+
+    Effect::createAndApply(Inkscape::LivePathEffect::PATTERN_ALONG_PATH, dc->desktop->doc(), item);
+    Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
+    gchar *svgd = sp_svg_write_path(c->get_pathvector());
+    static_cast<LPEPatternAlongPath*>(lpe)->pattern.paste_param_path(svgd);
+}
+
 /*
  * If we have an item and a waiting LPE, apply the effect to the item
  * (spiro spline mode is treated separately)
@@ -255,6 +269,35 @@ spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
     using namespace Inkscape::LivePathEffect;
 
     if (item) {
+        int shape = prefs_get_int_attribute("tools.freehand", "shape", 0);
+
+        switch (shape) {
+            case 0:
+                break;
+            case 1:
+            {
+                Effect::createAndApply(PATTERN_ALONG_PATH, dc->desktop->doc(), item);
+                Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
+                static_cast<LPEPatternAlongPath*>(lpe)->pattern.on_paste_button_click();
+                return;
+            }
+            case 2:
+            {
+                // TODO: this is only for illustration (we create a "decrescendo"-shaped path
+                //       manually; eventually we should read the path from a separate file)
+                SPCurve *c = new SPCurve();
+                c->moveto(0,0);
+                c->lineto(0,10);
+                c->lineto(200,5);
+                c->closepath();
+                spdc_paste_curve_as_param_path(c, dc, item);
+                c->unref();
+                return;
+            }
+            default:
+                break;
+        }
+
         if (prefs_get_int_attribute("tools.freehand", "spiro-spline-mode", 0)) {
             Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
             return;
@@ -276,8 +319,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
+    // note: in draw context, selection_changed() is only called with a valid item as argument 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 8a3e78aa5a975d5c86f5c31e7498dd599eb9574a..341f9945426c06d11b48d63be45164ecea223a7d 100644 (file)
@@ -34,8 +34,8 @@ public:
 
     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
 
-private:
     PathParam  pattern;
+private:
     EnumParam<PAPCopyType> copytype;
     ScalarParam  prop_scale;
     BoolParam scale_y_rel;
index 295e40b7a57b58e184a9d1c542601dbbd0feedba..16e579d16317e1968c856b0ba28a0cb95594609f 100644 (file)
@@ -346,23 +346,28 @@ PathParam::on_edit_button_click()
 }
 
 void
-PathParam::on_paste_button_click()
+PathParam::paste_param_path(const char *svgd)
 {
-    Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
-    Glib::ustring svgd = cm->getPathParameter();
-    
     if (svgd == "")
         return;
 
     // remove possible link to path
     remove_link();
 
-    param_write_to_repr(svgd.data());
+    param_write_to_repr(svgd);
     signal_path_pasted.emit();
     sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, 
                      _("Paste path parameter"));
 }
 
+void
+PathParam::on_paste_button_click()
+{
+    Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
+    Glib::ustring svgd = cm->getPathParameter();
+    paste_param_path(svgd.data());
+}
+
 void
 PathParam::on_copy_button_click()
 {
index 64c2de55cfb81e9a0804a6d81a2982116e681365..8dcda821517013991bfee877ddce85fe70732d51 100644 (file)
@@ -55,6 +55,9 @@ public:
     sigc::signal <void> signal_path_pasted;
     sigc::signal <void> signal_path_changed;
 
+    void paste_param_path(const char *svgd);
+    void on_paste_button_click();
+
 protected:
     std::vector<Geom::Path> _pathvector;   // this is primary data storage, since it is closest to SVG.
 
@@ -75,7 +78,6 @@ protected:
     void linked_modified(SPObject *linked_obj, guint flags);
 
     void on_edit_button_click();
-    void on_paste_button_click();
     void on_copy_button_click();
     void on_link_button_click();
 
index 61fdc74d7526f5c355a04dd927ac8e9fcf830457..8fa52c2815ab29a01a8f8e8db5101c99027a09a7 100644 (file)
@@ -367,6 +367,8 @@ static gchar const * ui_descr =
         "  <toolbar name='PenToolbar'>"
         "    <toolitem action='FreehandModeActionPenTemp' />"
         "    <toolitem action='FreehandModeActionPen' />"
+        "    <separator />"
+        "    <toolitem action='SetPenShapeAction'/>"
         "  </toolbar>"
 
         "  <toolbar name='PencilToolbar'>"
@@ -376,6 +378,8 @@ static gchar const * ui_descr =
         "    <toolitem action='PencilToleranceAction' />"
         "    <separator />"
         "    <toolitem action='PencilResetAction' />"
+        "    <separator />"
+        "    <toolitem action='SetPencilShapeAction'/>"
         "  </toolbar>"
 
         "  <toolbar name='CalligraphyToolbar'>"
@@ -3325,9 +3329,57 @@ static void sp_add_spiro_toggle(GtkActionGroup* mainActions, GObject* holder, bo
     }
 }
 
+static void sp_freehand_change_shape(EgeSelectOneAction* act, GObject *dataKludge) {
+    gint shape = ege_select_one_action_get_active( act );
+    prefs_set_int_attribute("tools.freehand", "shape", shape);
+}
+
+/**
+ * \brief Generate the list of freehand advanced shape option entries.
+ */
+GList * freehand_shape_dropdown_items_list() {
+    GList *glist = NULL;
+
+    glist = g_list_append (glist, _("None"));
+    glist = g_list_append (glist, _("Clipboard"));
+    glist = g_list_append (glist, _("Decrescendo"));
+
+    return glist;
+}
+
+static void
+sp_freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil) {
+    /*advanced shape options */
+    {
+        GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
+
+        GList* items = 0;
+        gint count = 0;
+        for ( items = freehand_shape_dropdown_items_list(); items ; items = g_list_next(items) )
+        {
+            GtkTreeIter iter;
+            gtk_list_store_append( model, &iter );
+            gtk_list_store_set( model, &iter, 0, reinterpret_cast<gchar*>(items->data), 1, count, -1 );
+            count++;
+        }
+        g_list_free( items );
+        items = 0;
+        EgeSelectOneAction* act1 = ege_select_one_action_new(
+            tool_is_pencil ? "SetPencilShapeAction" : "SetPenShapeAction",
+            _("Shape:"), (""), NULL, GTK_TREE_MODEL(model));
+        g_object_set( act1, "short_label", _("Shape:"), NULL );
+        ege_select_one_action_set_appearance( act1, "compact" );
+        ege_select_one_action_set_active( act1, prefs_get_int_attribute("tools.freehand", "shape", 0) );
+        g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(sp_freehand_change_shape), holder );
+        gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
+        g_object_set_data( holder, "shape_action", act1 );
+    }
+}
+
 static void sp_pen_toolbox_prep(SPDesktop */*desktop*/, GtkActionGroup* mainActions, GObject* holder)
 {
     sp_add_spiro_toggle(mainActions, holder, false);
+    sp_freehand_add_advanced_shape_options(mainActions, holder, false);
 }
 
 
@@ -3430,6 +3482,10 @@ static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio
         g_object_set_data(G_OBJECT(holder), "repr", repr);
 
     }
+
+    /* advanced shape options */
+    sp_freehand_add_advanced_shape_options(mainActions, holder, true);
+
     /* Reset */
     {
         InkAction* inky = ink_action_new( "PencilResetAction",