X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fevents%2Ftap-gesture%2Ftap-gesture-recognizer.cpp;h=975c847ce545f681ac5046e29f6b0c61f122f4d6;hb=017a0045f7628be3cbb2e77d21388632236c567f;hp=f4e058ae49b32bb7c7b6628b54c4a4873c18fd23;hpb=05878c24a70080018266949b76ce0b82a07ee9f3;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp index f4e058a..975c847 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp +++ b/dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 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. @@ -26,168 +26,192 @@ #include // INTERNAL INCLUDES -#include #include +#include 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) { - if (event.GetPointCount() == 1) + GestureRecognizerPtr ptr(this); // To keep us from being destroyed during the life-time of this method + + 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(); - switch (mState) + MouseButton::Type mouseButton = point.GetMouseButton(); + switch(mouseButton) { - case Clear: + case MouseButton::INVALID: + { + mGestureSourceType = GestureSourceType::INVALID; + break; + } + case MouseButton::PRIMARY: + { + mGestureSourceType = GestureSourceType::PRIMARY; + break; + } + case MouseButton::SECONDARY: + { + mGestureSourceType = GestureSourceType::SECONDARY; + break; + } + case MouseButton::TERTIARY: { - if (pointState == PointState::DOWN) + mGestureSourceType = GestureSourceType::TERTIARY; + break; + } + default: + { + mGestureSourceType = GestureSourceType::INVALID; + break; + } + } + + switch(mState) + { + case CLEAR: + { + 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(request); @@ -196,45 +220,46 @@ void TapGestureRecognizer::Update(const GestureRequest& 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;