From: Adeel Kazmi Date: Thu, 26 Jun 2014 14:23:05 +0000 (+0900) Subject: (PanGesture) Two motions before pan & ability to set the min distance/events via... X-Git-Tag: dali_1.0.0~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a7b11c8674a984950311171710839b93b7fa64b;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git (PanGesture) Two motions before pan & ability to set the min distance/events via environment variable [problem] Need more than one motion event to determine the direction. [cause] N/A [solution] Wait at least one more pan. Add configurability via environment variables: Minimum distance before pan: DALI_PAN_MINIMUM_DISTANCE Minimum motion events before pan (include down): DALI_PAN_MINIMUM_EVENTS Change-Id: I3dbe34dc56d6c84518aec3807911054280998ca5 Signed-off-by: Adeel Kazmi --- diff --git a/adaptors/base/environment-options.cpp b/adaptors/base/environment-options.cpp index 3256751..764a159 100644 --- a/adaptors/base/environment-options.cpp +++ b/adaptors/base/environment-options.cpp @@ -34,6 +34,8 @@ EnvironmentOptions::EnvironmentOptions() mPanGestureLoggingLevel(0), mPanGesturePredictionMode(-1), mPanGesturePredictionAmount(-1.0f), ///< only sets value in pan gesture if greater than 0 + mPanMinimumDistance(-1), + mPanMinimumEvents(-1), mLogFunction( NULL ) { } @@ -95,6 +97,16 @@ float EnvironmentOptions::GetPanGesturePredictionAmount() const return mPanGesturePredictionAmount; } +int EnvironmentOptions::GetMinimumPanDistance() const +{ + return mPanMinimumDistance; +} + +int EnvironmentOptions::GetMinimumPanEvents() const +{ + return mPanMinimumEvents; +} + void EnvironmentOptions::SetPanGesturePredictionMode(unsigned int mode) { mPanGesturePredictionMode = mode; @@ -105,6 +117,16 @@ void EnvironmentOptions::SetPanGesturePredictionAmount(unsigned int amount) mPanGesturePredictionAmount = amount; } +void EnvironmentOptions::SetMinimumPanDistance( int distance ) +{ + mPanMinimumDistance = distance; +} + +void EnvironmentOptions::SetMinimumPanEvents( int events ) +{ + mPanMinimumEvents = events; +} + } // Adaptor } // Internal diff --git a/adaptors/base/environment-options.h b/adaptors/base/environment-options.h index ec865e4..1ff9a8b 100644 --- a/adaptors/base/environment-options.h +++ b/adaptors/base/environment-options.h @@ -100,6 +100,16 @@ public: float GetPanGesturePredictionAmount() const; /** + * @return The minimum distance before a pan can be started (-1 means it's not set) + */ + int GetMinimumPanDistance() const; + + /** + * @return The minimum events before a pan can be started (-1 means it's not set) + */ + int GetMinimumPanEvents() const; + + /** * @brief Sets the mode used to smooth pan gesture movement properties calculated on the Update thread * * @param[in] mode The smoothing mode to use @@ -113,6 +123,20 @@ public: */ void SetPanGesturePredictionAmount(unsigned int amount); + /** + * @brief Sets the minimum distance required before a pan starts + * + * @param[in] distance The minimum distance before a pan starts + */ + void SetMinimumPanDistance( int distance ); + + /** + * @brief Sets the minimum number of events required before a pan starts + * + * @param[in] events The minimum events before a pan starts + */ + void SetMinimumPanEvents( int events ); + private: unsigned int mFpsFrequency; ///< how often fps is logged out in seconds @@ -121,6 +145,8 @@ private: unsigned int mPanGestureLoggingLevel; ///< pan-gesture log level int mPanGesturePredictionMode; ///< prediction mode for pan gestures float mPanGesturePredictionAmount; ///< prediction amount for pan gestures + int mPanMinimumDistance; ///< minimum distance required before pan starts + int mPanMinimumEvents; ///< minimum events required before pan starts Dali::Integration::Log::LogFunction mLogFunction; diff --git a/adaptors/base/environment-variables.h b/adaptors/base/environment-variables.h index d6f2966..f240292 100644 --- a/adaptors/base/environment-variables.h +++ b/adaptors/base/environment-variables.h @@ -35,6 +35,10 @@ namespace Adaptor #define DALI_ENV_PAN_PREDICTION_AMOUNT "DALI_PAN_PREDICTION_AMOUNT" +#define DALI_ENV_PAN_MINIMUM_DISTANCE "DALI_PAN_MINIMUM_DISTANCE" + +#define DALI_ENV_PAN_MINIMUM_EVENTS "DALI_PAN_MINIMUM_EVENTS" + } // namespace Adaptor } // namespace Internal diff --git a/adaptors/tizen/internal/common/accessibility-gesture-detector.cpp b/adaptors/tizen/internal/common/accessibility-gesture-detector.cpp index e9230a0..2152886 100644 --- a/adaptors/tizen/internal/common/accessibility-gesture-detector.cpp +++ b/adaptors/tizen/internal/common/accessibility-gesture-detector.cpp @@ -34,7 +34,7 @@ namespace Adaptor { AccessibilityGestureDetector::AccessibilityGestureDetector() -: PanGestureDetectorBase(Vector2::ZERO, Integration::PanGestureRequest()), +: PanGestureDetectorBase(Vector2::ZERO, Integration::PanGestureRequest(), NULL), mGestureHandler(NULL), mPanning(false) { diff --git a/adaptors/tizen/internal/common/adaptor-impl.cpp b/adaptors/tizen/internal/common/adaptor-impl.cpp index e20d44b..6e09188 100644 --- a/adaptors/tizen/internal/common/adaptor-impl.cpp +++ b/adaptors/tizen/internal/common/adaptor-impl.cpp @@ -155,6 +155,18 @@ void Adaptor::ParseEnvironmentOptions() mEnvironmentOptions.SetPanGesturePredictionAmount(predictionAmount); } + int minimumDistance(-1); + if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance )) + { + mEnvironmentOptions.SetMinimumPanDistance( minimumDistance ); + } + + int minimumEvents(-1); + if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents )) + { + mEnvironmentOptions.SetMinimumPanEvents( minimumEvents ); + } + mEnvironmentOptions.InstallLogFunction(); } @@ -173,7 +185,7 @@ void Adaptor::Initialize() PositionSize size = mSurface->GetPositionSize(); - mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager); + mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, mEnvironmentOptions); mGLES = new GlImplementation; diff --git a/adaptors/tizen/internal/common/events/gesture-manager.cpp b/adaptors/tizen/internal/common/events/gesture-manager.cpp index 8a9dc98..a0bd527 100644 --- a/adaptors/tizen/internal/common/events/gesture-manager.cpp +++ b/adaptors/tizen/internal/common/events/gesture-manager.cpp @@ -97,10 +97,11 @@ const char * GetGestureTypeString( Gesture::Type type ) const float MINIMUM_DISTANCE_DELTA_DIVISOR = 85.0f; } // unnamed namespace -GestureManager::GestureManager(CoreEventInterface& coreEventInterface, Vector2 screenSize,CallbackManager* callbackManager) +GestureManager::GestureManager(CoreEventInterface& coreEventInterface, Vector2 screenSize,CallbackManager* callbackManager, EnvironmentOptions& environmentOptions) : mCoreEventInterface( coreEventInterface ), mScreenSize( screenSize ), mCallbackManager( callbackManager ), + mEnvironmentOptions( environmentOptions ), mMinimumDistanceDelta(-1.0f), mRunning( true ) // This allows gestures to be created before Adaptor::Start() is called e.g. by Indicator { @@ -175,7 +176,7 @@ void GestureManager::Register(const Integration::GestureRequest& request) case Gesture::Pan: { - GestureDetectorPtr gesture = new PanGestureDetector(mCoreEventInterface, mScreenSize, static_cast(request)); + GestureDetectorPtr gesture = new PanGestureDetector(mCoreEventInterface, mScreenSize, static_cast(request), mEnvironmentOptions); mGestureDetectors.push_back(gesture); break; } diff --git a/adaptors/tizen/internal/common/events/gesture-manager.h b/adaptors/tizen/internal/common/events/gesture-manager.h index 7003a0b..7e5855d 100644 --- a/adaptors/tizen/internal/common/events/gesture-manager.h +++ b/adaptors/tizen/internal/common/events/gesture-manager.h @@ -42,6 +42,7 @@ namespace Adaptor class CallbackManager; class CoreEventInterface; +class EnvironmentOptions; /** * Implementation of the Integration::GestureManager. @@ -58,8 +59,9 @@ public: * @param[in] coreEventInterface Used to send events to Core. * @param[in] screenSize The size of the screen. * @param[in] callbackManager used to install callbacks + * @param[in] environmentOptions Environment Options */ - GestureManager(CoreEventInterface& coreEventInterface, Vector2 screenSize, CallbackManager* callbackManager); + GestureManager(CoreEventInterface& coreEventInterface, Vector2 screenSize, CallbackManager* callbackManager, EnvironmentOptions& environmentOptions); /** * The destructor @@ -119,6 +121,7 @@ private: GestureDetectorContainer mGestureDetectors; Vector2 mScreenSize; CallbackManager* mCallbackManager; + EnvironmentOptions& mEnvironmentOptions; float mMinimumDistanceDelta; ///< The minimum distance before a pinch is applicable. (-1.0f means pinch detector uses default value) bool mRunning; ///< States whether the GestureManager is running or not. }; diff --git a/adaptors/tizen/internal/common/events/pan-gesture-detector-base.cpp b/adaptors/tizen/internal/common/events/pan-gesture-detector-base.cpp index 22d54a0..189f8f4 100644 --- a/adaptors/tizen/internal/common/events/pan-gesture-detector-base.cpp +++ b/adaptors/tizen/internal/common/events/pan-gesture-detector-base.cpp @@ -27,6 +27,7 @@ #include // INTERNAL INCLUDES +#include namespace Dali { @@ -42,15 +43,33 @@ namespace // TODO: Used DPD Value. const float MINIMUM_MOTION_BEFORE_PAN_SQUARED( 15.0f * 15.0f ); const unsigned long MAXIMUM_TIME_DIFF_ALLOWED( 500 ); +const unsigned int MINIMUM_MOTION_EVENTS_BEFORE_PAN(2); } // unnamed namespace -PanGestureDetectorBase::PanGestureDetectorBase(Vector2 screenSize, const Integration::PanGestureRequest& request) +PanGestureDetectorBase::PanGestureDetectorBase(Vector2 screenSize, const Integration::PanGestureRequest& request, EnvironmentOptions* environmentOptions) : GestureDetector(screenSize, Gesture::Pan), mState(Clear), mPrimaryTouchDownTime(0), mMinimumTouchesRequired(request.minTouches), - mMaximumTouchesRequired(request.maxTouches) + mMaximumTouchesRequired(request.maxTouches), + mMinimumDistanceSquared( MINIMUM_MOTION_BEFORE_PAN_SQUARED ), + mMinimumMotionEvents( MINIMUM_MOTION_EVENTS_BEFORE_PAN ), + mMotionEvents(0) { + if ( environmentOptions ) + { + int minimumDistance = environmentOptions->GetMinimumPanDistance(); + if ( minimumDistance >= 0 ) + { + mMinimumDistanceSquared = minimumDistance * minimumDistance; + } + + int minimumEvents = environmentOptions->GetMinimumPanEvents(); + if ( minimumEvents >= 1 ) + { + mMinimumMotionEvents = minimumEvents - 1; // Down is the first event + } + } } PanGestureDetectorBase::~PanGestureDetectorBase() @@ -82,6 +101,7 @@ void PanGestureDetectorBase::SendEvent(const Integration::TouchEvent& event) { mPrimaryTouchDownLocation = event.points[0].screen; mPrimaryTouchDownTime = event.time; + mMotionEvents = 0; if (event.GetPointCount() == mMinimumTouchesRequired) { // We have satisfied the minimum touches required for a pan, tell core that a gesture may be possible and change our state accordingly. @@ -102,10 +122,12 @@ void PanGestureDetectorBase::SendEvent(const Integration::TouchEvent& event) if (primaryPointState == TouchPoint::Motion) { mTouchEvents.push_back(event); + mMotionEvents++; Vector2 delta(event.points[0].screen - mPrimaryTouchDownLocation); - if (delta.LengthSquared() >= MINIMUM_MOTION_BEFORE_PAN_SQUARED) + if ( ( mMotionEvents >= mMinimumMotionEvents ) && + ( delta.LengthSquared() >= mMinimumDistanceSquared ) ) { // If the touch point(s) have moved enough distance to be considered a pan, then tell Core that the pan gesture has started and change our state accordingly. mState = Started; @@ -115,7 +137,7 @@ void PanGestureDetectorBase::SendEvent(const Integration::TouchEvent& event) else if (primaryPointState == TouchPoint::Up) { Vector2 delta(event.points[0].screen - mPrimaryTouchDownLocation); - if(delta.LengthSquared() >= MINIMUM_MOTION_BEFORE_PAN_SQUARED) + if(delta.LengthSquared() >= mMinimumDistanceSquared) { SendPan(Gesture::Started, event); mTouchEvents.push_back(event); diff --git a/adaptors/tizen/internal/common/events/pan-gesture-detector-base.h b/adaptors/tizen/internal/common/events/pan-gesture-detector-base.h index eb63c16..dfbdad5 100644 --- a/adaptors/tizen/internal/common/events/pan-gesture-detector-base.h +++ b/adaptors/tizen/internal/common/events/pan-gesture-detector-base.h @@ -42,6 +42,8 @@ namespace Internal namespace Adaptor { +class EnvironmentOptions; + /** * When given a set of touch events, this detector attempts to determine if a pan gesture has taken place. */ @@ -73,7 +75,7 @@ protected: * @param[in] screenSize The size of the screen. * @param[in] request The details of the request. */ - PanGestureDetectorBase(Vector2 screenSize, const Integration::PanGestureRequest& request); + PanGestureDetectorBase(Vector2 screenSize, const Integration::PanGestureRequest& request, EnvironmentOptions* environmentOptions); private: @@ -111,6 +113,10 @@ private: unsigned long mPrimaryTouchDownTime; ///< The initial touch down time. unsigned int mMinimumTouchesRequired; ///< The minimum touches required before a pan should be emitted. unsigned int mMaximumTouchesRequired; ///< The maximum touches after which a pan should not be emitted. + + unsigned int mMinimumDistanceSquared; ///< The minimum distance squared before pan should start. + unsigned int mMinimumMotionEvents; ///< The minimum motion events before pan should start. + unsigned int mMotionEvents; ///< The motion events received so far (before pan is emitted). }; } // namespace Adaptor diff --git a/adaptors/tizen/internal/common/events/pan-gesture-detector.cpp b/adaptors/tizen/internal/common/events/pan-gesture-detector.cpp index 6220eae..01261d5 100644 --- a/adaptors/tizen/internal/common/events/pan-gesture-detector.cpp +++ b/adaptors/tizen/internal/common/events/pan-gesture-detector.cpp @@ -34,8 +34,8 @@ namespace Internal namespace Adaptor { -PanGestureDetector::PanGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::PanGestureRequest& request) -: PanGestureDetectorBase(screenSize, request), +PanGestureDetector::PanGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::PanGestureRequest& request, EnvironmentOptions& environmentOptions) +: PanGestureDetectorBase(screenSize, request, &environmentOptions), mCoreEventInterface(coreEventInterface) { } diff --git a/adaptors/tizen/internal/common/events/pan-gesture-detector.h b/adaptors/tizen/internal/common/events/pan-gesture-detector.h index 189e125..b4e0978 100644 --- a/adaptors/tizen/internal/common/events/pan-gesture-detector.h +++ b/adaptors/tizen/internal/common/events/pan-gesture-detector.h @@ -55,8 +55,9 @@ public: * @param[in] coreEventInterface Used to send events to Core. * @param[in] screenSize The size of the screen. * @param[in] request The details of the request. + * @param[in] environmentOptions The environmentOptions. */ - PanGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::PanGestureRequest& request); + PanGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::PanGestureRequest& request, EnvironmentOptions& environmentOptions); /** * Virtual destructor.