From 9e362f9cd4e43e7cffb08b5538b80bfb4f2533c2 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 16 Jun 2014 17:47:08 +0900 Subject: [PATCH] (PanGesture) Added pan velocities as a property. [problem] Unable to use the pan velocity values in constraint. [cause] They are not properties. [solution] Add properties which use this. Change-Id: I066a528ab0f56c1208e891d2f0d7a698ce09feac Signed-off-by: Adeel Kazmi --- .../src/dali/utc-Dali-PanGestureDetector.cpp | 27 ++++++-- capi/dali/public-api/events/pan-gesture-detector.h | 18 +++-- .../event/events/pan-gesture-detector-impl.cpp | 78 ++++++++++++++++------ .../update/gestures/scene-graph-pan-gesture.cpp | 28 ++++++-- .../update/gestures/scene-graph-pan-gesture.h | 18 ++++- 5 files changed, 128 insertions(+), 41 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp index 0e950a7..3a588e1 100644 --- a/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-PanGestureDetector.cpp @@ -135,13 +135,15 @@ struct ConstraintData Vector2 screenPosition; Vector2 screenDisplacement; + Vector2 screenVelocity; Vector2 localPosition; Vector2 localDisplacement; + Vector2 localVelocity; bool called; void Reset() { - screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO; + screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO; called = false; } }; @@ -154,13 +156,17 @@ struct PanConstraint Vector3 operator()(const Vector3& current, const PropertyInput& screenPositionProperty, const PropertyInput& screenDisplacementProperty, + const PropertyInput& screenVelocityProperty, const PropertyInput& localPositionProperty, - const PropertyInput& localDisplacementProperty) + const PropertyInput& localDisplacementProperty, + const PropertyInput& localVelocityProperty) { constraintData.screenPosition = screenPositionProperty.GetVector2(); constraintData.screenDisplacement = screenDisplacementProperty.GetVector2(); + constraintData.screenVelocity = screenVelocityProperty.GetVector2(); constraintData.localPosition = localPositionProperty.GetVector2(); constraintData.localDisplacement = localDisplacementProperty.GetVector2(); + constraintData.localVelocity = localVelocityProperty.GetVector2(); constraintData.called = true; return Vector3::ZERO; } @@ -195,7 +201,8 @@ PanGesture GeneratePan( unsigned int time, Vector2 localPosition, Vector2 screenDisplacement = Vector2::ONE, Vector2 localDisplacement = Vector2::ONE, - Vector2 velocity = Vector2::ONE, + Vector2 screenVelocity = Vector2::ONE, + Vector2 localVelocity = Vector2::ONE, unsigned int numberOfTouches = 1 ) { PanGesture pan( state ); @@ -208,7 +215,9 @@ PanGesture GeneratePan( unsigned int time, pan.screenDisplacement = screenDisplacement; pan.displacement = localDisplacement; - pan.screenVelocity = pan.velocity = velocity; + pan.screenVelocity = screenVelocity; + pan.velocity = localVelocity; + pan.numberOfTouches = numberOfTouches; return pan; @@ -2021,8 +2030,10 @@ int UtcDaliPanGestureSetProperties(void) ConstraintData constraintData; actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), + Source( detector, PanGestureDetector::SCREEN_VELOCITY ), Source( detector, PanGestureDetector::LOCAL_POSITION ), Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), + Source( detector, PanGestureDetector::LOCAL_VELOCITY ), PanConstraint( constraintData ) ) ); // Render and notify @@ -2034,10 +2045,12 @@ int UtcDaliPanGestureSetProperties(void) Vector2 screenPosition( 20.0f, 20.0f ); Vector2 screenDisplacement( 1.0f, 1.0f ); + Vector2 screenVelocity( 1.3f, 4.0f ); Vector2 localPosition( 21.0f, 21.0f ); Vector2 localDisplacement( 0.5f, 0.5f ); + Vector2 localVelocity( 1.5f, 2.5f ); - PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) ); + PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) ); DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION ); // Render and notify @@ -2049,6 +2062,8 @@ int UtcDaliPanGestureSetProperties(void) DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION ); DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION ); DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION ); + DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION ); constraintData.Reset(); END_TEST; } @@ -2075,8 +2090,10 @@ int UtcDaliPanGestureSetPropertiesAlreadyPanning(void) ConstraintData constraintData; actor.ApplyConstraint( Constraint::New( property, Source( detector, PanGestureDetector::SCREEN_POSITION ), Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ), + Source( detector, PanGestureDetector::SCREEN_VELOCITY ), Source( detector, PanGestureDetector::LOCAL_POSITION ), Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), + Source( detector, PanGestureDetector::LOCAL_VELOCITY ), PanConstraint( constraintData ) ) ); // Render and notify diff --git a/capi/dali/public-api/events/pan-gesture-detector.h b/capi/dali/public-api/events/pan-gesture-detector.h index 0ad3d76..ec25a46 100644 --- a/capi/dali/public-api/events/pan-gesture-detector.h +++ b/capi/dali/public-api/events/pan-gesture-detector.h @@ -58,14 +58,11 @@ struct PanGesture; */ class PanGestureDetector : public GestureDetector { -public: // Typedefs +public: - // Signals + // Typedefs typedef SignalV2< void (Actor, PanGesture) > DetectedSignalV2; ///< Pan gesture detected signal type - // Signal Names - static const char* const SIGNAL_PAN_DETECTED; ///< name "pan-detected" - // Directional Pan typedef std::pair< Radian, Radian > AngleThresholdPair; ///< Range of angles for a direction typedef std::vector< AngleThresholdPair > AngleContainer; ///< Group of angular thresholds for all directions @@ -79,12 +76,21 @@ public: // Typedefs static const Radian DEFAULT_THRESHOLD; ///< The default threshold is PI * 0.25 radians (or 45 degrees). - // Default Properties + /// @name Properties + /** @{ */ static const Property::Index SCREEN_POSITION; ///< name "screen-position", type VECTOR2 static const Property::Index SCREEN_DISPLACEMENT; ///< name "screen-displacement", type VECTOR2 + static const Property::Index SCREEN_VELOCITY; ///< name "screen-velocity", type VECTOR2 static const Property::Index LOCAL_POSITION; ///< name "local-position", type VECTOR2 static const Property::Index LOCAL_DISPLACEMENT; ///< name "local-displacement", type VECTOR2 + static const Property::Index LOCAL_VELOCITY; ///< name "local-velocity", type VECTOR2 static const Property::Index PANNING; ///< name "panning", type BOOLEAN + /** @} */ + + /// @name Signals + /** @{ */ + static const char* const SIGNAL_PAN_DETECTED; ///< name "pan-detected", @see DetectedSignal() + /** @} */ public: // Creation & Destruction diff --git a/dali/internal/event/events/pan-gesture-detector-impl.cpp b/dali/internal/event/events/pan-gesture-detector-impl.cpp index 5af07f1..9ea8920 100644 --- a/dali/internal/event/events/pan-gesture-detector-impl.cpp +++ b/dali/internal/event/events/pan-gesture-detector-impl.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -34,9 +35,11 @@ namespace Dali const Property::Index PanGestureDetector::SCREEN_POSITION = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT; const Property::Index PanGestureDetector::SCREEN_DISPLACEMENT = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 1; -const Property::Index PanGestureDetector::LOCAL_POSITION = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 2; -const Property::Index PanGestureDetector::LOCAL_DISPLACEMENT = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 3; -const Property::Index PanGestureDetector::PANNING = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 4; +const Property::Index PanGestureDetector::SCREEN_VELOCITY = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 2; +const Property::Index PanGestureDetector::LOCAL_POSITION = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 3; +const Property::Index PanGestureDetector::LOCAL_DISPLACEMENT = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 4; +const Property::Index PanGestureDetector::LOCAL_VELOCITY = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 5; +const Property::Index PanGestureDetector::PANNING = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 6; namespace Internal { @@ -46,24 +49,17 @@ namespace // Properties -const std::string DEFAULT_PROPERTY_NAMES[] = +PropertyDetails DEFAULT_PROPERTIES[] = { - "screen-position", - "screen-displacement", - "local-position", - "local-displacement", - "panning", -}; -const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_NAMES ) / sizeof( std::string ); - -const Property::Type DEFAULT_PROPERTY_TYPES[DEFAULT_PROPERTY_COUNT] = -{ - Property::VECTOR2, // SCREEN_POSITION - Property::VECTOR2, // SCREEN_DISPLACEMENT - Property::VECTOR2, // LOCAL_POSITION - Property::VECTOR2, // LOCAL_DISPLACEMENT - Property::BOOLEAN, // PANNING + { "screen-position", Property::VECTOR2, false, false, true }, + { "screen-displacement", Property::VECTOR2, false, false, true }, + { "screen-velocity", Property::VECTOR2, false, false, true }, + { "local-position", Property::VECTOR2, false, false, true }, + { "local-displacement", Property::VECTOR2, false, false, true }, + { "local-velocity", Property::VECTOR2, false, false, true }, + { "panning", Property::BOOLEAN, false, false, true }, }; +const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTIES ) / sizeof( DEFAULT_PROPERTIES[0] ); BaseHandle Create() { @@ -126,7 +122,7 @@ PanGestureDetector::PanGestureDetector() const int start = DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT; for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i ) { - ( *mDefaultPropertyLookup )[ DEFAULT_PROPERTY_NAMES[i] ] = i + start; + ( *mDefaultPropertyLookup )[ DEFAULT_PROPERTIES[i].name ] = i + start; } } } @@ -365,7 +361,7 @@ const std::string& PanGestureDetector::GetDefaultPropertyName( Property::Index i index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT; if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) ) { - return DEFAULT_PROPERTY_NAMES[ index ]; + return DEFAULT_PROPERTIES[ index ].name; } else { @@ -414,7 +410,7 @@ Property::Type PanGestureDetector::GetDefaultPropertyType(Property::Index index) index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT; if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) ) { - return DEFAULT_PROPERTY_TYPES[ index ]; + return DEFAULT_PROPERTIES[ index ].type; } else { @@ -465,6 +461,19 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co break; } + case Dali::PanGestureDetector::SCREEN_VELOCITY: + { + if(mSceneObject) + { + value = mSceneObject->GetScreenVelocityProperty().Get(); + } + else + { + value = Vector2(); + } + break; + } + case Dali::PanGestureDetector::LOCAL_POSITION: { if(mSceneObject) @@ -491,6 +500,19 @@ Property::Value PanGestureDetector::GetDefaultProperty(Property::Index index) co break; } + case Dali::PanGestureDetector::LOCAL_VELOCITY: + { + if(mSceneObject) + { + value = mSceneObject->GetLocalVelocityProperty().Get(); + } + else + { + value = Vector2(); + } + break; + } + case Dali::PanGestureDetector::PANNING: { if(mSceneObject) @@ -568,6 +590,12 @@ const PropertyInputImpl* PanGestureDetector::GetSceneObjectInputProperty( Proper break; } + case Dali::PanGestureDetector::SCREEN_VELOCITY: + { + property = &mSceneObject->GetScreenVelocityProperty(); + break; + } + case Dali::PanGestureDetector::LOCAL_POSITION: { property = &mSceneObject->GetLocalPositionProperty(); @@ -580,6 +608,12 @@ const PropertyInputImpl* PanGestureDetector::GetSceneObjectInputProperty( Proper break; } + case Dali::PanGestureDetector::LOCAL_VELOCITY: + { + property = &mSceneObject->GetLocalVelocityProperty(); + break; + } + case Dali::PanGestureDetector::PANNING: { property = &mSceneObject->GetPanningProperty(); diff --git a/dali/internal/update/gestures/scene-graph-pan-gesture.cpp b/dali/internal/update/gestures/scene-graph-pan-gesture.cpp index 5c2a1b5..4ee7ddd 100644 --- a/dali/internal/update/gestures/scene-graph-pan-gesture.cpp +++ b/dali/internal/update/gestures/scene-graph-pan-gesture.cpp @@ -75,7 +75,7 @@ void PanGesture::RemoveOldHistory(PanInfoHistory& panHistory, unsigned int curre } } -void PanGesture::SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut) +void PanGesture::SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut, unsigned int lastVSyncTime) { if( mInGesture ) { @@ -88,7 +88,13 @@ void PanGesture::SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut) // make current displacement relative to previous update-frame now. gestureOut.screen.displacement = gestureOut.screen.position - mLastEventGesture.screen.position; gestureOut.local.displacement = gestureOut.local.position - mLastEventGesture.local.position; + // calculate velocity relative to previous update-frame + unsigned int timeDiff( lastVSyncTime - mLastEventGesture.time ); + gestureOut.screen.velocity = gestureOut.screen.displacement / timeDiff; + gestureOut.local.velocity = gestureOut.local.displacement / timeDiff; } + + gestureOut.time = lastVSyncTime; } } @@ -246,8 +252,6 @@ void PanGesture::PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut, bool PanGesture::UpdateProperties( unsigned int lastVSyncTime, unsigned int nextVSyncTime ) { - bool propertiesUpdated( false ); - if( !mInGesture ) { // clear current pan history @@ -331,7 +335,7 @@ bool PanGesture::UpdateProperties( unsigned int lastVSyncTime, unsigned int next } case AVERAGE: { - SimpleAverageAlgorithm(justStarted, nextGesture); + SimpleAverageAlgorithm(justStarted, nextGesture, lastVSyncTime); // make latest gesture equal to current gesture after averaging updateProperties = true; break; @@ -362,10 +366,10 @@ bool PanGesture::UpdateProperties( unsigned int lastVSyncTime, unsigned int next mPanning.Set( mInGesture & !justFinished ); mScreenPosition.Set( nextGesture.screen.position ); mScreenDisplacement.Set( nextGesture.screen.displacement ); + mScreenVelocity.Set( nextGesture.screen.velocity ); mLocalPosition.Set( nextGesture.local.position ); mLocalDisplacement.Set( nextGesture.local.displacement ); - - propertiesUpdated = true; + mLocalVelocity.Set( nextGesture.local.velocity ); } if( mProfiling ) @@ -383,7 +387,7 @@ bool PanGesture::UpdateProperties( unsigned int lastVSyncTime, unsigned int next mProfiling->ClearData(); } - return propertiesUpdated; + return updateProperties; } const GesturePropertyBool& PanGesture::GetPanningProperty() const @@ -396,6 +400,11 @@ const GesturePropertyVector2& PanGesture::GetScreenPositionProperty() const return mScreenPosition; } +const GesturePropertyVector2& PanGesture::GetScreenVelocityProperty() const +{ + return mScreenVelocity; +} + const GesturePropertyVector2& PanGesture::GetScreenDisplacementProperty() const { return mScreenDisplacement; @@ -411,6 +420,11 @@ const GesturePropertyVector2& PanGesture::GetLocalDisplacementProperty() const return mLocalDisplacement; } +const GesturePropertyVector2& PanGesture::GetLocalVelocityProperty() const +{ + return mLocalVelocity; +} + void PanGesture::SetPredictionMode(PredictionMode mode) { mPredictionMode = mode; diff --git a/dali/internal/update/gestures/scene-graph-pan-gesture.h b/dali/internal/update/gestures/scene-graph-pan-gesture.h index fe0be5c..964379e 100644 --- a/dali/internal/update/gestures/scene-graph-pan-gesture.h +++ b/dali/internal/update/gestures/scene-graph-pan-gesture.h @@ -201,9 +201,11 @@ public: /** * USes last two gestures * + * @param[in] justStarted Whether the pan has just started. * @param[out] gestureOut Output gesture using average values from last two gestures + * @param[in] lastVSyncTime The time to set on gestureOut. */ - void SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut); + void SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut, unsigned int lastVSyncTime); /** * Uses elapsed time and time stamps @@ -235,6 +237,12 @@ public: const GesturePropertyVector2& GetScreenPositionProperty() const; /** + * Retrieves a reference to the screen velocity property. + * @return The screen velocity property. + */ + const GesturePropertyVector2& GetScreenVelocityProperty() const; + + /** * Retrieves a reference to the screen displacement property. * @return The screen displacement property. */ @@ -253,6 +261,12 @@ public: const GesturePropertyVector2& GetLocalDisplacementProperty() const; /** + * Retrieves a reference to the local velocity property. + * @return The local velocity property. + */ + const GesturePropertyVector2& GetLocalVelocityProperty() const; + + /** * @brief Sets the prediction mode of the pan gesture * * @param[in] mode The prediction mode @@ -293,8 +307,10 @@ private: GesturePropertyBool mPanning; ///< panning flag GesturePropertyVector2 mScreenPosition; ///< screen-position GesturePropertyVector2 mScreenDisplacement; ///< screen-displacement + GesturePropertyVector2 mScreenVelocity; ///< screen-velocity GesturePropertyVector2 mLocalPosition; ///< local-position GesturePropertyVector2 mLocalDisplacement; ///< local-displacement + GesturePropertyVector2 mLocalVelocity; ///< local-velocity PanInfo mGestures[PAN_GESTURE_HISTORY]; ///< Circular buffer storing the 4 most recent gestures. PanInfoHistory mPanHistory; -- 2.7.4