mirror of
https://github.com/konvajs/konva.git
synced 2025-11-18 17:21:36 +08:00
improved drag and drop performance by skipping buffer redraws on drag move
This commit is contained in:
@@ -28,18 +28,21 @@ Kinetic.DD._startDrag = function(evt) {
|
|||||||
|
|
||||||
if(!dd.moving) {
|
if(!dd.moving) {
|
||||||
dd.moving = true;
|
dd.moving = true;
|
||||||
|
node.setListening(false);
|
||||||
|
|
||||||
// execute dragstart events if defined
|
// execute dragstart events if defined
|
||||||
dd.node._handleEvent('dragstart', evt);
|
node._handleEvent('dragstart', evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute user defined ondragmove if defined
|
// execute user defined ondragmove if defined
|
||||||
dd.node._handleEvent('dragmove', evt);
|
node._handleEvent('dragmove', evt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Kinetic.DD._endDrag = function(evt) {
|
Kinetic.DD._endDrag = function(evt) {
|
||||||
var dd = Kinetic.DD;
|
var dd = Kinetic.DD;
|
||||||
var node = dd.node;
|
var node = dd.node;
|
||||||
if(node) {
|
if(node) {
|
||||||
|
node.setListening(true);
|
||||||
if(node.nodeType === 'Stage') {
|
if(node.nodeType === 'Stage') {
|
||||||
node.draw();
|
node.draw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ function test(condition, message, warn) {
|
|||||||
function log(message) {
|
function log(message) {
|
||||||
console.log('LOG: ' + message);
|
console.log('LOG: ' + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showBuffer(layer) {
|
||||||
|
document.body.appendChild(layer.bufferCanvas.element);
|
||||||
|
}
|
||||||
|
|
||||||
function Test() {
|
function Test() {
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
testCounter = document.createElement('div');
|
testCounter = document.createElement('div');
|
||||||
|
|||||||
@@ -712,7 +712,7 @@ Test.Modules.MANUAL = {
|
|||||||
layer.add(redCircle);
|
layer.add(redCircle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
},
|
},
|
||||||
'DRAG AND DROP - drag and drop elastic star with shadow': function(containerId) {
|
'*DRAG AND DROP - drag and drop elastic star with shadow': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
@@ -783,6 +783,8 @@ Test.Modules.MANUAL = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
showBuffer(layer);
|
||||||
},
|
},
|
||||||
'DRAG AND DROP - two draggable shapes': function(containerId) {
|
'DRAG AND DROP - two draggable shapes': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
@@ -828,54 +830,22 @@ Test.Modules.MANUAL = {
|
|||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
height: 200,
|
height: 200,
|
||||||
draggable: true,
|
draggable: true
|
||||||
//dragConstraint: 'horizontal',
|
|
||||||
/*
|
|
||||||
dragBounds: {
|
|
||||||
left: 100
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
});
|
|
||||||
var layer = new Kinetic.Layer({
|
|
||||||
/*
|
|
||||||
draggable: true,
|
|
||||||
dragBounds: {
|
|
||||||
left: 100
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
var Circle = new Kinetic.Circle({
|
var Circle = new Kinetic.Circle({
|
||||||
x: stage.getWidth() / 2,
|
x: stage.getWidth() / 2,
|
||||||
y: stage.getHeight() / 2,
|
y: stage.getHeight() / 2,
|
||||||
radius: 70,
|
radius: 70,
|
||||||
fill: 'red',
|
fill: 'red',
|
||||||
stroke: 'black',
|
stroke: 'black',
|
||||||
strokeWidth: 4,
|
strokeWidth: 4
|
||||||
//draggable: true,
|
|
||||||
/*
|
|
||||||
dragBounds: {
|
|
||||||
left: 100
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//stage.setDraggable(false);
|
|
||||||
//layer.setDraggable(false);
|
|
||||||
|
|
||||||
/*
|
|
||||||
stage.on('dragstart', function() {
|
|
||||||
console.log('dragstart');
|
|
||||||
});
|
|
||||||
stage.on('dragmove', function() {
|
|
||||||
//console.log('dragmove');
|
|
||||||
});
|
|
||||||
stage.on('dragend', function() {
|
|
||||||
console.log('dragend');
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
layer.add(Circle);
|
layer.add(Circle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
showBuffer(layer)
|
||||||
},
|
},
|
||||||
'DRAG AND DROP - draggable true false': function(containerId) {
|
'DRAG AND DROP - draggable true false': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
|||||||
@@ -60,6 +60,29 @@ Test.Modules.NODE = {
|
|||||||
rect2.setListening(true);
|
rect2.setListening(true);
|
||||||
test(rect2.getListening() === true, 'rect2 should be listening');
|
test(rect2.getListening() === true, 'rect2 should be listening');
|
||||||
},
|
},
|
||||||
|
'listen and don\'t listen with one shape': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
var rect = new Kinetic.Rect({
|
||||||
|
x: 50,
|
||||||
|
y: 50,
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
fill: 'blue'
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(rect);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
rect.setListening(false);
|
||||||
|
layer.drawBuffer();
|
||||||
|
|
||||||
|
showBuffer(layer);
|
||||||
|
},
|
||||||
'group to image': function(containerId) {
|
'group to image': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
|
|||||||
Reference in New Issue
Block a user