mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-20 09:41:45 +03:00
Multi-Touch MouseTracker Update
Pinch zoom update
This commit is contained in:
parent
38cae86659
commit
7aa0df1b66
@ -213,8 +213,11 @@
|
|||||||
penPoints: {},
|
penPoints: {},
|
||||||
penPointCount: 0,
|
penPointCount: 0,
|
||||||
// Tracking for pinch gesture
|
// Tracking for pinch gesture
|
||||||
|
pinchGesturePoints: [],
|
||||||
lastPinchDist: 0,
|
lastPinchDist: 0,
|
||||||
currentPinchDist: 0,
|
currentPinchDist: 0,
|
||||||
|
lastPinchCenter: null,
|
||||||
|
currentPinchCenter: null,
|
||||||
|
|
||||||
//insideElementPressed: false,
|
//insideElementPressed: false,
|
||||||
//insideElement: false,
|
//insideElement: false,
|
||||||
@ -853,6 +856,14 @@
|
|||||||
return point.minus( offset );
|
return point.minus( offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @inner
|
||||||
|
*/
|
||||||
|
function getCenterPoint( point1, point2 ) {
|
||||||
|
return new $.Point( ( point1.x + point2.x ) / 2, ( point1.y + point2.y ) / 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//*******************************************************************************************************************************************
|
//*******************************************************************************************************************************************
|
||||||
//** DOM EVent Handlers
|
//** DOM EVent Handlers
|
||||||
@ -1931,8 +1942,7 @@
|
|||||||
dispatchPress = false,
|
dispatchPress = false,
|
||||||
i,
|
i,
|
||||||
pointerCount = pointers.length,
|
pointerCount = pointers.length,
|
||||||
curPointer,
|
curPointer;
|
||||||
gesturePoints;
|
|
||||||
|
|
||||||
for ( i = 0; i < pointerCount; i++ ) {
|
for ( i = 0; i < pointerCount; i++ ) {
|
||||||
curPointer = pointers[ i ];
|
curPointer = pointers[ i ];
|
||||||
@ -1952,11 +1962,12 @@
|
|||||||
delegate.touchPointCount++;
|
delegate.touchPointCount++;
|
||||||
if ( delegate.touchPointCount == 2 && tracker.pinchHandler ) {
|
if ( delegate.touchPointCount == 2 && tracker.pinchHandler ) {
|
||||||
// Initialize for pinch gesture tracking
|
// Initialize for pinch gesture tracking
|
||||||
gesturePoints = [];
|
delegate.pinchGesturePoints = [];
|
||||||
for ( var p in delegate.touchPoints ) {
|
for ( var p in delegate.touchPoints ) {
|
||||||
gesturePoints.push( delegate.touchPoints[ p ] );
|
delegate.pinchGesturePoints.push( delegate.touchPoints[ p ] );
|
||||||
}
|
}
|
||||||
delegate.lastPinchDist = delegate.currentPinchDist = gesturePoints[0].currentPos.distanceTo(gesturePoints[1].currentPos);
|
delegate.lastPinchDist = delegate.currentPinchDist = delegate.pinchGesturePoints[0].currentPos.distanceTo( delegate.pinchGesturePoints[1].currentPos );
|
||||||
|
delegate.lastPinchCenter = delegate.currentPinchCenter = getCenterPoint( delegate.pinchGesturePoints[0].currentPos, delegate.pinchGesturePoints[1].currentPos );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2124,8 +2135,7 @@
|
|||||||
points,
|
points,
|
||||||
pointCount,
|
pointCount,
|
||||||
delta,
|
delta,
|
||||||
propagate,
|
propagate;
|
||||||
gesturePoints;
|
|
||||||
|
|
||||||
if ( pointers[ 0 ].type === 'mouse' ) {
|
if ( pointers[ 0 ].type === 'mouse' ) {
|
||||||
points = delegate.mousePoints;
|
points = delegate.mousePoints;
|
||||||
@ -2199,20 +2209,23 @@
|
|||||||
|
|
||||||
// Pinch Gesture
|
// Pinch Gesture
|
||||||
if ( pointers[ 0 ].type === 'touch' && delegate.touchPointCount == 2 && tracker.pinchHandler ) {
|
if ( pointers[ 0 ].type === 'touch' && delegate.touchPointCount == 2 && tracker.pinchHandler ) {
|
||||||
gesturePoints = [];
|
//gesturePoints = [];
|
||||||
for ( var p in delegate.touchPoints ) {
|
//for ( var p in delegate.touchPoints ) {
|
||||||
gesturePoints.push( delegate.touchPoints[ p ] );
|
// gesturePoints.push( delegate.touchPoints[ p ] );
|
||||||
}
|
//}
|
||||||
delta = gesturePoints[0].currentPos.distanceTo( gesturePoints[1].currentPos );
|
delta = delegate.pinchGesturePoints[0].currentPos.distanceTo( delegate.pinchGesturePoints[1].currentPos );
|
||||||
if ( delta != delegate.currentPinchDist ) {
|
if ( delta != delegate.currentPinchDist ) {
|
||||||
|
//window.alert(delegate.pinchGesturePoints[0].currentPos.x + ',' + delegate.pinchGesturePoints[0].currentPos.y + '\n' + delegate.pinchGesturePoints[1].currentPos.x + ',' + delegate.pinchGesturePoints[1].currentPos.y);
|
||||||
delegate.lastPinchDist = delegate.currentPinchDist;
|
delegate.lastPinchDist = delegate.currentPinchDist;
|
||||||
delegate.currentPinchDist = delta;
|
delegate.currentPinchDist = delta;
|
||||||
|
delegate.lastPinchCenter = delegate.currentPinchCenter;
|
||||||
|
delegate.currentPinchCenter = getCenterPoint( delegate.pinchGesturePoints[0].currentPos, delegate.pinchGesturePoints[1].currentPos );
|
||||||
propagate = tracker.pinchHandler(
|
propagate = tracker.pinchHandler(
|
||||||
{
|
{
|
||||||
eventSource: tracker,
|
eventSource: tracker,
|
||||||
gesturePoints: gesturePoints,
|
gesturePoints: delegate.pinchGesturePoints,
|
||||||
center: getPointRelative( new $.Point( ( gesturePoints[0].currentPos.x + gesturePoints[1].currentPos.x ) / 2,
|
lastCenter: getPointRelative( delegate.lastPinchCenter ),
|
||||||
( gesturePoints[0].currentPos.y + gesturePoints[1].currentPos.y ) / 2 ) ),
|
center: getPointRelative( delegate.currentPinchCenter ),
|
||||||
lastDistance: delegate.lastPinchDist,
|
lastDistance: delegate.lastPinchDist,
|
||||||
currentDistance: delegate.currentPinchDist,
|
currentDistance: delegate.currentPinchDist,
|
||||||
originalEvent: event,
|
originalEvent: event,
|
||||||
|
@ -1851,20 +1851,22 @@ function onCanvasScroll( event ) {
|
|||||||
|
|
||||||
function onCanvasPinch(event) {
|
function onCanvasPinch(event) {
|
||||||
//{
|
//{
|
||||||
// eventSource: tracker,
|
// eventSource:
|
||||||
// gesturePoints: gesturePoints,
|
// gesturePoints:
|
||||||
// center: getPointRelative( new $.Point( ( gesturePoints[0].currentPos.x + gesturePoints[1].currentPos.x ) / 2,
|
// lastCenter:
|
||||||
// ( gesturePoints[0].currentPos.y + gesturePoints[1].currentPos.y ) / 2 ) ),
|
// center:
|
||||||
// lastDistance: delegate.lastPinchDist,
|
// lastDistance:
|
||||||
// currentDistance: delegate.currentPinchDist,
|
// currentDistance:
|
||||||
// originalEvent: event,
|
// originalEvent:
|
||||||
// preventDefaultAction: false,
|
// preventDefaultAction:
|
||||||
// userData: tracker.userData
|
// userData:
|
||||||
//}
|
//}
|
||||||
if (!event.preventDefaultAction && this.viewport) {
|
if (!event.preventDefaultAction && this.viewport) {
|
||||||
|
//window.alert(event.lastCenter.x + ',' + event.lastCenter.y + '\n' + event.center.x + ',' + event.center.y);
|
||||||
//TODO This is temporary for testing. Zoom should track pinch gesture one-to-one!
|
//TODO This is temporary for testing. Zoom should track pinch gesture one-to-one!
|
||||||
this.viewport.zoomBy( event.currentDistance / event.lastDistance,
|
this.viewport.zoomBy( event.currentDistance / event.lastDistance,
|
||||||
this.viewport.pointFromPixel( event.center, true ) );
|
this.viewport.pointFromPixel( event.center, true ) );
|
||||||
|
this.viewport.panBy( this.viewport.pointFromPixel( event.lastCenter, true ).minus( this.viewport.pointFromPixel( event.center, true ) ), false );
|
||||||
this.viewport.applyConstraints();
|
this.viewport.applyConstraints();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user