mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Define PlacedItem as base class for Raster and PlacedSymbol.
This commit is contained in:
parent
7211e68245
commit
1cd7165ea2
5 changed files with 47 additions and 26 deletions
38
src/item/PlacedItem.js
Normal file
38
src/item/PlacedItem.js
Normal file
|
@ -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();
|
||||
}
|
||||
});
|
|
@ -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(),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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',
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue