Standardized x/y variables on mouse events, more polyedit+zoom improvements

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@625 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2009-09-11 13:32:56 +00:00
parent 05765706dc
commit d9ebb5bf08
1 changed files with 29 additions and 31 deletions

View File

@ -1331,8 +1331,8 @@ function BatchCommand(text) {
// and do nothing else // and do nothing else
var mouseDown = function(evt) var mouseDown = function(evt)
{ {
var x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft; var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft;
var y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop; var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop;
evt.preventDefault(); evt.preventDefault();
@ -1340,8 +1340,8 @@ function BatchCommand(text) {
addGradient(); addGradient();
} }
x /= current_zoom; x = mouse_x / current_zoom;
y /= current_zoom; y = mouse_y / current_zoom;
start_x = x; start_x = x;
start_y = y; start_y = y;
@ -1595,12 +1595,12 @@ function BatchCommand(text) {
{ {
if (!started) return; if (!started) return;
var selected = selectedElements[0]; var selected = selectedElements[0];
var x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft; var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft;
var y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop; var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop;
var shape = svgdoc.getElementById(getId()); var shape = svgdoc.getElementById(getId());
x /= current_zoom; x = mouse_x / current_zoom;
y /= current_zoom; y = mouse_y / current_zoom;
evt.preventDefault(); evt.preventDefault();
@ -1896,8 +1896,8 @@ function BatchCommand(text) {
// move the point grip // move the point grip
var grip = document.getElementById("polypointgrip_" + current_poly_pt_drag); var grip = document.getElementById("polypointgrip_" + current_poly_pt_drag);
if (grip) { if (grip) {
grip.setAttribute("cx", x); grip.setAttribute("cx", mouse_x);
grip.setAttribute("cy", y); grip.setAttribute("cy", mouse_y);
} }
} }
break; break;
@ -1992,8 +1992,10 @@ function BatchCommand(text) {
justSelected = null; justSelected = null;
if (!started) return; if (!started) return;
var x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft; var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft;
var y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop; var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop;
var x = mouse_x / current_zoom;
var y = mouse_y / current_zoom;
started = false; started = false;
var element = svgdoc.getElementById(getId()); var element = svgdoc.getElementById(getId());
@ -2048,8 +2050,8 @@ function BatchCommand(text) {
current_poly_pts = []; current_poly_pts = [];
var segList = t.pathSegList; var segList = t.pathSegList;
var curx = segList.getItem(0).x, cury = segList.getItem(0).y; var curx = segList.getItem(0).x, cury = segList.getItem(0).y;
current_poly_pts.push(curx); current_poly_pts.push(curx * current_zoom);
current_poly_pts.push(cury); current_poly_pts.push(cury * current_zoom);
var len = segList.numberOfItems; var len = segList.numberOfItems;
for (var i = 1; i < len; ++i) { for (var i = 1; i < len; ++i) {
var l = segList.getItem(i); var l = segList.getItem(i);
@ -2068,8 +2070,8 @@ function BatchCommand(text) {
curx += x; curx += x;
cury += y; cury += y;
} // type 5 (rel line) } // type 5 (rel line)
current_poly_pts.push(curx); current_poly_pts.push(curx * current_zoom);
current_poly_pts.push(cury); current_poly_pts.push(cury * current_zoom);
} // for each segment } // for each segment
canvas.clearSelection(); canvas.clearSelection();
// save the poly's bbox // save the poly's bbox
@ -2169,10 +2171,6 @@ function BatchCommand(text) {
element = null; element = null;
// continue to be set to true so that mouseMove happens // continue to be set to true so that mouseMove happens
started = true; started = true;
var real_x = x;
var real_y = y;
x /= current_zoom;
y /= current_zoom;
var stretchy = document.getElementById("poly_stretch_line"); var stretchy = document.getElementById("poly_stretch_line");
if (!stretchy) { if (!stretchy) {
stretchy = document.createElementNS(svgns, "line"); stretchy = document.createElementNS(svgns, "line");
@ -2206,12 +2204,12 @@ function BatchCommand(text) {
}); });
// set stretchy line to first point // set stretchy line to first point
assignAttributes(stretchy, { assignAttributes(stretchy, {
'x1': real_x, 'x1': mouse_x,
'y1': real_y, 'y1': mouse_y,
'x2': real_x, 'x2': mouse_x,
'y2': real_y 'y2': mouse_y
}); });
addPointGripToPoly(real_x,real_y,0); addPointGripToPoly(mouse_x,mouse_y,0);
} }
else { else {
// determine if we clicked on an existing point // determine if we clicked on an existing point
@ -2263,12 +2261,12 @@ function BatchCommand(text) {
// set stretchy line to latest point // set stretchy line to latest point
assignAttributes(stretchy, { assignAttributes(stretchy, {
'x1': real_x, 'x1': mouse_x,
'y1': real_y, 'y1': mouse_y,
'x2': real_x, 'x2': mouse_x,
'y2': real_y 'y2': mouse_y
}); });
addPointGripToPoly(real_x,real_y,(current_poly_pts.length/2 - 1)); addPointGripToPoly(mouse_x,mouse_y,(current_poly_pts.length/2 - 1));
} }
keep = true; keep = true;
} }