mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
pull request #109 opacity can now be applied to the stage
This commit is contained in:
commit
6f230fc42b
12
dist/kinetic-core.js
vendored
12
dist/kinetic-core.js
vendored
@ -3,7 +3,7 @@
|
||||
* http://www.kineticjs.com/
|
||||
* Copyright 2012, Eric Rowell
|
||||
* Licensed under the MIT or GPL Version 2 licenses.
|
||||
* Date: Oct 05 2012
|
||||
* Date: Oct 06 2012
|
||||
*
|
||||
* Copyright (C) 2011 - 2012 by Eric Rowell
|
||||
*
|
||||
@ -1741,12 +1741,9 @@ Kinetic.Node.prototype = {
|
||||
* @methodOf Kinetic.Node.prototype
|
||||
*/
|
||||
getAbsoluteOpacity: function() {
|
||||
var absOpacity = 1;
|
||||
var node = this;
|
||||
// traverse upwards
|
||||
while(node.nodeType !== 'Stage') {
|
||||
absOpacity *= node.attrs.opacity;
|
||||
node = node.parent;
|
||||
var absOpacity = this.getOpacity();
|
||||
if (this.getParent()) {
|
||||
absOpacity *= this.getParent().getAbsoluteOpacity();
|
||||
}
|
||||
return absOpacity;
|
||||
},
|
||||
@ -2491,6 +2488,7 @@ Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
|
||||
* @name getListening
|
||||
* @methodOf Kinetic.Node.prototype
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// 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
11
src/Node.js
11
src/Node.js
@ -518,12 +518,9 @@ Kinetic.Node.prototype = {
|
||||
* @methodOf Kinetic.Node.prototype
|
||||
*/
|
||||
getAbsoluteOpacity: function() {
|
||||
var absOpacity = 1;
|
||||
var node = this;
|
||||
// traverse upwards
|
||||
while(node.nodeType !== 'Stage') {
|
||||
absOpacity *= node.attrs.opacity;
|
||||
node = node.parent;
|
||||
var absOpacity = this.getOpacity();
|
||||
if (this.getParent()) {
|
||||
absOpacity *= this.getParent().getAbsoluteOpacity();
|
||||
}
|
||||
return absOpacity;
|
||||
},
|
||||
@ -1267,4 +1264,4 @@ Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
|
||||
* determine if listening to events or not
|
||||
* @name getListening
|
||||
* @methodOf Kinetic.Node.prototype
|
||||
*/
|
||||
*/
|
||||
|
@ -696,6 +696,32 @@ Test.prototype.tests = {
|
||||
test(circle.getAbsoluteOpacity() === 0.25, 'abs opacity should be 0.25');
|
||||
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) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
|
Loading…
Reference in New Issue
Block a user