Improved path node deleting behaviour, added functions to get svgCanvas vars: getContentElem, getRootElem and getSelectedElems

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1455 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-03-11 15:27:18 +00:00
parent 38a244bcc6
commit 750e6456b3
2 changed files with 75 additions and 5 deletions

View File

@ -269,9 +269,15 @@
<g id="new_image">
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="2.42792" y="1.6692" width="18" height="21" id="svg_55" fill="#eaeaea" stroke="#606060"/>
<circle stroke-width="0" stroke="#a0a0a0" fill="#fff175" id="svg_65" r="3.83333" cy="6.24769" cx="19.16813"/>
<circle stroke-width="0" stroke="#a0a0a0" fill="url(#svg_9)" id="svg_65" r="6.300781" cy="7.529969" cx="17.761984"/>
<defs>
<radialGradient id="svg_9" cx="0.5" cy="0.5" r="0.5">
<stop offset="0.1" stop-color="#ffe500" stop-opacity="1"/>
<stop offset="1" stop-color="#ffff00" stop-opacity="0"/>
</radialGradient>
</defs>
</svg>
</g>

View File

@ -3899,7 +3899,10 @@ function BatchCommand(text) {
if(update) {
var prev = seg.prev;
if(!prev) return segLine;
if(!prev) {
segLine.setAttribute("display", "none");
return segLine;
}
var pt = getGripPt(prev);
// Set start point
@ -5096,6 +5099,7 @@ function BatchCommand(text) {
}
else if (current_mode == "pathedit") {
this.clear();
this.toSelectMode();
}
},
getNodePoint: function() {
@ -5143,8 +5147,64 @@ function BatchCommand(text) {
path.deleteSeg(pt);
}
// Cleanup
var cleanup = function() {
var segList = path.elem.pathSegList;
var len = segList.numberOfItems;
var remItems = function(pos, count) {
while(count--) {
segList.removeItem(pos);
}
}
if(len <= 1) return true;
while(len--) {
var item = segList.getItem(len);
if(item.pathSegType === 1) {
var prev = segList.getItem(len-1);
var nprev = segList.getItem(len-2);
if(prev.pathSegType === 2) {
remItems(len-1, 2);
cleanup();
break;
} else if(nprev.pathSegType === 2) {
remItems(len-2, 3);
cleanup();
break;
}
} else if(item.pathSegType === 2) {
if(len > 0) {
var prev_type = segList.getItem(len-1).pathSegType;
// Path has M M
if(prev_type === 2) {
remItems(len-1, 1);
cleanup();
break;
// Entire path ends with Z M
} else if(prev_type === 1 && segList.numberOfItems-1 === len) {
remItems(len, 1);
cleanup();
break;
}
}
}
}
return false;
}
cleanup();
// Completely delete a path with 1 or 0 segments
if(path.elem.pathSegList.numberOfItems <= 1) {
pathActions.toSelectMode(path.elem);
canvas.deleteSelectedElements();
return;
}
path.init();
var sel_pt = sel_pts[0]-1 > 0 ? sel_pts[0]-1 : 1;
path.clearSelection();
@ -6376,6 +6436,10 @@ function BatchCommand(text) {
pathActions.linkControlPoints(linkPoints);
}
this.getContentElem = function() { return svgcontent; };
this.getRootElem = function() { return svgroot; };
this.getSelectedElems = function() { return selectedElements; };
this.getResolution = function() {
// var vb = svgcontent.getAttribute("viewBox").split(' ');
// return {'w':vb[2], 'h':vb[3], 'zoom': current_zoom};