Fix the minimum pinch gesture distance 40/215540/6
authorJiyun Yang <ji.yang@samsung.com>
Thu, 10 Oct 2019 08:29:41 +0000 (17:29 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Thu, 10 Oct 2019 11:29:21 +0000 (20:29 +0900)
Previously, the minimum pinch distance is determined by dividing the screen height by 85,
which is proportional to the screen height.

The problem is that, on the big size screen (or law dpi) devices,
the user have to make a long distance between their fingers to make a pinch gesture,
it makes the user misunderstand that the pinch gesture is not workoring properly.

This patch fixes the problem by calculating minimum pinch distance using screen dpi.

Change-Id: Iaab2d37f43421d53f9aa14060bd55465df4f9343
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
dali/internal/event/events/pinch-gesture/pinch-gesture-processor.cpp
dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.cpp
dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.h

index 162bf6b..c373fae 100644 (file)
@@ -222,7 +222,7 @@ void PinchGestureProcessor::AddGestureDetector( PinchGestureDetector* gestureDet
   if (createRecognizer)
   {
     Size size = scene.GetSize();
-    mGestureRecognizer = new PinchGestureRecognizer( *this, Vector2(size.width, size.height), mMinimumPinchDistance);
+    mGestureRecognizer = new PinchGestureRecognizer( *this, Vector2(size.width, size.height), scene.GetDpi(), mMinimumPinchDistance );
   }
 }
 
index 2dff2b5..23b24d8 100644 (file)
@@ -42,7 +42,8 @@ namespace
 const unsigned int MINIMUM_TOUCH_EVENTS_REQUIRED = 4;
 const unsigned int MINIMUM_TOUCH_EVENTS_REQUIRED_AFTER_START = 4;
 
-const float MINIMUM_DISTANCE_DELTA_DIVISOR = 85.0f;
+const float MINIMUM_DISTANCE_IN_MILLIINCH = 45.0f; // This value is used for measuring minimum pinch distance in pixel.
+const float MINIMUM_DISTANCE_IN_PIXEL = 10.0f; // This value is for devices that do not provide a valid dpi value. (assumes 220dpi)
 
 inline float GetDistance(const Integration::Point& point1, const Integration::Point& point2)
 {
@@ -55,13 +56,24 @@ inline Vector2 GetCenterPoint(const Integration::Point& point1, const Integratio
   return Vector2(point1.GetScreenPosition() + point2.GetScreenPosition()) * 0.5f;
 }
 
+inline bool IsValidDpi( const Vector2& dpi )
+{
+  return dpi.x > 0.f && dpi.y > 0.f;
+}
+
+inline float GetDefaultMinimumPinchDistance( const Vector2& dpi )
+{
+  return IsValidDpi( dpi ) ? ( ( MINIMUM_DISTANCE_IN_MILLIINCH * std::min( dpi.x, dpi.y ) ) / 1000.f ) : MINIMUM_DISTANCE_IN_PIXEL;
+}
+
 } // unnamed namespace
 
-PinchGestureRecognizer::PinchGestureRecognizer( Observer& observer, Vector2 screenSize, float minimumPinchDistance )
+PinchGestureRecognizer::PinchGestureRecognizer( Observer& observer, Vector2 screenSize, Vector2 screenDpi, float minimumPinchDistance )
 : GestureRecognizer( screenSize, Gesture::Pinch ),
   mObserver( observer ),
   mState( Clear ),
   mTouchEvents(),
+  mDefaultMinimumDistanceDelta( GetDefaultMinimumPinchDistance( screenDpi ) ),
   mStartingDistance( 0.0f )
 {
   SetMinimumPinchDistance( minimumPinchDistance );
@@ -73,7 +85,7 @@ PinchGestureRecognizer::~PinchGestureRecognizer()
 
 void PinchGestureRecognizer::SetMinimumPinchDistance(float value)
 {
-  mMinimumDistanceDelta = value >= 0.0f ? value : (mScreenSize.height / MINIMUM_DISTANCE_DELTA_DIVISOR);
+  mMinimumDistanceDelta = value >= 0.0f ? value : mDefaultMinimumDistanceDelta;
 }
 
 void PinchGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
index 008d7ff..509b6ef 100644 (file)
@@ -48,9 +48,10 @@ public:
   /**
    * Constructor
    * @param[in] screenSize The size of the screen.
+   * @param[in] screenDpi The dpi value of the screen
    * @param[in] minimumPinchDistance in pixels
    */
-  PinchGestureRecognizer(Observer& observer, Vector2 screenSize, float minimumPinchDistance);
+  PinchGestureRecognizer(Observer& observer, Vector2 screenSize, Vector2 screenDpi, float minimumPinchDistance);
 
   /**
    * Virtual destructor.
@@ -98,6 +99,8 @@ private:
   State mState; ///< The current state of the detector.
   std::vector<Integration::TouchEvent> mTouchEvents; ///< The touch events since initial touch down.
 
+  float mDefaultMinimumDistanceDelta; ///< The default value of the mMinimumDistanceDelta.
+
   float mMinimumDistanceDelta; ///< The minimum distance before a pinch is applicable.
 
   float mStartingDistance; ///< The distance between the two touch points when the pinch is first detected.