2012-03-07 13:45:48 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Layer
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* Layer constructor. Layers are tied to their own canvas element and are used
|
|
|
|
* to contain groups or shapes
|
|
|
|
* @constructor
|
|
|
|
* @augments Kinetic.Container
|
|
|
|
* @augments Kinetic.Node
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
|
|
|
Kinetic.Layer = function(config) {
|
2012-03-18 01:28:25 +08:00
|
|
|
this.className = 'Layer';
|
2012-03-07 13:45:48 +08:00
|
|
|
this.canvas = document.createElement('canvas');
|
|
|
|
this.context = this.canvas.getContext('2d');
|
|
|
|
this.canvas.style.position = 'absolute';
|
2012-03-13 13:41:09 +08:00
|
|
|
this.transitions = [];
|
|
|
|
this.transitionIdCounter = 0;
|
2012-03-19 10:50:20 +08:00
|
|
|
this.isTransitioning = false;
|
|
|
|
|
2012-03-07 13:45:48 +08:00
|
|
|
// call super constructors
|
|
|
|
Kinetic.Container.apply(this, []);
|
|
|
|
Kinetic.Node.apply(this, [config]);
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Layer methods
|
|
|
|
*/
|
|
|
|
Kinetic.Layer.prototype = {
|
|
|
|
/**
|
|
|
|
* public draw children
|
|
|
|
*/
|
|
|
|
draw: function() {
|
|
|
|
this._draw();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* clear layer
|
|
|
|
*/
|
|
|
|
clear: function() {
|
|
|
|
var context = this.getContext();
|
|
|
|
var canvas = this.getCanvas();
|
|
|
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get layer canvas
|
|
|
|
*/
|
|
|
|
getCanvas: function() {
|
|
|
|
return this.canvas;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get layer context
|
|
|
|
*/
|
|
|
|
getContext: function() {
|
|
|
|
return this.context;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* add node to layer
|
|
|
|
* @param {Node} node
|
|
|
|
*/
|
|
|
|
add: function(child) {
|
|
|
|
this._add(child);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* remove a child from the layer
|
|
|
|
* @param {Node} child
|
|
|
|
*/
|
|
|
|
remove: function(child) {
|
|
|
|
this._remove(child);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* private draw children
|
|
|
|
*/
|
|
|
|
_draw: function() {
|
|
|
|
this.clear();
|
|
|
|
if(this.visible) {
|
|
|
|
this._drawChildren();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Extend Container and Node
|
|
|
|
Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Container);
|
2012-03-13 13:41:09 +08:00
|
|
|
Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Node);
|