mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Move logic that determines if item can be directly composited into separate per-item #_canComposite() method.
This commit is contained in:
parent
9c3a4acabd
commit
719b9d5e24
4 changed files with 22 additions and 7 deletions
|
@ -2892,13 +2892,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// Determine if we can draw directly, or if we need to draw into a
|
||||
// separate canvas and then composite onto the main canvas.
|
||||
direct = blendMode === 'normal' && opacity === 1
|
||||
// If blending natively is possible, see if the type of item
|
||||
// and its color settings allow it. A path with only a fill
|
||||
// or a stroke can be directly blended, but if it has both,
|
||||
// it needs to be drawn into a separate canvas first.
|
||||
|| (nativeBlend || opacity < 1) && (type === 'raster'
|
||||
|| (type === 'path' || type === 'compound-path')
|
||||
&& !(this.hasFill() && this.hasStroke())),
|
||||
// If native blending is possible, see if the item allows it
|
||||
|| (nativeBlend || opacity < 1) && this._canComposite(),
|
||||
mainCtx, itemOffset, prevOffset;
|
||||
if (!direct) {
|
||||
// Apply the paren't global matrix to the calculation of correct
|
||||
|
@ -2954,6 +2949,10 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// Restore previous offset.
|
||||
param.offset = prevOffset;
|
||||
}
|
||||
},
|
||||
|
||||
_canComposite: function() {
|
||||
return false;
|
||||
}
|
||||
}, Base.each(['down', 'drag', 'up', 'move'], function(name) {
|
||||
this['removeOn' + Base.capitalize(name)] = function() {
|
||||
|
|
|
@ -561,5 +561,9 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
ctx.drawImage(element,
|
||||
-this._size.width / 2, -this._size.height / 2);
|
||||
}
|
||||
},
|
||||
|
||||
_canComposite: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -67,6 +67,12 @@ var Shape = Item.extend(/** @lends Shape# */{
|
|||
}
|
||||
},
|
||||
|
||||
_canComposite: function() {
|
||||
// A path with only a fill or a stroke can be directly blended, but if
|
||||
// it has both, it needs to be drawn into a separate canvas first.
|
||||
return !(this.hasFill() && this.hasStroke());
|
||||
},
|
||||
|
||||
_getBounds: function(getter, matrix) {
|
||||
var rect = new Rectangle(this._size).setCenter(0, 0);
|
||||
if (getter !== 'getBounds' && this.hasStroke())
|
||||
|
|
|
@ -176,6 +176,12 @@ var PathItem = Item.extend(/** @lends PathItem# */{
|
|||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_canComposite: function() {
|
||||
// A path with only a fill or a stroke can be directly blended, but if
|
||||
// it has both, it needs to be drawn into a separate canvas first.
|
||||
return !(this.hasFill() && this.hasStroke());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue