Code

* on-canvas clip and mask editing :) in the object menu you can find how to edit...
authorjohanengelen <johanengelen@users.sourceforge.net>
Sat, 23 Feb 2008 21:52:43 +0000 (21:52 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sat, 23 Feb 2008 21:52:43 +0000 (21:52 +0000)
* show helperpath toggle on node-edit toolbar. so helperpath is now also available for normal paths (instead of only for LPE'd paths)

12 files changed:
share/icons/icons.svg
src/menus-skeleton.h
src/nodepath.cpp
src/nodepath.h
src/preferences-skeleton.h
src/selection-chemistry.cpp
src/selection-chemistry.h
src/shape-editor.cpp
src/shape-editor.h
src/verbs.cpp
src/verbs.h
src/widgets/toolbox.cpp

index 65cbf7307295f5a8baf7d94dd675971c13bb583b..9915d8c882b67cc54dcfcbcdf70cd4ad9aaf59e4 100644 (file)
@@ -16252,4 +16252,36 @@ http://www.inkscape.org/</dc:description>
        x="905"
        y="240" />
   </g>
+  <g
+     id="nodes_show_helperpath"
+     transform="translate(835.01871,-120.9465)">
+    <path
+       style="fill:#ffffff;fill-opacity:0.75;fill-rule:evenodd;stroke:#ff0000;stroke-width:1.00000024;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:0;stroke-dasharray:none;stroke-opacity:1"
+       d="M -42.51871,188.4465 C -42.51871,182.9474 -42.01871,177.9465 -31.51871,177.4465 C -30.253328,177.38624 -33.51871,187.4465 -42.51871,188.4465"
+       id="path4756"
+       sodipodi:nodetypes="csc" />
+    <rect
+       y="175"
+       x="-45"
+       height="16"
+       width="16"
+       id="rect4758"
+       style="opacity:1;fill:none;fill-opacity:0.16788318;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:0;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;display:inline" />
+    <use
+       transform="translate(-4.9762,-5.349982e-2)"
+       x="0"
+       y="0"
+       xlink:href="#rect4374"
+       id="use4760"
+       width="1250"
+       height="1250" />
+    <use
+       transform="translate(5.981293,-11.02417)"
+       x="0"
+       y="0"
+       xlink:href="#rect4374"
+       id="use4762"
+       width="1250"
+       height="1250" />
+  </g>
 </svg>
index ac420970302c53caee67f5a4b5c1a431b5838852..208bc799429948e02c469ce71d76004b81f2ebb8 100644 (file)
@@ -160,10 +160,12 @@ static char const menus_skeleton[] =
 "       <separator/>\n"
 "       <submenu name=\"" N_("Cli_p") "\">\n"
 "           <verb verb-id=\"ObjectSetClipPath\" />\n"
+"           <verb verb-id=\"ObjectEditClipPath\" />\n"
 "           <verb verb-id=\"ObjectUnSetClipPath\" />\n"
 "       </submenu>\n"
 "       <submenu name=\"" N_("Mas_k") "\">\n"
 "           <verb verb-id=\"ObjectSetMask\" />\n"
+"           <verb verb-id=\"ObjectEditMask\" />\n"
 "           <verb verb-id=\"ObjectUnSetMask\" />\n"
 "       </submenu>\n"
 "       <submenu name=\"" N_("Patter_n") "\">\n"
index d0becd45dbf58f01042facd59a7bce2496bb0fbd..e03484d7a383033b8af80f7499e5b8040ad11f62 100644 (file)
@@ -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 */
index 8f17ecb14b966a76596abfb54120f7912cf53dd1..f426d414f68e1fba1c8bde40f866093a1e8dbdd0 100644 (file)
@@ -307,6 +307,7 @@ NR::Rect sp_node_selected_bbox (Inkscape::NodePath::Path *nodepath);
 NR::Maybe<NR::Coord> 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);
 
index 12783c02250edf263efd1481e472c4a12d2d4153..b974ce6d2e502f429d4d0fca37ad0d984d00ce46 100644 (file)
@@ -74,7 +74,7 @@ static char const preferences_skeleton[] =
 "    <eventcontext id=\"text\"  usecurrent=\"0\" gradientdrag=\"1\"\n" 
 "                       font_sample=\"AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()\"\n"
 "                  style=\"fill:black;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans;font-style:normal;font-weight:normal;font-size:40px;\" selcue=\"1\"/>\n"
-"    <eventcontext id=\"nodes\" selcue=\"1\" gradientdrag=\"1\" show_handles=\"1\" sculpting_profile=\"1\" />\n"
+"    <eventcontext id=\"nodes\" selcue=\"1\" gradientdrag=\"1\" show_handles=\"1\" show_helperpath=\"0\" sculpting_profile=\"1\" />\n"
 "    <eventcontext id=\"tweak\" selcue=\"0\" gradientdrag=\"0\" show_handles=\"0\" width=\"0.2\" force=\"0.2\" fidelity=\"0.5\" usepressure=\"1\" style=\"fill:red;stroke:none;\" usecurrent=\"0\"/>\n"
 "    <eventcontext id=\"gradient\" selcue=\"1\"/>\n"
 "    <eventcontext id=\"zoom\" selcue=\"1\" gradientdrag=\"0\"/>\n"
index e17452a5521a7bccd31aa31b97b550d6f34f68d9..6f038447ef15b427bf6b777478ed5cd3887c396a 100644 (file)
 #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 <typename D>
index 501dcc520ed8ee52b7f3ad96a538ebd0f2f49e63..9307fe5c06c75b227352f386d59223521f5dfb7e 100644 (file)
@@ -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);
index 0f630ac503482748969465d45d3e07a88f39ca5a..fbf42eaca1b8ebc71f1ce116c0db6036b134a5af 100644 (file)
@@ -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<NR::Point> center) {
     if (this->nodepath)
index c4271568f975b78b51e24b8a0c26218bf054d4ee..8e563b433d0185afb658cb2f31d6fcc8f2db781b 100644 (file)
@@ -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<NR::Point> center = NR::Nothing());
 
index 2902a4a2f9c89136384501b753862c5684ce6851..08f1bb124241362ba928d87d0bb6dccf19ba22db 100644 (file)
@@ -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),
 
index b754d3807d440d21a6e6811be97027ce8a1c779b..6576c96527685bb782f00a48b2ea12118e227679 100644 (file)
@@ -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,
index 8cdf0a07fcee4869fb4a1fe4cddb09f19670a4cc..fcf3e0ce6bd874917ee2b0730179a33b326adf6e 100644 (file)
@@ -250,6 +250,7 @@ static gchar const * ui_descr =
         "    <toolitem action='StrokeToPath' />"
         "    <separator />"
         "    <toolitem action='NodesShowHandlesAction' />"
+        "    <toolitem action='NodesShowHelperpath' />"
         "    <separator />"
         "    <toolitem action='EditNextLPEParameterAction' />"
         "    <separator />"
@@ -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<SPDesktop*>(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"),