From 3975a275f9173e958d4f249d93eaf65592b64b1d Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 6 Jan 2014 17:35:03 -0800 Subject: [PATCH] add center location to events --- src/pinch.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pinch.js b/src/pinch.js index 0727c67..3d26716 100644 --- a/src/pinch.js +++ b/src/pinch.js @@ -47,17 +47,21 @@ pointercancel: function(ev) { this.pointerup(ev); }, - dispatchPinch: function(diameter, target) { + dispatchPinch: function(diameter, points) { var zoom = diameter / this.reference.diameter; var ev = dispatcher.makeEvent('pinch', { - scale: zoom + scale: zoom, + centerX: points.center.x, + centerY: points.center.y }); dispatcher.dispatchEvent(ev, this.reference.target); }, - dispatchRotate: function(angle) { + dispatchRotate: function(angle, points) { var diff = Math.round((angle - this.reference.angle) % 360); var ev = dispatcher.makeEvent('rotate', { - angle: diff + angle: diff, + centerX: points.center.x, + centerY: points.center.y }); dispatcher.dispatchEvent(ev, this.reference.target); }, @@ -66,10 +70,10 @@ var diameter = points.diameter; var angle = this.calcAngle(points); if (diameter != this.reference.diameter) { - this.dispatchPinch(diameter); + this.dispatchPinch(diameter, points); } if (angle != this.reference.angle) { - this.dispatchRotate(angle); + this.dispatchRotate(angle, points); } }, calcChord: function() { @@ -93,8 +97,8 @@ } } } - x = Math.abs(points.a.clientX - points.b.clientX / 2); - y = Math.abs(points.a.clientY - points.b.clientY / 2); + x = Math.abs(points.a.clientX + points.b.clientX) / 2; + y = Math.abs(points.a.clientY + points.b.clientY) / 2; points.center = { x: x, y: y }; points.diameter = dist; return points;