From b9f6c99dcdce6bd261501e7da40aa20c02520e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 17 Nov 2011 19:28:05 +0100 Subject: [PATCH] Add comments and clean up code. --- src/item/Item.js | 9 --------- src/path/Path.js | 1 + src/ui/CanvasView.js | 1 + 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index d816f209..ada49dad 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1817,7 +1817,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ draw: function(item, ctx, param) { if (!item._visible || item._opacity == 0) return; - var tempCanvas, parentCtx; // If the item has a blendMode or is defining an opacity, draw it on // 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(); if (!bounds.width || !bounds.height) return; - // Floor the offset and ceil the size, so we don't cut off any // antialiased pixels when drawing onto the temporary canvas. var itemOffset = bounds.getTopLeft().floor(), size = bounds.getSize().ceil().add(new Size(1, 1)); tempCanvas = CanvasProvider.getCanvas(size); - // Save the parent context, so we can draw onto it later parentCtx = ctx; - // Set ctx to the context of the temporary canvas, // so we draw onto it, instead of the parentCtx ctx = tempCanvas.getContext('2d'); ctx.save(); - // Translate the context so the topLeft of the item is at (0, 0) // on the temporary canvas. ctx.translate(-itemOffset.x, -itemOffset.y); @@ -1859,15 +1854,12 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ item.draw(ctx, param); if (itemOffset) param.offset = savedOffset; - // If we created a temporary canvas before, composite it onto the // parent canvas: if (tempCanvas) { - // Restore the temporary canvas to its state before the // translation matrix was applied above. ctx.restore(); - // If the item has a blendMode, use BlendMode#process to // composite its canvas on the parentCanvas. if (item._blendMode !== 'normal') { @@ -1885,7 +1877,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ itemOffset.x, itemOffset.y); parentCtx.restore(); } - // Return the temporary canvas, so it can be reused CanvasProvider.returnCanvas(tempCanvas); } diff --git a/src/path/Path.js b/src/path/Path.js index c1ec4bf4..9c38fe75 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -215,6 +215,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{ } var fillColor = this.getFillColor(), strokeColor = this.getStrokeColor(); + // Try calling transform on colors in case they are GradientColors. if (fillColor && fillColor.transform) fillColor.transform(matrix); if (strokeColor && strokeColor.transform) diff --git a/src/ui/CanvasView.js b/src/ui/CanvasView.js index 340cc1ff..9eae86a6 100644 --- a/src/ui/CanvasView.js +++ b/src/ui/CanvasView.js @@ -89,6 +89,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{ called = false; while (item) { if (item.responds(type)) { + // Create an reuse the event object if we're bubbling if (!mouseEvent) mouseEvent = new MouseEvent(type, event, point, target, // Calculate delta if lastPoint was passed