From 7dd51999bd7d8030c5dc82df0f97e4e0d46a7e75 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Thu, 10 Oct 2019 17:29:41 +0900 Subject: [PATCH] Fix the minimum pinch gesture distance 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 --- .../pinch-gesture/pinch-gesture-processor.cpp | 2 +- .../pinch-gesture/pinch-gesture-recognizer.cpp | 18 +++++++++++++++--- .../pinch-gesture/pinch-gesture-recognizer.h | 5 ++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/dali/internal/event/events/pinch-gesture/pinch-gesture-processor.cpp b/dali/internal/event/events/pinch-gesture/pinch-gesture-processor.cpp index 162bf6b83..c373fae60 100644 --- a/dali/internal/event/events/pinch-gesture/pinch-gesture-processor.cpp +++ b/dali/internal/event/events/pinch-gesture/pinch-gesture-processor.cpp @@ -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 ); } } diff --git a/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.cpp b/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.cpp index 2dff2b510..23b24d891 100644 --- a/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.cpp +++ b/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.cpp @@ -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) diff --git a/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.h b/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.h index 008d7ffd3..509b6ef11 100644 --- a/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.h +++ b/dali/internal/event/events/pinch-gesture/pinch-gesture-recognizer.h @@ -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 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. -- 2.34.1