mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
pull request #109 opacity can now be applied to the stage
This commit is contained in:
12
dist/kinetic-core.js
vendored
12
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: Oct 05 2012
|
* Date: Oct 06 2012
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 - 2012 by Eric Rowell
|
* Copyright (C) 2011 - 2012 by Eric Rowell
|
||||||
*
|
*
|
||||||
@@ -1741,12 +1741,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;
|
||||||
},
|
},
|
||||||
@@ -2491,6 +2488,7 @@ Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
|
|||||||
* @name getListening
|
* @name getListening
|
||||||
* @methodOf Kinetic.Node.prototype
|
* @methodOf Kinetic.Node.prototype
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// Container
|
// Container
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
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
@@ -518,12 +518,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,
|
||||||
|
Reference in New Issue
Block a user