Add input source type to TapGesture. 77/259077/13
authorJoogab Yun <joogab.yun@samsung.com>
Tue, 1 Jun 2021 02:00:53 +0000 (11:00 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Thu, 10 Jun 2021 04:56:56 +0000 (13:56 +0900)
This is similar to MouseButton in TouchEvent.

Now, you can see from which input the tap was made.

Change-Id: I80800ebd805e283581486d76d046b5e269cbb8ba

automated-tests/src/dali-internal/utc-Dali-Internal-TapGesture.cpp
automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp
dali/internal/event/events/tap-gesture/tap-gesture-event.cpp
dali/internal/event/events/tap-gesture/tap-gesture-event.h
dali/internal/event/events/tap-gesture/tap-gesture-impl.h
dali/internal/event/events/tap-gesture/tap-gesture-processor.cpp
dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp
dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h
dali/public-api/events/gesture-enumerations.h
dali/public-api/events/tap-gesture.cpp
dali/public-api/events/tap-gesture.h

index 0af0624..483fe64 100644 (file)
@@ -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.
@@ -136,3 +136,20 @@ int UtcDaliTapGestureSetGetLocalPointP(void)
 
   END_TEST;
 }
+
+int UtcDaliTapGestureSetGetSourceTypeP(void)
+{
+  TapGesture gesture = DevelTapGesture::New(GestureState::STARTED);
+  DALI_TEST_EQUALS(gesture.GetSourceType(), GestureSourceType::INVALID, TEST_LOCATION);
+
+  GetImplementation(gesture).SetGestureSourceType(GestureSourceType::PRIMARY);
+  DALI_TEST_EQUALS(gesture.GetSourceType(), GestureSourceType::PRIMARY, TEST_LOCATION);
+
+  GetImplementation(gesture).SetGestureSourceType(GestureSourceType::SECONDARY);
+  DALI_TEST_EQUALS(gesture.GetSourceType(), GestureSourceType::SECONDARY, TEST_LOCATION);
+
+  GetImplementation(gesture).SetGestureSourceType(GestureSourceType::TERTIARY);
+  DALI_TEST_EQUALS(gesture.GetSourceType(), GestureSourceType::TERTIARY, TEST_LOCATION);
+
+  END_TEST;
+}
\ No newline at end of file
index 9cc4caf..7f79a5c 100644 (file)
@@ -121,6 +121,21 @@ struct TouchEventFunctor
   }
 };
 
+Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, int source, uint32_t time)
+{
+  Integration::TouchEvent touchEvent;
+  Integration::Point      point;
+  point.SetState(state);
+  point.SetDeviceId(4);
+  point.SetScreenPosition(screenPosition);
+  point.SetDeviceClass(Device::Class::TOUCH);
+  point.SetDeviceSubclass(Device::Subclass::NONE);
+  point.SetMouseButton(static_cast<MouseButton::Type>(source));
+  touchEvent.points.push_back(point);
+  touchEvent.time = time;
+  return touchEvent;
+}
+
 } // namespace
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -1044,3 +1059,64 @@ int UtcDaliTapGestureWhenGesturePropargation(void)
 
   END_TEST;
 }
+
+int UtcDaliTapGestureGetSourceType(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.Attach(actor);
+  detector.DetectedSignal().Connect(&application, functor);
+
+  // Emit a down signal with MouseButton
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 0, 100));
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 0, 120));
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::INVALID, TEST_LOCATION);
+
+  data.Reset();
+
+  // Emit a down signal with MouseButton
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 1, 700));
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 1, 720));
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::PRIMARY, TEST_LOCATION);
+
+  data.Reset();
+
+  // Emit a down signal with MouseButton
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 3, 1300));
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 3, 1320));
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::SECONDARY, TEST_LOCATION);
+
+  data.Reset();
+
+  // Emit a down signal with MouseButton
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 2, 1900));
+  application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 2, 1920));
+  application.SendNotification();
+
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::TERTIARY, TEST_LOCATION);
+
+  END_TEST;
+}
\ No newline at end of file
index 6ff9348..89b0620 100644 (file)
@@ -25,7 +25,8 @@ namespace Internal
 TapGestureEvent::TapGestureEvent(GestureState state)
 : GestureEvent(GestureType::TAP, state),
   numberOfTaps(1),
-  numberOfTouches(1)
+  numberOfTouches(1),
+  gestureSourceType(GestureSourceType::INVALID)
 {
 }
 
index 623f0a6..85f0b0f 100644 (file)
@@ -72,6 +72,11 @@ struct TapGestureEvent : public GestureEvent
    * If a multi-touch tap, then this should be the centroid of all the touch points.
    */
   Vector2 point;
+
+  /**
+   * This is the value of which input was tapped.
+   */
+  GestureSourceType gestureSourceType;
 };
 
 } // namespace Internal
index b13ce5d..58c62f4 100644 (file)
@@ -118,6 +118,23 @@ public:
     return mLocalPoint;
   }
 
+  /**
+   * @brief This is the value of which input was tapped.
+   * @param[in] source This is the value of which input was tapped to set.
+   */
+  inline void SetGestureSourceType(const GestureSourceType sourceType)
+  {
+    mGestureSourceType = sourceType;
+  }
+
+  /**
+   * @copydoc Dali::TapGesture::GetSourceType()
+   */
+  inline const GestureSourceType& GetSourceType() const
+  {
+    return mGestureSourceType;
+  }
+
 private:
   /**
    * @brief Virtual destructor
@@ -127,10 +144,11 @@ private:
   ~TapGesture() override = default;
 
 private:
-  Vector2  mScreenPoint;
-  Vector2  mLocalPoint;
-  uint32_t mNumberOfTaps{1u};
-  uint32_t mNumberOfTouches{1u};
+  Vector2           mScreenPoint;
+  Vector2           mLocalPoint;
+  uint32_t          mNumberOfTaps{1u};
+  uint32_t          mNumberOfTouches{1u};
+  GestureSourceType mGestureSourceType{GestureSourceType::INVALID};
 };
 
 } // namespace Internal
index c26f25a..39dd060 100644 (file)
@@ -60,6 +60,7 @@ void EmitTapSignal(
   tap->SetNumberOfTouches(tapEvent.numberOfTouches);
   tap->SetScreenPoint(tapEvent.point);
   tap->SetLocalPoint(localPoint);
+  tap->SetGestureSourceType(tapEvent.gestureSourceType);
 
   Dali::Actor                                    actorHandle(actor);
   const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
index 336fc64..975c847 100644 (file)
@@ -49,7 +49,8 @@ TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSiz
   mTapsRegistered(0),
   mTouchPosition(),
   mTouchTime(0u),
-  mLastTapTime(0u)
+  mLastTapTime(0u),
+  mGestureSourceType(GestureSourceType::INVALID)
 {
 }
 
@@ -64,6 +65,36 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
     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)
     {
       case CLEAR:
@@ -167,14 +198,16 @@ void TapGestureRecognizer::SetupForTouchDown(const Integration::TouchEvent& even
   mLastTapTime    = 0u;
   mTapsRegistered = 0;
   mState          = TOUCHED;
+
   EmitPossibleState(event);
 }
 
 void TapGestureRecognizer::EmitPossibleState(const Integration::TouchEvent& event)
 {
   TapGestureEvent tapEvent(GestureState::POSSIBLE);
-  tapEvent.point = mTouchPosition;
-  tapEvent.time  = event.time;
+  tapEvent.point             = mTouchPosition;
+  tapEvent.time              = event.time;
+  tapEvent.gestureSourceType = mGestureSourceType;
 
   ProcessEvent(tapEvent);
 }
@@ -216,9 +249,10 @@ void TapGestureRecognizer::EmitSingleTap(uint32_t time, const Integration::Point
 
 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);
 }
index 215b21c..f87d2ec 100644 (file)
@@ -141,6 +141,8 @@ private:
   Vector2  mTouchPosition; ///< The initial touch down position.
   uint32_t mTouchTime;     ///< The initial touch down time.
   uint32_t mLastTapTime;   ///< Time last tap gesture was registered
+
+  GestureSourceType mGestureSourceType; /// < Gesture input source type value.
 };
 
 } // namespace Internal
index 5fe303c..ba14daa 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GESTURE_ENUMERATIONS_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.
@@ -53,6 +53,17 @@ enum class GestureState : uint8_t
   POSSIBLE    ///< A gesture is possible. @SINCE_1_9.28
 };
 
+/**
+ * @brief Enumeration for gesture input source type.
+ */
+enum class GestureSourceType : int8_t
+{
+  INVALID   = -1, ///< invalid data
+  PRIMARY   = 1,  ///< Primary
+  SECONDARY = 3,  ///< Secondary
+  TERTIARY  = 2,  ///< Third (tertiary)
+};
+
 } // namespace Dali
 
 #endif // DALI_GESTURE_ENUMERATIONS_H
index fd0d62a..aba1966 100644 (file)
@@ -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.
@@ -61,4 +61,9 @@ const Vector2& TapGesture::GetLocalPoint() const
   return GetImplementation(*this).GetLocalPoint();
 }
 
+const GestureSourceType& TapGesture::GetSourceType() const
+{
+  return GetImplementation(*this).GetSourceType();
+}
+
 } // namespace Dali
index 0607568..04a2d9b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TAP_GESTURE_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.
@@ -120,6 +120,12 @@ public:
    */
   const Vector2& GetLocalPoint() const;
 
+  /**
+   * @brief This is the input type of which was tapped.
+   * @return The input type which was tapped.
+   */
+  const GestureSourceType& GetSourceType() const;
+
 public: // Not intended for application developers
   /// @cond internal
   /**