Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
add center location to events
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Jan 7, 2014
1 parent e3d6132 commit 3975a27
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/pinch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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() {
Expand All @@ -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;
Expand Down

0 comments on commit 3975a27

Please sign in to comment.