mirror of
https://github.com/konvajs/konva.git
synced 2026-01-18 19:51:21 +08:00
created a proper utility function that handles defaults. Integrating the ntew get() method fixes a shadowBlur issue. fixed #587
This commit is contained in:
@@ -455,20 +455,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
_applyShadow: function(shape) {
|
_applyShadow: function(shape) {
|
||||||
var context = this.context;
|
var context = this.context,
|
||||||
|
util, absOpacity, color, blur, offset, shadowOpacity;
|
||||||
|
|
||||||
if(shape.hasShadow() && shape.getShadowEnabled()) {
|
if(shape.hasShadow() && shape.getShadowEnabled()) {
|
||||||
var aa = shape.getAbsoluteOpacity();
|
util = Kinetic.Util;
|
||||||
// defaults
|
absOpacity = shape.getAbsoluteOpacity();
|
||||||
var color = shape.getShadowColor() || 'black';
|
color = util.get(shape.getShadowColor(), 'black');
|
||||||
var blur = shape.getShadowBlur() || 5;
|
blur = util.get(shape.getShadowBlur(), 5);
|
||||||
var offset = shape.getShadowOffset() || {
|
shadowOpacity = util.get(shape.getShadowOpacity(), 0);
|
||||||
|
offset = util.get(shape.getShadowOffset(), {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
};
|
});
|
||||||
|
|
||||||
if(shape.getShadowOpacity()) {
|
if(shadowOpacity) {
|
||||||
context.globalAlpha = shape.getShadowOpacity() * aa;
|
context.globalAlpha = shadowOpacity * absOpacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.shadowColor = color;
|
context.shadowColor = color;
|
||||||
context.shadowBlur = blur;
|
context.shadowBlur = blur;
|
||||||
context.shadowOffsetX = offset.x;
|
context.shadowOffsetX = offset.x;
|
||||||
|
|||||||
13
src/Util.js
13
src/Util.js
@@ -598,6 +598,19 @@
|
|||||||
}
|
}
|
||||||
return HASH + randColor;
|
return HASH + randColor;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* return value with default fallback
|
||||||
|
* @method
|
||||||
|
* @memberof Kinetic.Util.prototype
|
||||||
|
*/
|
||||||
|
get: function(val, def) {
|
||||||
|
if (val === undefined) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* get RGB components of a color
|
* get RGB components of a color
|
||||||
* @method
|
* @method
|
||||||
|
|||||||
9
tests/js/unit/utilTests.js
Normal file
9
tests/js/unit/utilTests.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Test.Modules.UTIL = {
|
||||||
|
'util get()': function(containerId) {
|
||||||
|
var get = Kinetic.Util.get;
|
||||||
|
|
||||||
|
test(get(1, 2) === 1, 'get() should return 1');
|
||||||
|
test(get(0, 2) === 0, 'get() should return 0');
|
||||||
|
test(get(undefined, {foo:'bar'}).foo === 'bar', 'get() should return bar');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user