From 92b051cadd0db5d9f985aacbbbf832995fb55f53 Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Tue, 24 Aug 2021 16:57:08 +0900 Subject: [PATCH] Add ReceiveAllTapEvents(bool) If MaximumTaps is greater than MinimumTaps, the event is sent by checking whether it is the correct single tap or multi tap. However, there are cases when I want to receive all tap events without these checks. Change-Id: Icad048eec6f87b6a0efca9907904afecee70fe08 --- .../src/dali/utc-Dali-TapGestureDetector.cpp | 63 ++++++++++++++++++++++ .../tap-gesture/tap-gesture-detector-impl.cpp | 10 +++- .../events/tap-gesture/tap-gesture-detector-impl.h | 6 +++ dali/public-api/events/tap-gesture-detector.cpp | 7 ++- dali/public-api/events/tap-gesture-detector.h | 13 ++++- 5 files changed, 95 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp index a05941a..714c146 100644 --- a/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp @@ -1081,4 +1081,67 @@ int UtcDaliTapGestureGetSourceType(void) DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::TERTIARY, TEST_LOCATION); END_TEST; +} + +int UtcDaliTapGestureReceiveAllTapEvents(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + + application.GetScene().Add(actor); + + // Render and notify + application.SendNotification(); + application.Render(); + + SignalData data; + GestureReceivedFunctor functor(data); + + TapGestureDetector detector = TapGestureDetector::New(); + detector.SetMaximumTapsRequired(2u); + detector.Attach(actor); + detector.DetectedSignal().Connect(&application, functor); + + // Emit signals, Because MaximumTapsRequired is 2, a timer that checks whether it is a single tap or a double tap operates internally. + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 0, 100)); + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 0, 120)); + application.SendNotification(); + + // So detector don't get the tap event yet. + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + data.Reset(); + + // Emit signals, Send the second tab. + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 0, 130)); + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 0, 150)); + application.SendNotification(); + application.GetPlatform().TriggerTimer(); + + // It find out to be a double tap. Detector receives events. + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + // Detector want to receive all tap events. + detector.ReceiveAllTapEvents(true); + + // Emit signals, should receive + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 0, 500)); + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 0, 520)); + application.SendNotification(); + + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + // Emit signals, should receive + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 0, 530)); + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 0, 550)); + application.SendNotification(); + + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + END_TEST; } \ No newline at end of file diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.cpp b/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.cpp index ee1f0d5..5256361 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.cpp +++ b/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.cpp @@ -71,7 +71,8 @@ TapGestureDetector::TapGestureDetector() mTouchesRequired(DEFAULT_TOUCHES_REQUIRED), mTimerId(0), mTappedActor(), - mTap() + mTap(), + mReceiveAllTapEvents(false) { } @@ -149,6 +150,11 @@ unsigned int TapGestureDetector::GetTouchesRequired() const return mTouchesRequired; } +void TapGestureDetector::ReceiveAllTapEvents(bool receive) +{ + mReceiveAllTapEvents = receive; +} + void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const Dali::TapGesture& tap) { Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction(); @@ -157,7 +163,7 @@ void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const Dal platformAbstraction.CancelTimer(mTimerId); mTimerId = 0; } - if(mMaximumTapsRequired > tap.GetNumberOfTaps()) + if(mMaximumTapsRequired > tap.GetNumberOfTaps() && !mReceiveAllTapEvents) { mTappedActor = tappedActor; diff --git a/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h b/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h index fd7db72..1dd5dc8 100644 --- a/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h +++ b/dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h @@ -93,6 +93,11 @@ public: */ unsigned int GetTouchesRequired() const; + /** + * @copydoc Dali::TapGestureDetector::ReceiveAllTapEvents() + */ + void ReceiveAllTapEvents(bool receive); + public: /** * Called by the TapGestureProcessor when a tap gesture event occurs within the bounds of our @@ -164,6 +169,7 @@ private: uint32_t mTimerId; Dali::Actor mTappedActor; Dali::TapGesture mTap; + bool mReceiveAllTapEvents; }; } // namespace Internal diff --git a/dali/public-api/events/tap-gesture-detector.cpp b/dali/public-api/events/tap-gesture-detector.cpp index fa9376d..e491ef0 100644 --- a/dali/public-api/events/tap-gesture-detector.cpp +++ b/dali/public-api/events/tap-gesture-detector.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -79,6 +79,11 @@ uint32_t TapGestureDetector::GetMaximumTapsRequired() const return GetImplementation(*this).GetMaximumTapsRequired(); } +void TapGestureDetector::ReceiveAllTapEvents(bool receive) +{ + return GetImplementation(*this).ReceiveAllTapEvents(receive); +} + TapGestureDetector::DetectedSignalType& TapGestureDetector::DetectedSignal() { return GetImplementation(*this).DetectedSignal(); diff --git a/dali/public-api/events/tap-gesture-detector.h b/dali/public-api/events/tap-gesture-detector.h index 7432c83..7782231 100644 --- a/dali/public-api/events/tap-gesture-detector.h +++ b/dali/public-api/events/tap-gesture-detector.h @@ -2,7 +2,7 @@ #define DALI_TAP_GESTURE_DETECTOR_H /* - * 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. @@ -148,6 +148,7 @@ public: // Setters * @param[in] minimumTaps The minimum taps required * @pre The gesture detector has been initialized. * @note The default is '1', the maximum is 2. + * @see ReceiveAllTapEvents */ void SetMinimumTapsRequired(uint32_t minimumTaps); @@ -159,9 +160,19 @@ public: // Setters * @param[in] maximumTaps The maximum taps required * @pre The gesture detector has been initialized. * @note The default is '1', the maximum is 2. + * @see ReceiveAllTapEvents */ void SetMaximumTapsRequired(uint32_t maximumTaps); + /** + * @brief When set to true, all tap gestures will be received when multiple taps are supported by the gesture detector. + * + * @param[in] receive The receiving all tap events flag + * @pre The gesture detector has been initialized. + * @note The default is false. + */ + void ReceiveAllTapEvents(bool receive); + public: // Getters /** * @brief Retrieves the minimum number of taps required. -- 2.7.4