{
namespace Internal
{
-namespace
-{
-// TODO: Set these according to DPI
-constexpr float MAXIMUM_MOTION_ALLOWED = 20.0f;
-} // unnamed namespace
-TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime)
+TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request, uint32_t maximumAllowedTime, uint32_t recognizerTime, float maximumMotionAllowedDistance)
: GestureRecognizer(screenSize, GestureType::TAP),
mObserver(observer),
mState(CLEAR),
mLastTapTime(0u),
mDeltaBetweenTouchDownTouchUp(0u),
mMaximumAllowedTime(maximumAllowedTime),
- mRecognizerTime(recognizerTime)
+ mRecognizerTime(recognizerTime),
+ mMaximumMotionAllowedDistance(maximumMotionAllowedDistance)
{
}
mDeltaBetweenTouchDownTouchUp = event.time - mTouchTime;
if(mDeltaBetweenTouchDownTouchUp < mRecognizerTime)
{
- EmitGesture(GestureState::STARTED, event.time);
+ const Vector2& screen(point.GetScreenPosition());
+ Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
+ std::abs(mTouchPosition.y - screen.y));
+ if(distanceDelta.x > mMaximumMotionAllowedDistance ||
+ distanceDelta.y > mMaximumMotionAllowedDistance)
+ {
+ mState = CLEAR;
+ DALI_LOG_RELEASE_INFO("There is a long distance between touch down and touch up. (%f or %f > %f)\n", distanceDelta.x, distanceDelta.y, mMaximumMotionAllowedDistance);
+ }
+ else
+ {
+ EmitGesture(GestureState::STARTED, event.time);
+ }
}
else // Clear if the time between touch down and touch up is long.
{
uint32_t timeDelta = event.time - mLastTapTime;
mTouchTime = event.time;
- if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
- distanceDelta.y > MAXIMUM_MOTION_ALLOWED ||
+ if(distanceDelta.x > mMaximumMotionAllowedDistance ||
+ distanceDelta.y > mMaximumMotionAllowedDistance ||
timeDelta > mMaximumAllowedTime) // If the time between tabs is long, it starts over from SetupForTouchDown.
{
SetupForTouchDown(event, point);
mRecognizerTime = time;
}
+void TapGestureRecognizer::SetMaximumMotionAllowedDistance(float distance)
+{
+ mMaximumMotionAllowedDistance = distance;
+}
+
void TapGestureRecognizer::EmitGesture(GestureState state, uint32_t time)
{
TapGestureEvent event(state);
Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
std::abs(mTouchPosition.y - screen.y));
- if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
- distanceDelta.y > MAXIMUM_MOTION_ALLOWED)
+ if(distanceDelta.x > mMaximumMotionAllowedDistance ||
+ distanceDelta.y > mMaximumMotionAllowedDistance)
{
event.state = GestureState::CANCELLED;
}