diff --git a/src/item/PlacedItem.js b/src/item/PlacedItem.js new file mode 100644 index 00000000..0cbe1d88 --- /dev/null +++ b/src/item/PlacedItem.js @@ -0,0 +1,38 @@ +/* + * Paper.js + * + * This file is part of Paper.js, a JavaScript Vector Graphics Library, + * based on Scriptographer.org and designed to be largely API compatible. + * http://paperjs.org/ + * http://scriptographer.org/ + * + * Distributed under the MIT license. See LICENSE file for details. + * + * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey + * http://lehni.org/ & http://jonathanpuckey.com/ + * + * All rights reserved. + */ + +/** + * @name PlacedItem + * + * @class The PlacedItem class is the base for any items that have a matrix + * associated with them, describing their placement in the project, such as + * {@link Raster} and {@link PlacedSymbol}. + * + * @extends Item + */ +var PlacedItem = this.PlacedItem = Item.extend(/** @lends PlacedItem# */{ + + _transform: function(matrix, flags) { + // In order to set the right context transformation when drawing the + // raster, simply preconcatenate the internal matrix with the provided + // one. + this.matrix.preConcatenate(matrix); + }, + + getStrokeBounds: function() { + return this.getBounds(); + } +}); diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index 4bf64811..83ee3589 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -20,9 +20,9 @@ * @class A PlacedSymbol represents an instance of a symbol which has been * placed in a Paper.js project. * - * @extends Item + * @extends PlacedItem */ -var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{ +var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{ /** * Creates a new PlacedSymbol Item. * @@ -82,13 +82,6 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{ return this._clone(new PlacedSymbol(this.symbol, this.matrix.clone())); }, - _transform: function(matrix, flags) { - // In order to set the right context transformation when drawing the - // raster, simply preconcatenate the internal matrix with the provided - // one. - this.matrix.preConcatenate(matrix); - }, - getBounds: function() { if (!this._bounds) this._bounds = this._createBounds( @@ -96,10 +89,6 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{ return this._bounds; }, - getStrokeBounds: function() { - return this.getBounds(); - }, - draw: function(ctx, param) { if (param.selection) { Item.drawSelectedBounds(this.symbol._definition.getStrokeBounds(), diff --git a/src/item/Raster.js b/src/item/Raster.js index 3d238f0c..2b3e8be8 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -16,10 +16,12 @@ /** * @name Raster + * * @class The Raster item represents an image in a Paper.js project. - * @extends Item + * + * @extends PlacedItem */ -var Raster = this.Raster = Item.extend(/** @lends Raster# */{ +var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ // TODO: Implement url / type, width, height. // TODO: Have PlacedSymbol & Raster inherit from a shared class? // DOCS: Document Raster constructor. @@ -341,6 +343,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{ return this.getContext().createImageData(size.width, size.height); }, + // TODO: Rename to #get/setImageData, as it will conflict with Item#getData // DOCS: document Raster#getData /** * @param {Rectangle} rect @@ -365,13 +368,6 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{ this.getContext(true).putImageData(data, point.x, point.y); }, - _transform: function(matrix, flags) { - // In order to set the right context transformation when drawing the - // raster, simply preconcatenate the internal matrix with the provided - // one. - this.matrix.preConcatenate(matrix); - }, - getBounds: function() { if (!this._bounds) this._bounds = this._createBounds(this.matrix._transformBounds( @@ -379,10 +375,6 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{ return this._bounds; }, - getStrokeBounds: function() { - return this.getBounds(); - }, - draw: function(ctx, param) { if (param.selection) { var bounds = new Rectangle(this._size).setCenter(0, 0); diff --git a/src/load.js b/src/load.js index ee1c9554..1f0d97ac 100644 --- a/src/load.js +++ b/src/load.js @@ -42,6 +42,7 @@ var sources = [ 'src/item/Item.js', 'src/item/Group.js', 'src/item/Layer.js', + 'src/item/PlacedItem.js', 'src/item/Raster.js', 'src/item/PlacedSymbol.js', diff --git a/src/paper.js b/src/paper.js index 4b3839bf..4e390ae7 100644 --- a/src/paper.js +++ b/src/paper.js @@ -64,6 +64,7 @@ var paper = new function() { //#include "item/Item.js" //#include "item/Group.js" //#include "item/Layer.js" +//#include "item/PlacedItem.js" //#include "item/Raster.js" //#include "item/PlacedSymbol.js"