mirror of
https://github.com/konvajs/konva.git
synced 2025-12-05 03:24:23 +08:00
checking in split files in preparation for new Ruby build
This commit is contained in:
78
src/Layer.js
Normal file
78
src/Layer.js
Normal file
@@ -0,0 +1,78 @@
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// 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) {
|
||||
this.className = "Layer";
|
||||
this.canvas = document.createElement('canvas');
|
||||
this.context = this.canvas.getContext('2d');
|
||||
this.canvas.style.position = 'absolute';
|
||||
|
||||
// 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);
|
||||
Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Node);
|
||||
Reference in New Issue
Block a user