mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Pass on the baseItem of a getBounds call, required to implement proper caching later.
This commit is contained in:
parent
8729e9919f
commit
a0ad81b576
5 changed files with 12 additions and 11 deletions
|
@ -1258,7 +1258,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* matrix concatenation and handles all the complicated caching mechanisms.
|
||||
* Note: Needs to be called on an item using getBounds.call(item, ...).
|
||||
*/
|
||||
function getBounds(type, matrix) {
|
||||
function getBounds(baseItem, type, matrix) {
|
||||
// If the result of concatinating the passed matrix with our internal
|
||||
// one is an identity transformation, set it to null for faster
|
||||
// processing
|
||||
|
@ -1273,7 +1273,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
var cache = !this._children && !matrix && type;
|
||||
if (cache && this._bounds && this._bounds[cache])
|
||||
return this._bounds[cache];
|
||||
var bounds = this._getBounds(type, matrix);
|
||||
var bounds = this._getBounds(baseItem, type, matrix);
|
||||
// If we're returning 'bounds', create a LinkedRectangle that uses
|
||||
// the setBounds() setter to update the Item whenever the bounds are
|
||||
// changed:
|
||||
|
@ -1297,7 +1297,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// overridden by subclasses, see below.
|
||||
this['get' + Base.capitalize(name)] = function(/* matrix */) {
|
||||
var type = this._boundsType;
|
||||
return getBounds.call(this,
|
||||
return getBounds.call(this, this,
|
||||
// Allow subclasses to override _boundsType if they use the
|
||||
// same calculations for multiple types.
|
||||
// The default is name:
|
||||
|
@ -1314,7 +1314,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* them. Subclasses override it to define calculations for the various
|
||||
* required bounding types.
|
||||
*/
|
||||
_getBounds: function(type, matrix) {
|
||||
_getBounds: function(baseItem, type, matrix) {
|
||||
// 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.
|
||||
|
@ -1330,7 +1330,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
for (var i = 0, l = children.length; i < l; i++) {
|
||||
var child = children[i];
|
||||
if (child._visible) {
|
||||
var rect = getBounds.call(child, type, matrix);
|
||||
var rect = getBounds.call(child, baseItem, type, matrix);
|
||||
x1 = Math.min(rect.x, x1);
|
||||
y1 = Math.min(rect.y, y1);
|
||||
x2 = Math.max(rect.x + rect.width, x2);
|
||||
|
|
|
@ -94,14 +94,15 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
|||
return this._clone(new PlacedSymbol(this.symbol, this._matrix.clone()));
|
||||
},
|
||||
|
||||
_getBounds: function(type, matrix) {
|
||||
_getBounds: function(baseItem, type, matrix) {
|
||||
// Redirect the call to the symbol definition to calculate the bounds
|
||||
return this.symbol._definition._getBounds(type, matrix);
|
||||
return this.symbol._definition._getBounds(baseItem, type, matrix);
|
||||
},
|
||||
|
||||
draw: function(ctx, param) {
|
||||
if (param.selection) {
|
||||
Item.drawSelectedBounds(this._getBounds('bounds'), ctx, this._matrix);
|
||||
Item.drawSelectedBounds(this._getBounds(this, 'bounds'), ctx,
|
||||
this._matrix);
|
||||
} else {
|
||||
ctx.save();
|
||||
this._matrix.applyToContext(ctx);
|
||||
|
|
|
@ -382,7 +382,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
|||
this.getContext(true).putImageData(data, point.x, point.y);
|
||||
},
|
||||
|
||||
_getBounds: function(type, matrix) {
|
||||
_getBounds: function(baseItem, type, matrix) {
|
||||
var rect = new Rectangle(this._size).setCenter(0, 0);
|
||||
return matrix ? matrix._transformBounds(rect) : rect;
|
||||
},
|
||||
|
|
|
@ -2060,7 +2060,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
};
|
||||
|
||||
return {
|
||||
_getBounds: function(type, matrix) {
|
||||
_getBounds: function(baseItem, type, matrix) {
|
||||
return get[type](this, matrix);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -98,7 +98,7 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
|
|||
var context = null;
|
||||
|
||||
return {
|
||||
_getBounds: function(type, matrix) {
|
||||
_getBounds: function(baseItem, type, matrix) {
|
||||
// If there is no text, there are no bounds
|
||||
if (!this._content)
|
||||
return new Rectangle();
|
||||
|
|
Loading…
Reference in a new issue