mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 02:37:59 +08:00
fixes #353
This commit is contained in:
34
src/Layer.js
34
src/Layer.js
@@ -45,25 +45,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
/**
|
drawScene: function(canvas) {
|
||||||
* set before draw handler
|
var layer = this.getLayer();
|
||||||
* @name beforeDraw
|
|
||||||
* @methodOf Kinetic.Layer.prototype
|
if(layer && layer.getClearBeforeDraw()) {
|
||||||
* @param {Function} handler
|
layer.getCanvas().clear();
|
||||||
*/
|
}
|
||||||
beforeDraw: function(func) {
|
|
||||||
this.beforeDrawFunc = func;
|
Kinetic.Container.prototype.drawScene.call(this, canvas);
|
||||||
return this;
|
|
||||||
},
|
},
|
||||||
/**
|
drawHit: function() {
|
||||||
* set after draw handler
|
var layer = this.getLayer();
|
||||||
* @name afterDraw
|
|
||||||
* @methodOf Kinetic.Layer.prototype
|
if(layer && layer.getClearBeforeDraw()) {
|
||||||
* @param {Function} handler
|
layer.getHitCanvas().clear();
|
||||||
*/
|
}
|
||||||
afterDraw: function(func) {
|
|
||||||
this.afterDrawFunc = func;
|
Kinetic.Container.prototype.drawHit.call(this);
|
||||||
return this;
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* get layer canvas
|
* get layer canvas
|
||||||
|
@@ -992,16 +992,10 @@
|
|||||||
* the scene renderer
|
* the scene renderer
|
||||||
*/
|
*/
|
||||||
draw: function() {
|
draw: function() {
|
||||||
var layer = this.getLayer(),
|
var evt = {
|
||||||
evt = {
|
|
||||||
node: this
|
node: this
|
||||||
};
|
};
|
||||||
|
|
||||||
if(layer && layer.getClearBeforeDraw()) {
|
|
||||||
layer.getCanvas().clear();
|
|
||||||
layer.getHitCanvas().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fire(BEFORE_DRAW, evt);
|
this.fire(BEFORE_DRAW, evt);
|
||||||
this.drawScene();
|
this.drawScene();
|
||||||
this.drawHit();
|
this.drawHit();
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -28,41 +28,39 @@ Test.Modules.LAYER = {
|
|||||||
test(style.padding === '0px', 'canvas padding style should be 0px');
|
test(style.padding === '0px', 'canvas padding style should be 0px');
|
||||||
test(style.backgroundColor === 'transparent', 'canvas backgroundColor style should be transparent');
|
test(style.backgroundColor === 'transparent', 'canvas backgroundColor style should be transparent');
|
||||||
},
|
},
|
||||||
'beforeDraw and afterDraw': function(containerId) {
|
'redraw hit graph': 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 rect = new Kinetic.Rect({
|
||||||
var circle = new Kinetic.Circle({
|
x: 200,
|
||||||
x: 100,
|
width: 100,
|
||||||
y: stage.getHeight() / 2,
|
height: 50,
|
||||||
radius: 70,
|
|
||||||
fill: 'green',
|
fill: 'green',
|
||||||
stroke: 'black',
|
stroke: 'black',
|
||||||
strokeWidth: 4
|
strokeWidth: 4,
|
||||||
|
scale: [3, 1],
|
||||||
|
draggable: true,
|
||||||
|
strokeScaleEnabled: false
|
||||||
});
|
});
|
||||||
|
|
||||||
layer.add(circle);
|
rect.colorKey = '000000';
|
||||||
|
|
||||||
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
var counter = 0;
|
rect.setY(100);
|
||||||
|
layer.drawHit();
|
||||||
|
|
||||||
layer.beforeDraw(function() {
|
showHit(layer);
|
||||||
counter++;
|
|
||||||
test(counter === 1, 'counter should be 1');
|
|
||||||
});
|
|
||||||
|
|
||||||
layer.afterDraw(function() {
|
testDataUrl(layer.hitCanvas.toDataURL(), 'black rect hit graph', 'redrawn hitgraph data url is incorrect');
|
||||||
counter++;
|
|
||||||
test(counter === 2, 'counter should be 2');
|
|
||||||
});
|
|
||||||
|
|
||||||
layer.draw();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'set clearBeforeDraw to false, and test toDataURL for stage, layer, group, and shape': function(containerId) {
|
'set clearBeforeDraw to false, and test toDataURL for stage, layer, group, and shape': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
|
@@ -26,6 +26,7 @@ Test.Modules.SHAPE = {
|
|||||||
|
|
||||||
testDataUrl(layer.toDataURL(), 'scaled rect with disabled stroke scale', 'probem with stroke scale disabling');
|
testDataUrl(layer.toDataURL(), 'scaled rect with disabled stroke scale', 'probem with stroke scale disabling');
|
||||||
},
|
},
|
||||||
|
|
||||||
'test intersects()': function(containerId) {
|
'test intersects()': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
|
Reference in New Issue
Block a user