mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Add comments and clean up code.
This commit is contained in:
parent
427cc21b3a
commit
b9f6c99dcd
3 changed files with 2 additions and 9 deletions
|
@ -1817,7 +1817,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
draw: function(item, ctx, param) {
|
draw: function(item, ctx, param) {
|
||||||
if (!item._visible || item._opacity == 0)
|
if (!item._visible || item._opacity == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var tempCanvas, parentCtx;
|
var tempCanvas, parentCtx;
|
||||||
// If the item has a blendMode or is defining an opacity, draw it on
|
// If the item has a blendMode or is defining an opacity, draw it on
|
||||||
// a temporary canvas first and composite the canvas afterwards.
|
// a temporary canvas first and composite the canvas afterwards.
|
||||||
|
@ -1832,21 +1831,17 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
var bounds = item.getStrokeBounds() || item.getBounds();
|
var bounds = item.getStrokeBounds() || item.getBounds();
|
||||||
if (!bounds.width || !bounds.height)
|
if (!bounds.width || !bounds.height)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Floor the offset and ceil the size, so we don't cut off any
|
// Floor the offset and ceil the size, so we don't cut off any
|
||||||
// antialiased pixels when drawing onto the temporary canvas.
|
// antialiased pixels when drawing onto the temporary canvas.
|
||||||
var itemOffset = bounds.getTopLeft().floor(),
|
var itemOffset = bounds.getTopLeft().floor(),
|
||||||
size = bounds.getSize().ceil().add(new Size(1, 1));
|
size = bounds.getSize().ceil().add(new Size(1, 1));
|
||||||
tempCanvas = CanvasProvider.getCanvas(size);
|
tempCanvas = CanvasProvider.getCanvas(size);
|
||||||
|
|
||||||
// Save the parent context, so we can draw onto it later
|
// Save the parent context, so we can draw onto it later
|
||||||
parentCtx = ctx;
|
parentCtx = ctx;
|
||||||
|
|
||||||
// Set ctx to the context of the temporary canvas,
|
// Set ctx to the context of the temporary canvas,
|
||||||
// so we draw onto it, instead of the parentCtx
|
// so we draw onto it, instead of the parentCtx
|
||||||
ctx = tempCanvas.getContext('2d');
|
ctx = tempCanvas.getContext('2d');
|
||||||
ctx.save();
|
ctx.save();
|
||||||
|
|
||||||
// Translate the context so the topLeft of the item is at (0, 0)
|
// Translate the context so the topLeft of the item is at (0, 0)
|
||||||
// on the temporary canvas.
|
// on the temporary canvas.
|
||||||
ctx.translate(-itemOffset.x, -itemOffset.y);
|
ctx.translate(-itemOffset.x, -itemOffset.y);
|
||||||
|
@ -1859,15 +1854,12 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
item.draw(ctx, param);
|
item.draw(ctx, param);
|
||||||
if (itemOffset)
|
if (itemOffset)
|
||||||
param.offset = savedOffset;
|
param.offset = savedOffset;
|
||||||
|
|
||||||
// If we created a temporary canvas before, composite it onto the
|
// If we created a temporary canvas before, composite it onto the
|
||||||
// parent canvas:
|
// parent canvas:
|
||||||
if (tempCanvas) {
|
if (tempCanvas) {
|
||||||
|
|
||||||
// Restore the temporary canvas to its state before the
|
// Restore the temporary canvas to its state before the
|
||||||
// translation matrix was applied above.
|
// translation matrix was applied above.
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
|
||||||
// If the item has a blendMode, use BlendMode#process to
|
// If the item has a blendMode, use BlendMode#process to
|
||||||
// composite its canvas on the parentCanvas.
|
// composite its canvas on the parentCanvas.
|
||||||
if (item._blendMode !== 'normal') {
|
if (item._blendMode !== 'normal') {
|
||||||
|
@ -1885,7 +1877,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
itemOffset.x, itemOffset.y);
|
itemOffset.x, itemOffset.y);
|
||||||
parentCtx.restore();
|
parentCtx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the temporary canvas, so it can be reused
|
// Return the temporary canvas, so it can be reused
|
||||||
CanvasProvider.returnCanvas(tempCanvas);
|
CanvasProvider.returnCanvas(tempCanvas);
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,6 +215,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
}
|
}
|
||||||
var fillColor = this.getFillColor(),
|
var fillColor = this.getFillColor(),
|
||||||
strokeColor = this.getStrokeColor();
|
strokeColor = this.getStrokeColor();
|
||||||
|
// Try calling transform on colors in case they are GradientColors.
|
||||||
if (fillColor && fillColor.transform)
|
if (fillColor && fillColor.transform)
|
||||||
fillColor.transform(matrix);
|
fillColor.transform(matrix);
|
||||||
if (strokeColor && strokeColor.transform)
|
if (strokeColor && strokeColor.transform)
|
||||||
|
|
|
@ -89,6 +89,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
||||||
called = false;
|
called = false;
|
||||||
while (item) {
|
while (item) {
|
||||||
if (item.responds(type)) {
|
if (item.responds(type)) {
|
||||||
|
// Create an reuse the event object if we're bubbling
|
||||||
if (!mouseEvent)
|
if (!mouseEvent)
|
||||||
mouseEvent = new MouseEvent(type, event, point, target,
|
mouseEvent = new MouseEvent(type, event, point, target,
|
||||||
// Calculate delta if lastPoint was passed
|
// Calculate delta if lastPoint was passed
|
||||||
|
|
Loading…
Reference in a new issue