mirror of
https://github.com/scratchfoundation/Gestouch.git
synced 2025-02-16 23:40:14 -05:00
Fixed several things related to Gesture#centralPoint (affected DragGesture)
This commit is contained in:
parent
151d0ddca6
commit
ad8b5a2ecd
7 changed files with 72 additions and 21 deletions
|
@ -147,7 +147,7 @@ package org.gestouch.gestures
|
|||
_thresholdTimer.reset();
|
||||
_thresholdTimer.delay = timeThreshold;
|
||||
_thresholdTimer.start();
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
}
|
||||
|
||||
_minTouchPointsCountReached = true;
|
||||
|
@ -155,7 +155,7 @@ package org.gestouch.gestures
|
|||
if (moveThreshold > 0)
|
||||
{
|
||||
// calculate central point for future moveThreshold comparsion
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
// save points for later comparsion with moveThreshold
|
||||
_prevCentralPoint = _lastCentralPoint;
|
||||
_lastCentralPoint = _centralPoint.clone();
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
package org.gestouch.gestures
|
||||
{
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.InteractiveObject;
|
||||
import flash.events.GesturePhase;
|
||||
import flash.events.TouchEvent;
|
||||
import org.gestouch.core.GesturesManager;
|
||||
import org.gestouch.core.TouchPoint;
|
||||
import org.gestouch.core.gestouch_internal;
|
||||
import org.gestouch.events.DragGestureEvent;
|
||||
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.InteractiveObject;
|
||||
import flash.events.GesturePhase;
|
||||
import flash.events.TouchEvent;
|
||||
import flash.geom.Point;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -95,7 +97,7 @@ package org.gestouch.gestures
|
|||
|
||||
if (_trackingPointsCount > 1)
|
||||
{
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
_centralPoint.lastMove.x = _centralPoint.lastMove.y = 0;
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +111,7 @@ package org.gestouch.gestures
|
|||
return;
|
||||
}
|
||||
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
|
||||
if (!_slopPassed)
|
||||
{
|
||||
|
@ -117,8 +119,27 @@ package org.gestouch.gestures
|
|||
|
||||
if (_slopPassed)
|
||||
{
|
||||
_centralPoint.lastMove.x = _centralPoint.lastMove.y = 0;
|
||||
_dispatch(new DragGestureEvent(DragGestureEvent.GESTURE_DRAG, true, false, GesturePhase.BEGIN, _lastLocalCentralPoint.x, _lastLocalCentralPoint.y));
|
||||
var slopVector:Point = slop > 0 ? null : new Point();
|
||||
if (!slopVector)
|
||||
{
|
||||
if (_canMoveHorizontally && _canMoveVertically)
|
||||
{
|
||||
slopVector = _centralPoint.moveOffset.clone();
|
||||
slopVector.normalize(slop);
|
||||
slopVector.x = Math.round(slopVector.x);
|
||||
slopVector.y = Math.round(slopVector.y);
|
||||
}
|
||||
else if (_canMoveVertically)
|
||||
{
|
||||
slopVector = new Point(0, _centralPoint.moveOffset.y >= slop ? slop : -slop);
|
||||
}
|
||||
else if (_canMoveHorizontally)
|
||||
{
|
||||
slopVector = new Point(_centralPoint.moveOffset.x >= slop ? slop : -slop, 0);
|
||||
}
|
||||
}
|
||||
_centralPoint.lastMove = _centralPoint.moveOffset.subtract(slopVector);
|
||||
_dispatch(new DragGestureEvent(DragGestureEvent.GESTURE_DRAG, true, false, GesturePhase.BEGIN, _lastLocalCentralPoint.x, _lastLocalCentralPoint.y, 1, 1, 0, _centralPoint.lastMove.x, _centralPoint.lastMove.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,8 +155,7 @@ package org.gestouch.gestures
|
|||
var ending:Boolean = (_trackingPointsCount == minTouchPointsCount);
|
||||
_forgetPoint(touchPoint);
|
||||
|
||||
_adjustCentralPoint();
|
||||
_centralPoint.lastMove.x = _centralPoint.lastMove.y = 0;
|
||||
_updateCentralPoint();
|
||||
|
||||
if (ending)
|
||||
{
|
||||
|
|
|
@ -434,6 +434,20 @@ _propertyNames.push("timeThreshold", "moveThreshold");
|
|||
_firstTouchPoint = touchPoint;
|
||||
_centralPoint = touchPoint.clone() as TouchPoint;
|
||||
}
|
||||
else if (_trackingPointsCount == minTouchPointsCount)
|
||||
{
|
||||
_updateCentralPoint();
|
||||
_centralPoint.touchBeginPos.x = _centralPoint.x;
|
||||
_centralPoint.touchBeginPos.y = _centralPoint.y;
|
||||
_centralPoint.moveOffset.x = 0;
|
||||
_centralPoint.moveOffset.y = 0;
|
||||
_centralPoint.lastMove.x = 0;
|
||||
_centralPoint.lastMove.y = 0;
|
||||
}
|
||||
else if (_trackingPointsCount > minTouchPointsCount)
|
||||
{
|
||||
_adjustCentralPoint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -451,11 +465,13 @@ _propertyNames.push("timeThreshold", "moveThreshold");
|
|||
delete _trackingPointsMap[touchPoint.id];
|
||||
_trackingPoints.splice(_trackingPoints.indexOf(touchPoint), 1);
|
||||
_trackingPointsCount--;
|
||||
|
||||
_adjustCentralPoint();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adjusts (recalculates) _centralPoint and all it's properties
|
||||
* Updates _centralPoint and all it's properties
|
||||
* (such as positions, offsets, velocity, etc...).
|
||||
* Also updates _lastLocalCentralPoint (used for dispatching events).
|
||||
*
|
||||
|
@ -463,7 +479,7 @@ _propertyNames.push("timeThreshold", "moveThreshold");
|
|||
* @see #_lastLocalCentralPoint
|
||||
* @see #trackingPoints
|
||||
*/
|
||||
protected function _adjustCentralPoint():void
|
||||
protected function _updateCentralPoint():void
|
||||
{
|
||||
var x:Number = 0;
|
||||
var y:Number = 0;
|
||||
|
@ -495,6 +511,21 @@ _propertyNames.push("timeThreshold", "moveThreshold");
|
|||
|
||||
_lastLocalCentralPoint = target.globalToLocal(_centralPoint);
|
||||
}
|
||||
|
||||
|
||||
protected function _adjustCentralPoint():void
|
||||
{
|
||||
var oldCentralPoint:TouchPoint = _centralPoint.clone() as TouchPoint;
|
||||
_updateCentralPoint();
|
||||
var centralPointChange:Point = _centralPoint.subtract(oldCentralPoint);
|
||||
_centralPoint.touchBeginPos = _centralPoint.touchBeginPos.add(centralPointChange);
|
||||
// fix moveOffset according to fixed touchBeginPos
|
||||
_centralPoint.moveOffset.x = _centralPoint.x - _centralPoint.touchBeginPos.x;
|
||||
_centralPoint.moveOffset.y = _centralPoint.y - _centralPoint.touchBeginPos.y;
|
||||
// restore original lastMove
|
||||
_centralPoint.lastMove.x = oldCentralPoint.lastMove.x;
|
||||
_centralPoint.lastMove.y = oldCentralPoint.lastMove.y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -133,7 +133,7 @@ package org.gestouch.gestures
|
|||
|
||||
if (held)
|
||||
{
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
_reset();
|
||||
_dispatch(new LongPressGestureEvent(LongPressGestureEvent.GESTURE_LONG_PRESS, true, false, GesturePhase.END, _lastLocalCentralPoint.x, _lastLocalCentralPoint.y));
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ package org.gestouch.gestures
|
|||
|
||||
protected function _onThresholdTimerComplete(event:TimerEvent):void
|
||||
{
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
_dispatch(new LongPressGestureEvent(LongPressGestureEvent.GESTURE_LONG_PRESS, true, false, GesturePhase.BEGIN, _lastLocalCentralPoint.x, _lastLocalCentralPoint.y));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ package org.gestouch.gestures
|
|||
_lastVector.x = _trackingPoints[1].x - _trackingPoints[0].x;
|
||||
_lastVector.y = _trackingPoints[1].y - _trackingPoints[0].y;
|
||||
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
|
||||
_dispatch(new RotateGestureEvent(RotateGestureEvent.GESTURE_ROTATE, true, false, GesturePhase.BEGIN, _lastLocalCentralPoint.x, _lastLocalCentralPoint.y));
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ package org.gestouch.gestures
|
|||
return;
|
||||
}
|
||||
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
|
||||
_currVector.x = _trackingPoints[1].x - _trackingPoints[0].x;
|
||||
_currVector.y = _trackingPoints[1].y - _trackingPoints[0].y;
|
||||
|
|
|
@ -113,7 +113,7 @@ package org.gestouch.gestures
|
|||
return;
|
||||
}
|
||||
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
|
||||
if (!_slopPassed)
|
||||
{
|
||||
|
|
|
@ -97,7 +97,7 @@ package org.gestouch.gestures
|
|||
_lastVector.x = _trackingPoints[1].x - _trackingPoints[0].x;
|
||||
_lastVector.y = _trackingPoints[1].y - _trackingPoints[0].y;
|
||||
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
|
||||
_dispatch(new ZoomGestureEvent(ZoomGestureEvent.GESTURE_ZOOM, true, false, GesturePhase.BEGIN, _lastLocalCentralPoint.x, _lastLocalCentralPoint.y));
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ package org.gestouch.gestures
|
|||
return;
|
||||
}
|
||||
|
||||
_adjustCentralPoint();
|
||||
_updateCentralPoint();
|
||||
|
||||
_currVector.x = _trackingPoints[1].x - _trackingPoints[0].x;
|
||||
_currVector.y = _trackingPoints[1].y - _trackingPoints[0].y;
|
||||
|
|
Loading…
Reference in a new issue