Allows updating MinimumDistance and MinimumPanEvents of pan gestures. 39/310139/3
authorjoogab.yun <joogab.yun@samsung.com>
Tue, 23 Apr 2024 05:45:38 +0000 (14:45 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Tue, 23 Apr 2024 06:55:14 +0000 (15:55 +0900)
Change-Id: Ibe985928ae9e68f70fc4faf573284ce1ee956fb5

automated-tests/src/dali/utc-Dali-PanGestureRecognizer.cpp
dali/internal/event/events/gesture-event-processor.cpp
dali/internal/event/events/pan-gesture/pan-gesture-processor.cpp
dali/internal/event/events/pan-gesture/pan-gesture-processor.h
dali/internal/event/events/pan-gesture/pan-gesture-recognizer.cpp
dali/internal/event/events/pan-gesture/pan-gesture-recognizer.h

index 5f6e075..c6ee297 100644 (file)
@@ -696,6 +696,62 @@ int UtcDaliPanGestureRecognizerNewParamsMinNum(void)
   END_TEST;
 }
 
+int UtcDaliPanGestureRecognizerUpdateParamsMinNum(void)
+{
+  TestApplication application;
+
+  Integration::SetPanGestureMinimumPanEvents(8);
+
+  PanGestureDetector detector = PanGestureDetector::New();
+
+  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();
+
+  detector.Attach(actor);
+
+  SignalData             data;
+  GestureReceivedFunctor functor(data);
+  detector.DetectedSignal().Connect(&application, functor);
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 352));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 70.0f), 453));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 80.0f), 554));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 90.0f), 655));
+
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 90.0f), 756));
+  application.SendNotification();
+  data.Reset();
+
+  Integration::SetPanGestureMinimumPanEvents(10);
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 352));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 70.0f), 453));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 80.0f), 554));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 90.0f), 655));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 100.0f), 756));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 110.0f), 857));
+
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+
+  END_TEST;
+}
+
+
 int UtcDaliPanGestureRecognizerNewParamsMinDistance(void)
 {
   TestApplication application;
@@ -732,3 +788,59 @@ int UtcDaliPanGestureRecognizerNewParamsMinDistance(void)
 
   END_TEST;
 }
+
+int UtcDaliPanGestureRecognizerUpdateParamsMinDistance(void)
+{
+  TestApplication application;
+
+  Integration::SetPanGestureMinimumDistance(100);
+
+  PanGestureDetector detector = PanGestureDetector::New();
+
+  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();
+
+  detector.Attach(actor);
+
+  SignalData             data;
+  GestureReceivedFunctor functor(data);
+  detector.DetectedSignal().Connect(&application, functor);
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 352));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 70.0f), 453));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 80.0f), 554));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 90.0f), 655));
+
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 90.0f), 756));
+  application.SendNotification();
+  data.Reset();
+
+  Integration::SetPanGestureMinimumDistance(130);
+
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 352));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 70.0f), 453));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 80.0f), 554));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 90.0f), 655));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 100.0f),756));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 110.0f),857));
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 120.0f),858));
+
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+
+  END_TEST;
+}
index 135097d..85abccc 100644 (file)
@@ -329,11 +329,13 @@ void GestureEventProcessor::SetPanGestureMultitapSmoothingRange(int32_t value)
 void GestureEventProcessor::SetPanGestureMinimumDistance(int32_t value)
 {
   envOptionMinimumPanDistance = value;
+  mPanGestureProcessor.SetMinimumDistance(value);
 }
 
 void GestureEventProcessor::SetPanGestureMinimumPanEvents(int32_t value)
 {
   envOptionMinimumPanEvents = value;
+  mPanGestureProcessor.SetMinimumPanEvents(value);
 }
 
 void GestureEventProcessor::SetPinchGestureMinimumDistance(float value)
index e1ff19e..a495995 100644 (file)
@@ -495,6 +495,31 @@ void PanGestureProcessor::SetMultitapSmoothingRange(int value)
   mSceneObject->SetMultitapSmoothingRange(value);
 }
 
+void PanGestureProcessor::SetMinimumDistance(int32_t value)
+{
+  if(mGestureRecognizer)
+  {
+    PanGestureRecognizer* panRecognizer = dynamic_cast<PanGestureRecognizer*>(mGestureRecognizer.Get());
+    if(panRecognizer)
+    {
+      panRecognizer->SetMinimumDistance(value);
+    }
+  }
+}
+
+void PanGestureProcessor::SetMinimumPanEvents(int32_t value)
+{
+  if(mGestureRecognizer)
+  {
+    PanGestureRecognizer* panRecognizer = dynamic_cast<PanGestureRecognizer*>(mGestureRecognizer.Get());
+    if(panRecognizer)
+    {
+      panRecognizer->SetMinimumPanEvents(value);
+    }
+  }
+}
+
+
 const SceneGraph::PanGesture& PanGestureProcessor::GetSceneObject() const
 {
   return *mSceneObject;
index bfeb623..c9f60c3 100644 (file)
@@ -221,6 +221,18 @@ public: // To be called by GestureEventProcessor
    */
   void SetMultitapSmoothingRange(int value);
 
+  /**
+   * This method sets the minimum distance to start a pan
+   * @param[in] value The distance in pixels
+   */
+  void SetMinimumDistance(int32_t value);
+
+  /**
+   * Sets the minimum touch events required before a pan can be started
+   * @param[in] value The number of touch events
+   */
+  void SetMinimumPanEvents(int32_t value);
+
 public: // for PanGestureDetector
   /**
    * @return the pan gesture scene object
index 4e6ad9e..d5b40d0 100644 (file)
@@ -345,6 +345,27 @@ void PanGestureRecognizer::SendPan(GestureState state, const Integration::TouchE
   }
 }
 
+void PanGestureRecognizer::SetMinimumDistance(int32_t minimumDistance)
+{
+  if(minimumDistance >= 0)
+  {
+    mMinimumDistanceSquared = minimumDistance * minimumDistance;
+
+    // Usually, we do not want to apply the threshold straight away, but phased over the first few pans
+    // Set our distance to threshold adjustments ratio here.
+    float fMinimumDistance     = static_cast<float>(minimumDistance);
+    mThresholdTotalAdjustments = static_cast<unsigned int>(fMinimumDistance * MINIMUM_MOTION_DISTANCE_TO_THRESHOLD_ADJUSTMENTS_RATIO);
+  }
+}
+
+void PanGestureRecognizer::SetMinimumPanEvents(int32_t minimumPanEvents)
+{
+  if(minimumPanEvents >= 1)
+  {
+    mMinimumMotionEvents = minimumPanEvents - 1; // Down is the first event
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali
index 8bc3715..c1b1f30 100644 (file)
@@ -63,6 +63,18 @@ public:
 
 public:
   /**
+   * This method sets the minimum distance to start a pan
+   * @param[in] minimumDistance The distance in pixels
+   */
+  void SetMinimumDistance(int32_t minimumDistance);
+
+  /**
+   * Sets the minimum touch events required before a pan can be started
+   * @param[in] minimumPanEvents The number of touch events
+   */
+  void SetMinimumPanEvents(int32_t minimumPanEvents);
+
+  /**
    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
    */
   void SendEvent(const Integration::TouchEvent& event) override;