mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Move PlacedItem#_hitTest() to PlacedSymbol#_hitTest() since it was written for symbols, and remove PlacedItem as it's an empty class now.
This commit is contained in:
parent
8fc2a69136
commit
9cc0822477
6 changed files with 20 additions and 44 deletions
|
@ -854,7 +854,7 @@ var Item = this.Item = Base.extend(Callback, {
|
|||
_getBounds: function(getter, matrix, cacheItem) {
|
||||
// Note: We cannot cache these results here, since we do not get
|
||||
// _changed() notifications here for changing geometry in children.
|
||||
// But cacheName is used in sub-classes such as PlacedItem.
|
||||
// But cacheName is used in sub-classes such as PlacedSymbol and Raster.
|
||||
var children = this._children;
|
||||
// TODO: What to return if nothing is defined, e.g. empty Groups?
|
||||
// Scriptographer behaves weirdly then too.
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
* 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# */{
|
||||
// PlacedItem uses strokeBounds for bounds
|
||||
_boundsGetter: { getBounds: 'getStrokeBounds' },
|
||||
|
||||
_hitTest: function(point, options, matrix) {
|
||||
var result = this._symbol._definition._hitTest(point, options, matrix);
|
||||
// TODO: When the symbol's definition is a path, should hitResult
|
||||
// contain information like HitResult#curve?
|
||||
if (result)
|
||||
result.item = this;
|
||||
return result;
|
||||
}
|
||||
});
|
|
@ -16,10 +16,12 @@
|
|||
* @class A PlacedSymbol represents an instance of a symbol which has been
|
||||
* placed in a Paper.js project.
|
||||
*
|
||||
* @extends PlacedItem
|
||||
* @extends Item
|
||||
*/
|
||||
var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{
|
||||
var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
|
||||
_class: 'PlacedSymbol',
|
||||
// PlacedSymbol uses strokeBounds for bounds
|
||||
_boundsGetter: { getBounds: 'getStrokeBounds' },
|
||||
_boundsSelected: true,
|
||||
_serializeFields: {
|
||||
symbol: null
|
||||
|
@ -110,6 +112,15 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
|||
return this.symbol._definition._getCachedBounds(getter, matrix);
|
||||
},
|
||||
|
||||
_hitTest: function(point, options, matrix) {
|
||||
var result = this._symbol._definition._hitTest(point, options, matrix);
|
||||
// TODO: When the symbol's definition is a path, should hitResult
|
||||
// contain information like HitResult#curve?
|
||||
if (result)
|
||||
result.item = this;
|
||||
return result;
|
||||
},
|
||||
|
||||
_draw: function(ctx, param) {
|
||||
this.symbol._definition.draw(ctx, param);
|
||||
}
|
||||
|
|
|
@ -15,17 +15,17 @@
|
|||
*
|
||||
* @class The Raster item represents an image in a Paper.js project.
|
||||
*
|
||||
* @extends PlacedItem
|
||||
* @extends Item
|
||||
*/
|
||||
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||
var Raster = this.Raster = Item.extend(/** @lends Raster# */{
|
||||
_class: 'Raster',
|
||||
// Raster doesn't make the distinction between the different bounds,
|
||||
// so use the same name for all of them
|
||||
_boundsGetter: 'getBounds',
|
||||
_boundsSelected: true,
|
||||
_serializeFields: {
|
||||
source: null
|
||||
},
|
||||
// Raster doesn't make the distinction between the different bounds,
|
||||
// so use the same name for all of them
|
||||
_boundsGetter: 'getBounds',
|
||||
|
||||
// TODO: Implement type, width, height.
|
||||
// TODO: Have PlacedSymbol & Raster inherit from a shared class?
|
||||
|
|
|
@ -62,7 +62,6 @@ 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');
|
||||
/*#*/ include('item/HitResult.js');
|
||||
|
|
|
@ -95,7 +95,7 @@ var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
|
|||
* @param {ChangeFlag} flags describes what exactly has changed.
|
||||
*/
|
||||
_changed: function(flags) {
|
||||
// Notify all PlacedItems of the change in our definition, so they
|
||||
// Notify all PlacedSymbols of the change in our definition, so they
|
||||
// can clear cached bounds.
|
||||
Base.each(this._instances, function(item) {
|
||||
item._changed(flags);
|
||||
|
|
Loading…
Reference in a new issue