Simplify Raster#initialize, set _size in Raster#setCanvas and add todo.

This commit is contained in:
Jonathan Puckey 2011-02-24 14:15:30 +01:00
parent ff2ac484da
commit d37a794b64

View file

@ -6,15 +6,15 @@ Raster = Item.extend({
initialize: function(object) { initialize: function(object) {
var width, height; var width, height;
this.base(); this.base();
if (object instanceof Image) { if (object.getContext) {
this.canvas = object;
width = this.canvas.width;
height = this.canvas.height;
} else {
this._image = object; this._image = object;
// TODO: cross browser compatible? // TODO: cross browser compatible?
width = object.naturalWidth; width = object.naturalWidth;
height = object.naturalHeight; height = object.naturalHeight;
} else if (object.getContext) {
this.canvas = object;
width = this.canvas.width;
height = this.canvas.height;
} }
this._size = new Size(width, height); this._size = new Size(width, height);
this._bounds = new Rectangle(-width / 2, -height / 2, width, height); this._bounds = new Rectangle(-width / 2, -height / 2, width, height);
@ -142,6 +142,8 @@ Raster = Item.extend({
setCanvas: function(canvas) { setCanvas: function(canvas) {
if (this._canvas) if (this._canvas)
CanvasProvider.returnCanvas(this._canvas); CanvasProvider.returnCanvas(this._canvas);
// TODO: should the width / height of the bounds be reset too?
this._size = new Size(canvas.width, canvas.height);
this._image = null; this._image = null;
this._ctx = null; this._ctx = null;
this._canvas = canvas; this._canvas = canvas;