From d37a794b646bfe729d3e5fbde72b39f96d94e4fa Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Thu, 24 Feb 2011 14:15:30 +0100 Subject: [PATCH] Simplify Raster#initialize, set _size in Raster#setCanvas and add todo. --- src/item/Raster.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/item/Raster.js b/src/item/Raster.js index 9607050f..f66468ca 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -6,15 +6,15 @@ Raster = Item.extend({ initialize: function(object) { var width, height; this.base(); - if (object instanceof Image) { + if (object.getContext) { + this.canvas = object; + width = this.canvas.width; + height = this.canvas.height; + } else { this._image = object; // TODO: cross browser compatible? width = object.naturalWidth; 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._bounds = new Rectangle(-width / 2, -height / 2, width, height); @@ -142,6 +142,8 @@ Raster = Item.extend({ setCanvas: function(canvas) { if (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._ctx = null; this._canvas = canvas;