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