Added clone node option, cleaned up some poly point code

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@774 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2009-10-07 16:04:32 +00:00
parent 824c66229a
commit 94f99e937a
3 changed files with 68 additions and 32 deletions

View File

@ -249,6 +249,7 @@ script type="text/javascript" src="locale/locale.min.js"></script-->
<input id="poly_node_x" class="poly_node_tool attr_changer" title="Change node's x coordinate" size="3" data-attr="x"/> <input id="poly_node_x" class="poly_node_tool attr_changer" title="Change node's x coordinate" size="3" data-attr="x"/>
<label class="poly_node_tool">y:</label> <label class="poly_node_tool">y:</label>
<input id="poly_node_y" class="poly_node_tool attr_changer" title="Change node's y coordinate" size="3" data-attr="y"/> <input id="poly_node_y" class="poly_node_tool attr_changer" title="Change node's y coordinate" size="3" data-attr="y"/>
<img class="tool_button" id="tool_node_clone" src="images/clone.png" title="Clone Node" alt="Clone"/>
<img class="tool_button" id="tool_node_delete" src="images/delete.png" title="Delete Node" alt="Delete"/> <img class="tool_button" id="tool_node_delete" src="images/delete.png" title="Delete Node" alt="Delete"/>
</div> </div>

View File

@ -56,8 +56,8 @@ function svg_edit_setup() {
if (svgCanvas.getMode() != "multiselect" && !is_node) { if (svgCanvas.getMode() != "multiselect" && !is_node) {
setSelectMode(); setSelectMode();
updateToolbar();
} }
updateToolbar();
} // if (elem != null) } // if (elem != null)
updateContextPanel(); updateContextPanel();
@ -632,6 +632,12 @@ function svg_edit_setup() {
svgCanvas.moveSelectedElements(dx,dy); svgCanvas.moveSelectedElements(dx,dy);
} }
}; };
var cloneNode = function() {
if (svgCanvas.getNodePoint()) {
svgCanvas.cloneNode();
}
};
var deleteNode = function() { var deleteNode = function() {
if (svgCanvas.getNodePoint()) { if (svgCanvas.getNodePoint()) {
@ -852,6 +858,7 @@ function svg_edit_setup() {
$('#tool_docprops').click(showDocProperties); $('#tool_docprops').click(showDocProperties);
$('#tool_delete').click(deleteSelected); $('#tool_delete').click(deleteSelected);
$('#tool_delete_multi').click(deleteSelected); $('#tool_delete_multi').click(deleteSelected);
$('#tool_node_clone').click(cloneNode);
$('#tool_node_delete').click(deleteNode); $('#tool_node_delete').click(deleteNode);
$('#tool_move_top').click(moveToTopSelected); $('#tool_move_top').click(moveToTopSelected);
$('#tool_move_bottom').click(moveToBottomSelected); $('#tool_move_bottom').click(moveToBottomSelected);

View File

@ -1399,7 +1399,12 @@ function BatchCommand(text) {
this.addNodeToSelection = function(point) { this.addNodeToSelection = function(point) {
// Currently only one node can be selected at a time, should allow more later // Currently only one node can be selected at a time, should allow more later
// Should point be the index or the grip element? // Should point be the index or the grip element?
current_poly_pt = point; if(point == current_poly_pts.length/2 - 1) {
current_poly_pt = 0;
} else {
current_poly_pt = point;
}
$('#polypointgrip_container circle').attr('fill','#0F0'); $('#polypointgrip_container circle').attr('fill','#0F0');
var grip = $('#polypointgrip_' + point).attr('fill','blue'); var grip = $('#polypointgrip_' + point).attr('fill','blue');
call("selected", [grip[0]]); call("selected", [grip[0]]);
@ -2007,12 +2012,16 @@ function BatchCommand(text) {
} }
}; };
var resetPointGrips = function() {
var sr = svgroot.suspendRedraw(100);
removeAllPointGripsFromPoly();
addAllPointGripsToPoly();
svgroot.unsuspendRedraw(sr);
};
var removeAllPointGripsFromPoly = function() { var removeAllPointGripsFromPoly = function() {
// loop through and hide all pointgrips // loop through and hide all pointgrips
var i = current_poly_pts.length/2; $('#polypointgrip_container > *').attr("display", "none");
while(i--) {
document.getElementById("polypointgrip_"+i).setAttribute("display", "none");
}
var line = document.getElementById("poly_stretch_line"); var line = document.getElementById("poly_stretch_line");
if (line) line.setAttribute("display", "none"); if (line) line.setAttribute("display", "none");
@ -3245,12 +3254,44 @@ function BatchCommand(text) {
return false; return false;
} }
} }
this.deleteNode = function() { this.cloneNode = function() {
if(current_poly_pt == current_poly_pts.length/2 - 1) { var pt = current_poly_pt, list = current_poly.pathSegList;
var last_pt = current_poly_pt;
current_poly_pt = 0; var next_item = list.getItem(pt+1);
// Get point in between nodes
if(next_item.pathSegType % 2 == 0) { // even num, so abs
var cur_item = list.getItem(pt);
var new_x = (next_item.x - cur_item.x) / 2;
var new_y = (next_item.y - cur_item.y) / 2;
} else {
var new_x = next_item.x/2;
var new_y = next_item.y/2;
} }
var seg = current_poly.createSVGPathSegLinetoRel(new_x, new_y);
list.insertItemBefore(seg, pt+1); // Webkit doesn't do this right.
replacePathSeg(5, pt+2, [new_x, new_y]);
var abs_x = getPolyPoint(pt)[0] + new_x;
var abs_y = getPolyPoint(pt)[1] + new_y;
var last_num = current_poly_pts.length/2;
// Add new grip
addPointGripToPoly(abs_x, abs_y, last_num);
// Update poly_pts
current_poly_pts.splice(pt*2 + 2, 0, abs_x, abs_y);
resetPointGrips();
this.addNodeToSelection(pt+1);
}
this.deleteNode = function() {
var last_pt = current_poly_pts.length/2 - 1;
var pt = current_poly_pt, list = current_poly.pathSegList; var pt = current_poly_pt, list = current_poly.pathSegList;
var cur_item = list.getItem(pt); var cur_item = list.getItem(pt);
var next_item = list.getItem(pt+1); var next_item = list.getItem(pt+1);
@ -3264,36 +3305,23 @@ function BatchCommand(text) {
// Reposition last node // Reposition last node
var last_item = list.getItem(last_pt); var last_item = list.getItem(last_pt);
replacePathSeg(5, last_pt, [next_x - getPolyPoint(last_pt-1)[0], next_y - getPolyPoint(last_pt-1)[1]]); replacePathSeg(5, last_pt, [next_x - getPolyPoint(last_pt-1)[0], next_y - getPolyPoint(last_pt-1)[1]]);
assignAttributes($('#polypointgrip_' + last_pt)[0], {
cx: next_x * current_zoom,
cy: next_y * current_zoom
});
removeControlPointGrips(last_pt - 1); removeControlPointGrips(last_pt - 1);
current_poly_pts.splice(last_pt*2, 2, next_x, next_y);
current_poly_pts.splice(0, 2);
} else { } else {
// Since relative values are used, the current point's values need to be added to the next one. // Since relative values are used, the current point's values need to be added to the next one.
// Hard to tell whether it should be straight or curve, so always straight for now // Hard to tell whether it should be straight or curve, so always straight for now
replacePathSeg(5, pt+1, [next_item.x + cur_item.x, next_item.y + cur_item.y]); replacePathSeg(5, pt+1, [next_item.x + cur_item.x, next_item.y + cur_item.y]);
current_poly_pts.splice(pt*2, 2);
} }
removeControlPointGrips(pt);
removeControlPointGrips(pt-1);
list.removeItem(pt); list.removeItem(pt);
current_poly_pts.splice(pt*2, 2);
$('#polypointgrip_' + pt).remove();
$('#polypointgrip_container circle').each(function(i, item) {
this.id = 'polypointgrip_' + i;
});
$('#ctrlpointgrip_container circle').each(function(i, item) { resetPointGrips();
var data = this.id.match(/_(\d+)(c\d)/);
var inum = data[1] - 0; if(window.opera) { // Opera repaints incorrectly
var cnum = data[2]; var cp = $(current_poly); cp.attr('d',cp.attr('d'));
if(inum >= pt) { }
this.id = 'ctrlpointgrip_' + (inum-1) + cnum;
$('#ctrlLine_' + inum + cnum)[0].id = 'ctrlLine_' + (inum-1) + cnum;
}
});
this.addNodeToSelection(pt); this.addNodeToSelection(pt);
} }