diff --git a/src/Shape.js b/src/Shape.js index 60ea36aa..711d052b 100644 --- a/src/Shape.js +++ b/src/Shape.js @@ -70,7 +70,7 @@ * @memberof Kinetic.Shape.prototype */ hasShadow: function() { - return !!(this.getShadowColor() || this.getShadowBlur() || this.getShadowOffsetX() || this.getShadowOffsetY()); + return (this.getShadowOpacity() !== 0 && !!(this.getShadowColor() || this.getShadowBlur() || this.getShadowOffsetX() || this.getShadowOffsetY())); }, /** * returns whether or not a fill is present diff --git a/tests/js/manualTests.js b/tests/js/manualTests.js index 003b620f..2eef884e 100644 --- a/tests/js/manualTests.js +++ b/tests/js/manualTests.js @@ -904,6 +904,33 @@ Test.Modules.EVENTS = { }; Test.Modules.DRAG_AND_DROP = { + '*drag and drop layer with offset': function(containerId) { + var stage = new Kinetic.Stage({ + container: containerId, + width: 578, + height: 200 + }); + var layer = new Kinetic.Layer({ + offset: [50, 50], + draggable: true + }); + + var star = new Kinetic.Star({ + x: 200, + y: 100, + numPoints: 5, + innerRadius: 40, + outerRadius: 70, + fill: 'green', + stroke: 'blue', + strokeWidth: 5, + lineJoin: "round" + }); + + layer.add(star); + stage.add(layer); + layer.draw(); + }, 'drag and drop elastic star with shadow': function(containerId) { var stage = new Kinetic.Stage({ container: containerId, @@ -942,7 +969,7 @@ Test.Modules.DRAG_AND_DROP = { showHit(layer); }, - '*two draggable shapes': function(containerId) { + 'two draggable shapes': function(containerId) { var stage = new Kinetic.Stage({ container: containerId, width: 578, diff --git a/tests/js/unit/shapeTests.js b/tests/js/unit/shapeTests.js index d363c512..7abb5b13 100644 --- a/tests/js/unit/shapeTests.js +++ b/tests/js/unit/shapeTests.js @@ -120,6 +120,42 @@ Test.Modules.SHAPE = { }) === false, '(303, 153) should not intersect the shape'); }, + 'test hasShadow() method': function(containerId) { + var stage = new Kinetic.Stage({ + container: containerId, + width: 578, + height: 200 + }); + var layer = new Kinetic.Layer(); + var shape = new Kinetic.Shape({ + drawFunc: function(canvas) { + var context = canvas.getContext(); + context.beginPath(); + context.moveTo(0, 0); + context.lineTo(100, 0); + context.lineTo(100, 100); + context.closePath(); + canvas.fillStroke(this); + }, + x: 10, + y: 10, + fill: 'green', + stroke: 'blue', + strokeWidth: 5, + shadowColor: 'black', + shadowOffset: 10, + shadowOpacity: 0 + }); + + layer.add(shape); + stage.add(layer); + + test(!shape.hasShadow(), 'shape should not have a shadow because opacity is 0'); + + shape.setShadowOpacity(0.5); + + test(shape.hasShadow(), 'shape should have a shadow because opacity is nonzero'); + }, 'custom shape with fill, stroke, and strokeWidth': function(containerId) { var stage = new Kinetic.Stage({ container: containerId, @@ -329,7 +365,7 @@ Test.Modules.SHAPE = { test(circle.getDashArrayEnabled() === true, 'dashArrayEnabled should be true'); circle.disableFill(); - + test(circle.getFillEnabled() === false, 'fillEnabled should be false'); test(circle.getStrokeEnabled() === true, 'strokeEnabled should be true'); test(circle.getShadowEnabled() === true, 'shadowEnabled should be true');