mirror of
https://github.com/konvajs/konva.git
synced 2025-12-05 03:24:23 +08:00
refactored setAbsolutePosition() method and Shape _draw method
This commit is contained in:
35
src/Stage.js
35
src/Stage.js
@@ -717,6 +717,10 @@ Kinetic.Stage.prototype = {
|
||||
var pos = that.getUserPosition();
|
||||
var dc = node.attrs.dragConstraint;
|
||||
var db = node.attrs.dragBounds;
|
||||
var lastNodePos = {
|
||||
x: node.attrs.x,
|
||||
y: node.attrs.y
|
||||
};
|
||||
|
||||
// default
|
||||
var newNodePos = {
|
||||
@@ -724,28 +728,6 @@ Kinetic.Stage.prototype = {
|
||||
y: pos.y - go.drag.offset.y
|
||||
};
|
||||
|
||||
/*
|
||||
* chrome currently has a bug that slows down drag and drop.
|
||||
* For google chrome instances, dynamically set the dragTimeInterval
|
||||
* to improve drag and drop performance while not effecting other browsers
|
||||
*/
|
||||
//if(go.isChrome) {
|
||||
/*
|
||||
* handle dynamice drag time interval. As the distance between
|
||||
* the mouse and cursor increases, we need to increase the drag
|
||||
* time interval to reduce the number of layer draws so that
|
||||
* the node position can catch back up to the cursor. When the difference
|
||||
* is zero, the time interval is zero. When the difference approahces
|
||||
* infinity, the time interval approaches the max drag time interval
|
||||
*/
|
||||
/*
|
||||
var dragDiffX = Math.abs(newNodePos.x - node.attrs.x);
|
||||
var dragDiffY = Math.abs(newNodePos.y - node.attrs.y);
|
||||
var dragDiff = Math.sqrt(Math.pow(dragDiffX, 2) + Math.pow(dragDiffY, 2));
|
||||
go.dragTimeInterval = go.maxDragTimeInterval * (dragDiff - 1) / (dragDiff + 1);
|
||||
*/
|
||||
//}
|
||||
|
||||
// bounds overrides
|
||||
if(db.left !== undefined && newNodePos.x < db.left) {
|
||||
newNodePos.x = db.left;
|
||||
@@ -760,17 +742,16 @@ Kinetic.Stage.prototype = {
|
||||
newNodePos.y = db.bottom;
|
||||
}
|
||||
|
||||
node.setAbsolutePosition(newNodePos);
|
||||
|
||||
// constraint overrides
|
||||
var override = {};
|
||||
if(dc === 'horizontal') {
|
||||
override.y = node.attrs.y;
|
||||
node.attrs.y = lastNodePos.y;
|
||||
}
|
||||
else if(dc === 'vertical') {
|
||||
override.x = node.attrs.x;
|
||||
node.attrs.x = lastNodePos.x;
|
||||
}
|
||||
|
||||
node.setAbsolutePosition(newNodePos, override);
|
||||
|
||||
go.drag.node.getLayer().draw();
|
||||
|
||||
if(!go.drag.moving) {
|
||||
|
||||
Reference in New Issue
Block a user