mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
Made getAbsoluteOpacity work recursively. Also added support for stage opacity (included test).
This commit is contained in:
parent
759ec116ce
commit
73bf805483
11
dist/kinetic-core.js
vendored
11
dist/kinetic-core.js
vendored
@ -3,7 +3,7 @@
|
|||||||
* http://www.kineticjs.com/
|
* http://www.kineticjs.com/
|
||||||
* Copyright 2012, Eric Rowell
|
* Copyright 2012, Eric Rowell
|
||||||
* Licensed under the MIT or GPL Version 2 licenses.
|
* Licensed under the MIT or GPL Version 2 licenses.
|
||||||
* Date: Sep 26 2012
|
* Date: Oct 01 2012
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 - 2012 by Eric Rowell
|
* Copyright (C) 2011 - 2012 by Eric Rowell
|
||||||
*
|
*
|
||||||
@ -1742,12 +1742,9 @@ Kinetic.Node.prototype = {
|
|||||||
* @methodOf Kinetic.Node.prototype
|
* @methodOf Kinetic.Node.prototype
|
||||||
*/
|
*/
|
||||||
getAbsoluteOpacity: function() {
|
getAbsoluteOpacity: function() {
|
||||||
var absOpacity = 1;
|
var absOpacity = this.getOpacity();
|
||||||
var node = this;
|
if (this.getParent()) {
|
||||||
// traverse upwards
|
absOpacity *= this.getParent().getAbsoluteOpacity();
|
||||||
while(node.nodeType !== 'Stage') {
|
|
||||||
absOpacity *= node.attrs.opacity;
|
|
||||||
node = node.parent;
|
|
||||||
}
|
}
|
||||||
return absOpacity;
|
return absOpacity;
|
||||||
},
|
},
|
||||||
|
8
dist/kinetic-core.min.js
vendored
8
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -519,12 +519,9 @@ Kinetic.Node.prototype = {
|
|||||||
* @methodOf Kinetic.Node.prototype
|
* @methodOf Kinetic.Node.prototype
|
||||||
*/
|
*/
|
||||||
getAbsoluteOpacity: function() {
|
getAbsoluteOpacity: function() {
|
||||||
var absOpacity = 1;
|
var absOpacity = this.getOpacity();
|
||||||
var node = this;
|
if (this.getParent()) {
|
||||||
// traverse upwards
|
absOpacity *= this.getParent().getAbsoluteOpacity();
|
||||||
while(node.nodeType !== 'Stage') {
|
|
||||||
absOpacity *= node.attrs.opacity;
|
|
||||||
node = node.parent;
|
|
||||||
}
|
}
|
||||||
return absOpacity;
|
return absOpacity;
|
||||||
},
|
},
|
||||||
|
@ -696,6 +696,32 @@ Test.prototype.tests = {
|
|||||||
test(circle.getAbsoluteOpacity() === 0.25, 'abs opacity should be 0.25');
|
test(circle.getAbsoluteOpacity() === 0.25, 'abs opacity should be 0.25');
|
||||||
test(layer.getAbsoluteOpacity() === 0.5, 'abs opacity should be 0.5');
|
test(layer.getAbsoluteOpacity() === 0.5, 'abs opacity should be 0.5');
|
||||||
},
|
},
|
||||||
|
'STAGE - set shape, layer and stage opacity to 0.5': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
var circle = new Kinetic.Circle({
|
||||||
|
x: stage.getWidth() / 2,
|
||||||
|
y: stage.getHeight() / 2,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4
|
||||||
|
});
|
||||||
|
|
||||||
|
circle.setOpacity(0.5);
|
||||||
|
layer.setOpacity(0.5);
|
||||||
|
stage.setOpacity(0.5);
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(circle.getAbsoluteOpacity() === 0.125, 'abs opacity should be 0.125');
|
||||||
|
test(layer.getAbsoluteOpacity() === 0.25, 'abs opacity should be 0.25');
|
||||||
|
test(stage.getAbsoluteOpacity() === 0.5, 'abs opacity should be 0.5');
|
||||||
|
},
|
||||||
'STAGE - remove shape without adding its parent to stage': function(containerId) {
|
'STAGE - remove shape without adding its parent to stage': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
|
Loading…
Reference in New Issue
Block a user