From 390745fa4524b55aad12d5d2d656cd73e75a0bc0 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Thu, 3 Jul 2008 09:40:20 +0000 Subject: [PATCH] First shot at a dropdown selector for various shapes in pen/pencil tool, along the lines of Valerie's blueprint. TODO: more paths for the dropdown, read them from a separate file; show images for the choices, not text --- src/draw-context.cpp | 47 ++++++++++++++++++++- src/live_effects/lpe-patternalongpath.h | 2 +- src/live_effects/parameter/path.cpp | 15 ++++--- src/live_effects/parameter/path.h | 4 +- src/widgets/toolbox.cpp | 56 +++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 9 deletions(-) diff --git a/src/draw-context.cpp b/src/draw-context.cpp index ce6ccc0e4..d54ccc778 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -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(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(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) { diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index 8a3e78aa5..341f99454 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -34,8 +34,8 @@ public: virtual void transform_multiply(Geom::Matrix const& postmul, bool set); -private: PathParam pattern; +private: EnumParam copytype; ScalarParam prop_scale; BoolParam scale_y_rel; diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 295e40b7a..16e579d16 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -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() { diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 64c2de55c..8dcda8215 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -55,6 +55,9 @@ public: sigc::signal signal_path_pasted; sigc::signal signal_path_changed; + void paste_param_path(const char *svgd); + void on_paste_button_click(); + protected: std::vector _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(); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 61fdc74d7..8fa52c281 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -367,6 +367,8 @@ static gchar const * ui_descr = " " " " " " + " " + " " " " " " @@ -376,6 +378,8 @@ static gchar const * ui_descr = " " " " " " + " " + " " " " " " @@ -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(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", -- 2.30.2