From 72aa7310f3a87958233d5cb4bf1386ff999be0ac Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sat, 23 Feb 2008 21:52:43 +0000 Subject: [PATCH] * on-canvas clip and mask editing :) in the object menu you can find how to edit them. * show helperpath toggle on node-edit toolbar. so helperpath is now also available for normal paths (instead of only for LPE'd paths) --- share/icons/icons.svg | 32 ++++++++++++++++++++++++ src/menus-skeleton.h | 2 ++ src/nodepath.cpp | 22 ++++++++++++++++ src/nodepath.h | 1 + src/preferences-skeleton.h | 2 +- src/selection-chemistry.cpp | 50 +++++++++++++++++++++++++++++++++++++ src/selection-chemistry.h | 2 ++ src/shape-editor.cpp | 4 +++ src/shape-editor.h | 1 + src/verbs.cpp | 10 ++++++++ src/verbs.h | 2 ++ src/widgets/toolbox.cpp | 19 ++++++++++++++ 12 files changed, 146 insertions(+), 1 deletion(-) diff --git a/share/icons/icons.svg b/share/icons/icons.svg index 65cbf7307..9915d8c88 100644 --- a/share/icons/icons.svg +++ b/share/icons/icons.svg @@ -16252,4 +16252,36 @@ http://www.inkscape.org/ x="905" y="240" /> + + + + + + diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index ac4209703..208bc7994 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -160,10 +160,12 @@ static char const menus_skeleton[] = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" " \n" +" \n" " \n" " \n" " \n" diff --git a/src/nodepath.cpp b/src/nodepath.cpp index d0becd45d..e03484d7a 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -201,6 +201,8 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, np->local_change = 0; np->show_handles = show_handles; np->helper_path = NULL; + np->helperpath_rgba = 0xff0000ff; + np->helperpath_width = 1.0; np->curve = sp_curve_copy(curve); np->show_helperpath = false; np->straight_path = false; @@ -4541,6 +4543,26 @@ void sp_nodepath_set_curve (Inkscape::NodePath::Path *np, SPCurve *curve) { void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *np, bool show) { np->show_helperpath = show; + + if (show) { + SPCurve *helper_curve = sp_curve_copy(np->curve); + sp_curve_transform(helper_curve, np->i2d ); + if (!np->helper_path) { + np->helper_path = sp_canvas_bpath_new(sp_desktop_controls(np->desktop), helper_curve); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(np->helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(np->helper_path), 0, SP_WIND_RULE_NONZERO); + sp_canvas_item_show(np->helper_path); + } else { + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(np->helper_path), helper_curve); + } + sp_curve_unref(helper_curve); + } else { + if (np->helper_path) { + GtkObject *temp = np->helper_path; + np->helper_path = NULL; + gtk_object_destroy(temp); + } + } } /* this function does not work yet */ diff --git a/src/nodepath.h b/src/nodepath.h index 8f17ecb14..f426d414f 100644 --- a/src/nodepath.h +++ b/src/nodepath.h @@ -307,6 +307,7 @@ NR::Rect sp_node_selected_bbox (Inkscape::NodePath::Path *nodepath); NR::Maybe sp_node_selected_common_coord (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis); void sp_nodepath_show_handles(Inkscape::NodePath::Path *nodepath, bool show); +void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *nodepath, bool show); void sp_nodepath_selected_nodes_rotate (Inkscape::NodePath::Path * nodepath, gdouble angle, int which, bool screen); diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 12783c022..b974ce6d2 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -74,7 +74,7 @@ static char const preferences_skeleton[] = " \n" -" \n" +" \n" " \n" " \n" " \n" diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index e17452a55..6f038447e 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -86,6 +86,12 @@ #include "live_effects/parameter/path.h" #include "libnr/nr-convert2geom.h" +// For clippath editing +#include "tools-switch.h" +#include "shape-editor.h" +#include "node-context.h" +#include "nodepath.h" + using NR::X; using NR::Y; @@ -2130,6 +2136,50 @@ void sp_selection_next_patheffect_param(SPDesktop * dt) } } +void sp_selection_edit_clip_or_mask(SPDesktop * dt, bool clip) +{ + if (!dt) return; + + Inkscape::Selection *selection = sp_desktop_selection(dt); + if ( selection && !selection->isEmpty() ) { + SPItem *item = selection->singleItem(); + if ( item ) { + SPObject *obj = NULL; + if (clip) + obj = item->clip_ref ? SP_OBJECT(item->clip_ref->getObject()) : NULL; + else + obj = item->mask_ref ? SP_OBJECT(item->mask_ref->getObject()) : NULL; + + if (obj) { + // obj is a group object, the children are the actual clippers + for ( SPObject *child = obj->children ; child ; child = child->next ) { + if ( SP_IS_ITEM(child) ) { + // If not already in nodecontext, goto it! + if (!tools_isactive(dt, TOOLS_NODES)) { + tools_switch_current(TOOLS_NODES); + } + + ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor; + shape_editor->set_item(SP_ITEM(child)); + Inkscape::NodePath::Path *np = shape_editor->get_nodepath(); + if (np) { + np->helperpath_rgba = clip ? 0x0000ffff : 0x800080ff; + np->helperpath_width = 1.0; + sp_nodepath_show_helperpath(np, true); + } + break; // break out of for loop after 1st encountered item + } + } + } else if (clip) { + dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied clip path.")); + } else { + dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied mask.")); + } + } + } +} + + namespace { template diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 501dcc520..9307fe5c0 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -98,6 +98,8 @@ void sp_selection_item_prev (void); void sp_selection_next_patheffect_param(SPDesktop * dt); +void sp_selection_edit_clip_or_mask(SPDesktop * dt, bool clip); + void scroll_to_show_item(SPDesktop *desktop, SPItem *item); void sp_undo (SPDesktop *desktop, SPDocument *doc); diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp index 0f630ac50..fbf42eaca 100644 --- a/src/shape-editor.cpp +++ b/src/shape-editor.cpp @@ -480,6 +480,10 @@ void ShapeEditor::show_handles (bool show) { sp_nodepath_show_handles (this->nodepath, show); } +void ShapeEditor::show_helperpath (bool show) { + if (this->nodepath) + sp_nodepath_show_helperpath (this->nodepath, show); +} void ShapeEditor::flip (NR::Dim2 axis, NR::Maybe center) { if (this->nodepath) diff --git a/src/shape-editor.h b/src/shape-editor.h index c4271568f..8e563b433 100644 --- a/src/shape-editor.h +++ b/src/shape-editor.h @@ -107,6 +107,7 @@ public: void select_prev (); void show_handles (bool show); + void show_helperpath (bool show); void flip (NR::Dim2 axis, NR::Maybe center = NR::Nothing()); diff --git a/src/verbs.cpp b/src/verbs.cpp index 2902a4a2f..08f1bb124 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1335,12 +1335,18 @@ ObjectVerb::perform( SPAction *action, void *data, void */*pdata*/ ) case SP_VERB_OBJECT_SET_MASK: sp_selection_set_mask(false, false); break; + case SP_VERB_OBJECT_EDIT_MASK: + sp_selection_edit_clip_or_mask(dt, false); + break; case SP_VERB_OBJECT_UNSET_MASK: sp_selection_unset_mask(false); break; case SP_VERB_OBJECT_SET_CLIPPATH: sp_selection_set_mask(true, false); break; + case SP_VERB_OBJECT_EDIT_CLIPPATH: + sp_selection_edit_clip_or_mask(dt, true); + break; case SP_VERB_OBJECT_UNSET_CLIPPATH: sp_selection_unset_mask(true); break; @@ -2363,10 +2369,14 @@ Verb *Verb::_base_verbs[] = { "object_flip_ver"), new ObjectVerb(SP_VERB_OBJECT_SET_MASK, "ObjectSetMask", N_("_Set"), N_("Apply mask to selection (using the topmost object as mask)"), NULL), + new ObjectVerb(SP_VERB_OBJECT_EDIT_MASK, "ObjectEditMask", N_("_Edit"), + N_("Edit mask"), NULL), new ObjectVerb(SP_VERB_OBJECT_UNSET_MASK, "ObjectUnSetMask", N_("_Release"), N_("Remove mask from selection"), NULL), new ObjectVerb(SP_VERB_OBJECT_SET_CLIPPATH, "ObjectSetClipPath", N_("_Set"), N_("Apply clipping path to selection (using the topmost object as clipping path)"), NULL), + new ObjectVerb(SP_VERB_OBJECT_EDIT_CLIPPATH, "ObjectEditClipPath", N_("_Edit"), + N_("Edit clipping path"), NULL), new ObjectVerb(SP_VERB_OBJECT_UNSET_CLIPPATH, "ObjectUnSetClipPath", N_("_Release"), N_("Remove clipping path from selection"), NULL), diff --git a/src/verbs.h b/src/verbs.h index b754d3807..6576c9652 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -137,8 +137,10 @@ enum { SP_VERB_OBJECT_FLIP_HORIZONTAL, SP_VERB_OBJECT_FLIP_VERTICAL, SP_VERB_OBJECT_SET_MASK, + SP_VERB_OBJECT_EDIT_MASK, SP_VERB_OBJECT_UNSET_MASK, SP_VERB_OBJECT_SET_CLIPPATH, + SP_VERB_OBJECT_EDIT_CLIPPATH, SP_VERB_OBJECT_UNSET_CLIPPATH, /* Tools */ SP_VERB_CONTEXT_SELECT, diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 8cdf0a07f..fcf3e0ce6 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -250,6 +250,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " " " @@ -845,6 +846,13 @@ static void toggle_show_handles (GtkToggleAction *act, gpointer /*data*/) { if (shape_editor) shape_editor->show_handles(show); } +static void toggle_show_helperpath (GtkToggleAction *act, gpointer /*data*/) { + bool show = gtk_toggle_action_get_active( act ); + prefs_set_int_attribute ("tools.nodes", "show_helperpath", show ? 1 : 0); + ShapeEditor *shape_editor = get_current_shape_editor(); + if (shape_editor) shape_editor->show_helperpath(show); +} + void sp_node_path_edit_nextLPEparam (GtkAction */*act*/, gpointer data) { sp_selection_next_patheffect_param( reinterpret_cast(data) ); } @@ -1095,6 +1103,17 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.nodes", "show_handles", 1 ) ); } + { + InkToggleAction* act = ink_toggle_action_new( "NodesShowHelperpath", + _("Show Outline"), + _("Show the outline of the path"), + "nodes_show_helperpath", + Inkscape::ICON_SIZE_DECORATION ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_helperpath), desktop ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.nodes", "show_helperpath", 0 ) ); + } + { InkAction* inky = ink_action_new( "EditNextLPEParameterAction", _("Next Path Effect Parameter"), -- 2.39.5