mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Simplify Raster#initialize, set _size in Raster#setCanvas and add todo.
This commit is contained in:
parent
ff2ac484da
commit
d37a794b64
1 changed files with 7 additions and 5 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue