diff --git a/editor/images/svg_edit_icons.svg b/editor/images/svg_edit_icons.svg index 00a0ffde..3653d24a 100644 --- a/editor/images/svg_edit_icons.svg +++ b/editor/images/svg_edit_icons.svg @@ -198,6 +198,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/editor/svg-editor.html b/editor/svg-editor.html index dc346d03..42b62d15 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -365,6 +365,7 @@ script type="text/javascript" src="locale/locale.min.js">
+
diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 9722f007..a1363673 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -794,6 +794,7 @@ function svg_edit_setup() { $('#tool_reorient').toggleClass('disabled', angle == 0); } else { var point = path.getNodePoint(); + $('#tool_add_subpath').removeClass('push_button_pressed').addClass('tool_button'); $('#tool_node_delete').toggleClass('disabled', !path.canDeleteNodes); if(point) { var seg_type = $('#seg_type'); @@ -1414,6 +1415,20 @@ function svg_edit_setup() { path.deletePathNode(); } }; + + var addSubPath = function() { + var button = $('#tool_add_subpath'); + var sp = !button.hasClass('push_button_pressed'); + if (sp) { + button.addClass('push_button_pressed').removeClass('tool_button'); + } else { + button.removeClass('push_button_pressed').addClass('tool_button'); + } + + path.addSubPath(sp); + + }; + var selectNext = function() { svgCanvas.cycleElement(1); @@ -2486,6 +2501,7 @@ function svg_edit_setup() { {sel:'#tool_node_link', fn: linkControlPoints, evt: 'click'}, {sel:'#tool_node_clone', fn: clonePathNode, evt: 'click'}, {sel:'#tool_node_delete', fn: deletePathNode, evt: 'click'}, + {sel:'#tool_add_subpath', fn: addSubPath, evt: 'click'}, {sel:'#tool_move_top', fn: moveToTopSelected, evt: 'click', key: 'shift+up'}, {sel:'#tool_move_bottom', fn: moveToBottomSelected, evt: 'click', key: 'shift+down'}, {sel:'#tool_topath', fn: convertToPath, evt: 'click'}, @@ -2885,6 +2901,7 @@ function svg_edit_setup() { '#tool_clone,#tool_clone_multi,#tool_node_clone':'clone', '#layer_delete,#tool_delete,#tool_delete_multi,#tool_node_delete':'delete', + '#tool_add_subpath':'add_subpath', '#tool_move_top':'move_top', '#tool_move_bottom':'move_bottom', '#tool_topath':'to_path', diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 854aa3b2..a8b442e4 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -3741,6 +3741,7 @@ function BatchCommand(text) { var pathActions = function() { + var subpath = false; var pathData = {}; var current_path; var path; @@ -4347,6 +4348,13 @@ function BatchCommand(text) { this.selectPt = function(pt, ctrl_num) { p.clearSelection(); + if(pt == null) { + p.eachSeg(function(i) { + if(this.prev) { + pt = i; + } + }); + } p.addPtsToSelection(pt); if(ctrl_num) { p.dragctrl = ctrl_num; @@ -4806,7 +4814,8 @@ function BatchCommand(text) { 'x2': mouse_x, 'y2': mouse_y }); - addPointGrip(0,mouse_x,mouse_y); + var index = subpath ? path.segs.length : 0; + addPointGrip(index, mouse_x, mouse_y); } else { // determine if we clicked on an existing point @@ -4849,13 +4858,23 @@ function BatchCommand(text) { keep = false; return keep; } - // removeAllPointGripsFromPath(); $(stretchy).remove(); // this will signal to commit the path element = newpath; current_path_pts = []; started = false; + + if(subpath) { + var new_d = newpath.getAttribute("d"); + var orig_d = $(path.elem).attr("d"); + $(path.elem).attr("d", orig_d + new_d); + $(newpath).remove(); + path.init(); + pathActions.toEditMode(path.elem); + path.selectPt(); + return false; + } } // else, create a new point, append to pts array, update path element else { @@ -4880,7 +4899,9 @@ function BatchCommand(text) { 'x2': mouse_x, 'y2': mouse_y }); - addPointGrip((current_path_pts.length/2 - 1),mouse_x,mouse_y); + var index = (current_path_pts.length/2 - 1); + if(subpath) index += path.segs.length; + addPointGrip(index, mouse_x, mouse_y); } keep = true; } @@ -4931,6 +4952,7 @@ function BatchCommand(text) { canvas.clearSelection(); path.show(true).update(); path.oldbbox = canvas.getBBox(path.elem); + subpath = false; }, toSelectMode: function(elem) { var selPath = (elem == path.elem); @@ -4949,6 +4971,17 @@ function BatchCommand(text) { canvas.addToSelection([elem], true); } }, + addSubPath: function(on) { + if(on) { + // Internally we go into "path" mode, but in the UI it will + // still appear as if in "pathedit" mode. + current_mode = "path"; + subpath = true; + } else { + pathActions.clear(true); + pathActions.toEditMode(path.elem); + } + }, select: function(target) { if (current_path == target) { pathActions.toEditMode(target);