fixed drag and drop bug related to drag constraints and positioned containers. Just needed to move the drag constraint logic after the matrix unravel

This commit is contained in:
Eric Rowell 2012-04-01 15:59:12 -07:00
parent bdafb3eb25
commit 313c6a1541
4 changed files with 34 additions and 23 deletions

23
dist/kinetic-core.js vendored
View File

@ -1676,14 +1676,6 @@ Kinetic.Stage.prototype = {
newNodePos.y = db.bottom; newNodePos.y = db.bottom;
} }
// constraint overrides
if(dc === 'horizontal') {
newNodePos.y = node.y;
}
else if(dc === 'vertical') {
newNodePos.x = node.x;
}
/* /*
* save rotation and scale and then * save rotation and scale and then
* remove them from the transform * remove them from the transform
@ -1703,9 +1695,20 @@ Kinetic.Stage.prototype = {
var it = node.getAbsoluteTransform(); var it = node.getAbsoluteTransform();
it.invert(); it.invert();
it.translate(newNodePos.x, newNodePos.y); it.translate(newNodePos.x, newNodePos.y);
newNodePos = {
x: node.x + it.getTranslation().x,
y: node.y + it.getTranslation().y
};
node.x += it.getTranslation().x; // constraint overrides
node.y += it.getTranslation().y; if(dc === 'horizontal') {
newNodePos.y = node.y;
}
else if(dc === 'vertical') {
newNodePos.x = node.x;
}
node.setPosition(newNodePos.x, newNodePos.y);
// restore rotation and scale // restore rotation and scale
node.rotate(rot); node.rotate(rot);

File diff suppressed because one or more lines are too long

View File

@ -646,14 +646,6 @@ Kinetic.Stage.prototype = {
newNodePos.y = db.bottom; newNodePos.y = db.bottom;
} }
// constraint overrides
if(dc === 'horizontal') {
newNodePos.y = node.y;
}
else if(dc === 'vertical') {
newNodePos.x = node.x;
}
/* /*
* save rotation and scale and then * save rotation and scale and then
* remove them from the transform * remove them from the transform
@ -673,9 +665,20 @@ Kinetic.Stage.prototype = {
var it = node.getAbsoluteTransform(); var it = node.getAbsoluteTransform();
it.invert(); it.invert();
it.translate(newNodePos.x, newNodePos.y); it.translate(newNodePos.x, newNodePos.y);
newNodePos = {
x: node.x + it.getTranslation().x,
y: node.y + it.getTranslation().y
};
node.x += it.getTranslation().x; // constraint overrides
node.y += it.getTranslation().y; if(dc === 'horizontal') {
newNodePos.y = node.y;
}
else if(dc === 'vertical') {
newNodePos.x = node.x;
}
node.setPosition(newNodePos.x, newNodePos.y);
// restore rotation and scale // restore rotation and scale
node.rotate(rot); node.rotate(rot);

View File

@ -1264,13 +1264,17 @@ Test.prototype.tests = {
layer.add(circle2); layer.add(circle2);
stage.add(layer); stage.add(layer);
}, },
'DRAG AND DROP - drag and drop constrianed horiztonally': function(containerId) { 'DRAG AND DROP - drag and drop constrianed horiztontally inside positioned group': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
container: containerId, container: containerId,
width: 578, width: 578,
height: 200 height: 200
}); });
var layer = new Kinetic.Layer(); var layer = new Kinetic.Layer();
var group = new Kinetic.Group({
x: 0,
y: 10
});
var circle = new Kinetic.Circle({ var circle = new Kinetic.Circle({
x: stage.width / 2, x: stage.width / 2,
y: stage.height / 2, y: stage.height / 2,
@ -1282,7 +1286,8 @@ Test.prototype.tests = {
dragConstraint: 'horizontal' dragConstraint: 'horizontal'
}); });
layer.add(circle); group.add(circle);
layer.add(group);
stage.add(layer); stage.add(layer);
}, },
'DRAG AND DROP - drag and drop constrianed vertically': function(containerId) { 'DRAG AND DROP - drag and drop constrianed vertically': function(containerId) {