Add a layer to the document's children list when created and support activeLayer.

This commit is contained in:
Jonathan Puckey 2011-02-11 18:38:44 +01:00
parent c9c27f7be2
commit 31c51ea9eb

View file

@ -1,14 +1,19 @@
Doc = Base.extend({
initialize: function(canvas) {
this.canvas = canvas;
this.ctx = this.canvas.getContext('2d');
this.size = new Size(canvas.offsetWidth, canvas.offsetHeight);
this.children = [];
if(canvas) {
this.canvas = canvas;
this.ctx = this.canvas.getContext('2d');
this.size = new Size(canvas.offsetWidth, canvas.offsetHeight);
}
this.activeLayer = new Layer();
this.children = this.activeLayer;
},
redraw: function() {
this.ctx.clearRect(0, 0, this.size.width, this.size.height);
for(var i = 0, l = this.children.length; i < l; i++) {
this.children[i].draw(this.ctx);
if(this.canvas) {
this.ctx.clearRect(0, 0, this.size.width, this.size.height);
for(var i = 0, l = this.children.length; i < l; i++) {
this.children[i].draw(this.ctx);
}
}
}
});