/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/integration-api/events/touch-event-integ.h>
// INTERNAL INCLUDES
-#include <dali/internal/event/events/gesture-requests.h>
#include <dali/internal/event/common/scene-impl.h>
+#include <dali/internal/event/events/gesture-requests.h>
namespace Dali
{
-
namespace Internal
{
-
namespace
{
// TODO: Set these according to DPI
-const float MAXIMUM_MOTION_ALLOWED = 20.0f;
-const unsigned long MAXIMUM_TIME_ALLOWED = 500u;
+const float MAXIMUM_MOTION_ALLOWED = 20.0f;
+const unsigned long MAXIMUM_TIME_ALLOWED = 500u;
} // unnamed namespace
-TapGestureRecognizer::TapGestureRecognizer( Observer& observer, Vector2 screenSize, const TapGestureRequest& request)
-: GestureRecognizer( screenSize, Gesture::Tap ),
+TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request)
+: GestureRecognizer(screenSize, GestureType::TAP),
mObserver(observer),
- mState(Clear),
+ mState(CLEAR),
mMinimumTapsRequired(request.minTaps),
mMaximumTapsRequired(request.maxTaps),
mTapsRegistered(0),
mTouchPosition(),
mTouchTime(0u),
- mLastTapTime(0u)
+ mLastTapTime(0u),
+ mGestureSourceType(GestureSourceType::INVALID)
{
}
-TapGestureRecognizer::~TapGestureRecognizer()
-{
-}
+TapGestureRecognizer::~TapGestureRecognizer() = default;
void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
{
GestureRecognizerPtr ptr(this); // To keep us from being destroyed during the life-time of this method
- if (event.GetPointCount() == 1)
+ if(event.GetPointCount() == 1)
{
- const Integration::Point& point = event.points[0];
- PointState::Type pointState = point.GetState();
+ const Integration::Point& point = event.points[0];
+ PointState::Type pointState = point.GetState();
+
+ MouseButton::Type mouseButton = point.GetMouseButton();
+ switch(mouseButton)
+ {
+ case MouseButton::INVALID:
+ {
+ mGestureSourceType = GestureSourceType::INVALID;
+ break;
+ }
+ case MouseButton::PRIMARY:
+ {
+ mGestureSourceType = GestureSourceType::PRIMARY;
+ break;
+ }
+ case MouseButton::SECONDARY:
+ {
+ mGestureSourceType = GestureSourceType::SECONDARY;
+ break;
+ }
+ case MouseButton::TERTIARY:
+ {
+ mGestureSourceType = GestureSourceType::TERTIARY;
+ break;
+ }
+ default:
+ {
+ mGestureSourceType = GestureSourceType::INVALID;
+ break;
+ }
+ }
- switch (mState)
+ switch(mState)
{
- case Clear:
+ case CLEAR:
{
- if (pointState == PointState::DOWN)
+ if(pointState == PointState::DOWN)
{
- SetupForTouchDown( event, point );
+ SetupForTouchDown(event, point);
}
break;
}
- case Touched:
+ case TOUCHED:
{
uint32_t deltaBetweenTouchDownTouchUp = event.time - mTouchTime;
- if ( pointState == PointState::UP )
+ if(pointState == PointState::UP)
{
- if ( deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED )
+ if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
{
mLastTapTime = mTouchTime;
- EmitSingleTap( event.time, point );
- mState = Registered;
+ EmitSingleTap(event.time, point);
+ mState = REGISTERED;
}
else
{
- mState = Clear;
+ mState = CLEAR;
}
}
- else if (pointState == PointState::INTERRUPTED)
+ else if(pointState == PointState::INTERRUPTED)
{
- mState = Clear;
+ mState = CLEAR;
}
break;
}
- case Registered:
+ case REGISTERED:
{
- if ( pointState == PointState::UP )
+ if(pointState == PointState::UP)
{
+ // This is a possible multiple tap, so has it been quick enough?
+ uint32_t timeDelta = event.time - mLastTapTime;
uint32_t deltaBetweenTouchDownTouchUp = event.time - mTouchTime;
-
- if ( deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED )
+ if(timeDelta > MAXIMUM_TIME_ALLOWED) // If exceeded time between taps then just a single tap
{
- // This is a possible multiple tap, so has it been quick enough?
- uint32_t timeDelta = event.time - mLastTapTime;
- if( timeDelta > MAXIMUM_TIME_ALLOWED ) // If exceeded time between taps then just a single tap
- {
- mLastTapTime = event.time;
- EmitSingleTap(event.time, point);
- mState = Registered;
- }
- else
- {
- ++mTapsRegistered;
- EmitGesture( Gesture::Started, event.time );
- mState = Clear;
- }
+ mLastTapTime = event.time;
+ EmitSingleTap(event.time, point);
}
- else // Delta between touch down and touch up too long to be considered a Tap event
+ else if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
{
- mState = Clear;
+ ++mTapsRegistered;
+ EmitGesture(GestureState::STARTED, event.time);
+ }
+ else // Delta between touch down and touch up too long to be considered a TAP event
+ {
+ mState = CLEAR;
}
}
- else if (pointState == PointState::DOWN)
+ else if(pointState == PointState::DOWN)
{
- const Vector2& screen( point.GetScreenPosition() );
- Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
+ const Vector2& screen(point.GetScreenPosition());
+ Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
std::abs(mTouchPosition.y - screen.y));
uint32_t timeDelta = event.time - mLastTapTime;
- if (distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
- distanceDelta.y > MAXIMUM_MOTION_ALLOWED ||
- timeDelta > MAXIMUM_TIME_ALLOWED )
+ if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
+ distanceDelta.y > MAXIMUM_MOTION_ALLOWED ||
+ timeDelta > MAXIMUM_TIME_ALLOWED)
{
- SetupForTouchDown( event, point );
+ SetupForTouchDown(event, point);
}
else
{
- EmitPossibleState( event );
+ EmitPossibleState(event);
}
}
break;
}
- case Failed:
+ case FAILED:
default:
{
- mState = Clear;
+ mState = CLEAR;
break;
}
}
}
else
{
- mState = Failed;
+ mState = FAILED;
// We have entered a multi-touch event so emit registered gestures if required.
- EmitGesture(Gesture::Started, event.time);
+ EmitGesture(GestureState::STARTED, event.time);
}
}
-void TapGestureRecognizer::SetupForTouchDown( const Integration::TouchEvent& event, const Integration::Point& point )
+void TapGestureRecognizer::SetupForTouchDown(const Integration::TouchEvent& event, const Integration::Point& point)
{
- mTouchPosition = point.GetScreenPosition();
- mTouchTime = event.time;
- mLastTapTime = 0u;
+ mTouchPosition = point.GetScreenPosition();
+ mTouchTime = event.time;
+ mLastTapTime = 0u;
mTapsRegistered = 0;
- mState = Touched;
- EmitPossibleState( event );
+ mState = TOUCHED;
+
+ EmitPossibleState(event);
}
-void TapGestureRecognizer::EmitPossibleState( const Integration::TouchEvent& event )
+void TapGestureRecognizer::EmitPossibleState(const Integration::TouchEvent& event)
{
- TapGestureEvent tapEvent( Gesture::Possible );
- tapEvent.point = mTouchPosition;
- tapEvent.time = event.time;
+ TapGestureEvent tapEvent(GestureState::POSSIBLE);
+ tapEvent.point = mTouchPosition;
+ tapEvent.time = event.time;
+ tapEvent.gestureSourceType = mGestureSourceType;
- ProcessEvent( tapEvent );
+ ProcessEvent(tapEvent);
}
-
void TapGestureRecognizer::Update(const GestureRequest& request)
{
const TapGestureRequest& tap = static_cast<const TapGestureRequest&>(request);
mMaximumTapsRequired = tap.maxTaps;
}
-void TapGestureRecognizer::EmitGesture( Gesture::State state, uint32_t time )
+void TapGestureRecognizer::EmitGesture(GestureState state, uint32_t time)
{
- if ( (state == Gesture::Cancelled) ||
- (mTapsRegistered >= mMinimumTapsRequired && mTapsRegistered <= mMaximumTapsRequired) )
+ if((state == GestureState::CANCELLED) ||
+ (mTapsRegistered >= mMinimumTapsRequired && mTapsRegistered <= mMaximumTapsRequired))
{
- TapGestureEvent event( state );
- EmitTap( time, event );
+ TapGestureEvent event(state);
+ EmitTap(time, event);
}
}
-void TapGestureRecognizer::EmitSingleTap( uint32_t time, const Integration::Point& point )
+void TapGestureRecognizer::EmitSingleTap(uint32_t time, const Integration::Point& point)
{
- TapGestureEvent event( Gesture::Started );
- const Vector2& screen( point.GetScreenPosition() );
- Vector2 distanceDelta(std::abs(mTouchPosition.x - screen.x),
+ TapGestureEvent event(GestureState::STARTED);
+ const Vector2& screen(point.GetScreenPosition());
+ 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 > MAXIMUM_MOTION_ALLOWED ||
+ distanceDelta.y > MAXIMUM_MOTION_ALLOWED)
{
- event.state = Gesture::Cancelled;
+ event.state = GestureState::CANCELLED;
}
mTapsRegistered = 1u;
- EmitTap( time, event );
+ EmitTap(time, event);
}
-void TapGestureRecognizer::EmitTap( uint32_t time, TapGestureEvent& event )
+void TapGestureRecognizer::EmitTap(uint32_t time, TapGestureEvent& event)
{
- event.numberOfTaps = mTapsRegistered;
- event.point = mTouchPosition;
- event.time = time;
+ event.numberOfTaps = mTapsRegistered;
+ event.point = mTouchPosition;
+ event.time = time;
+ event.gestureSourceType = mGestureSourceType;
- ProcessEvent( event );
+ ProcessEvent(event);
}
-void TapGestureRecognizer::ProcessEvent( TapGestureEvent& event )
+void TapGestureRecognizer::ProcessEvent(TapGestureEvent& event)
{
- if( mScene )
+ if(mScene)
{
// Create another handle so the recognizer cannot be destroyed during process function
GestureRecognizerPtr recognizerHandle = this;