X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Fscrollable%2Fscroll-view%2Fscroll-view-impl.cpp;h=790c7f8a843a67e431cdccf8ca1b8e530961c440;hp=d0f05aedd753ccd94c2be3d756499bcab8ee5eaf;hb=f6be8012c03a25aca4a8403e4a0da31854a2ef69;hpb=73a843c989185d86282edb116aeac40a5f3eb865 diff --git a/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp index d0f05ae..790c7f8 100644 --- a/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp @@ -25,6 +25,14 @@ #include #include +//#define ENABLED_SCROLL_STATE_LOGGING + +#ifdef ENABLED_SCROLL_STATE_LOGGING +#define DALI_LOG_SCROLL_STATE(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ## args) +#else +#define DALI_LOG_SCROLL_STATE(format, args...) +#endif + // TODO: Change to two class system: // 1. DraggableActor (is an actor which can be dragged anywhere/scaled/rotated, can be set to range using the ruler) // 2. ScrollView (contains a draggable actor that can a) be dragged in the negative X, and Y domain, b) has a hitArea for touches) @@ -50,6 +58,7 @@ const unsigned long MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET( 150u ); const float DEFAULT_OVERSHOOT_ANIMATION_DURATION = 0.35f; // time in seconds const Vector2 OVERSCROLL_CLAMP(1.0f, 1.0f); // maximum overscroll allowed in pixels when overshoot indicator is being used const float TOUCH_DOWN_TIMER_INTERVAL = 100.0f; +const float DEFAULT_SCROLL_UPDATE_DISTANCE( 30.0f ); ///< Default distance to travel in pixels for scroll update signal // predefined effect values const Vector3 ANGLE_CAROUSEL_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f); @@ -434,12 +443,17 @@ struct OvershootXConstraint float operator()(const float& current, const PropertyInput& scrollPrePositionProperty, - const PropertyInput& scrollPostPositionProperty) + const PropertyInput& scrollPostPositionProperty, + const PropertyInput& canScrollProperty) { - const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3(); - const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3(); - float newOvershoot = scrollPrePosition.x - scrollPostPosition.x; - return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot; + if( canScrollProperty.GetBoolean() ) + { + const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3(); + const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3(); + float newOvershoot = scrollPrePosition.x - scrollPostPosition.x; + return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot; + } + return 0.0f; } float mMaxOvershoot; @@ -455,12 +469,17 @@ struct OvershootYConstraint float operator()(const float& current, const PropertyInput& scrollPrePositionProperty, - const PropertyInput& scrollPostPositionProperty) + const PropertyInput& scrollPostPositionProperty, + const PropertyInput& canScrollProperty) { - const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3(); - const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3(); - float newOvershoot = scrollPrePosition.y - scrollPostPosition.y; - return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot; + if( canScrollProperty.GetBoolean() ) + { + const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3(); + const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3(); + float newOvershoot = scrollPrePosition.y - scrollPostPosition.y; + return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot; + } + return 0.0f; } float mMaxOvershoot; @@ -578,7 +597,7 @@ ScrollView::ScrollView() mMinTouchesForPanning(1), mMaxTouchesForPanning(1), mLockAxis(LockPossible), - mRefreshIntervalMilliseconds(DEFAULT_REFRESH_INTERVAL_MILLISECONDS), + mScrollUpdateDistance(DEFAULT_SCROLL_UPDATE_DISTANCE), mOvershootDelay(1.0f), mMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT), mUserMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT), @@ -604,7 +623,9 @@ ScrollView::ScrollView() mWrapMode(false), mAxisAutoLock(false), mAlterChild(false), - mDefaultMaxOvershoot(true) + mDefaultMaxOvershoot(true), + mCanScrollHorizontal(true), + mCanScrollVertical(true) { SetRequiresMouseWheelEvents(true); } @@ -662,6 +683,8 @@ void ScrollView::OnInitialize() void ScrollView::OnControlStageConnection() { + DALI_LOG_SCROLL_STATE("[0x%X]", this); + if ( mSensitive ) { SetScrollSensitive( false ); @@ -676,11 +699,14 @@ void ScrollView::OnControlStageConnection() void ScrollView::OnControlStageDisconnection() { + DALI_LOG_SCROLL_STATE("[0x%X]", this); + StopAnimation(); } ScrollView::~ScrollView() { + DALI_LOG_SCROLL_STATE("[0x%X]", this); } AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const @@ -904,8 +930,8 @@ void ScrollView::SetRulerY(RulerPtr ruler) void ScrollView::UpdatePropertyDomain(const Vector3& size) { Actor self = Self(); - Vector3 min = self.GetProperty(mPropertyPositionMin); - Vector3 max = self.GetProperty(mPropertyPositionMax); + Vector3 min = mMinScroll; + Vector3 max = mMaxScroll; bool scrollPositionChanged = false; bool domainChanged = false; @@ -915,8 +941,8 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size) if(mRulerX->IsEnabled()) { const Toolkit::RulerDomain& rulerDomain = mRulerX->GetDomain(); - if( fabsf(min.x - rulerDomain.min) > Math::MACHINE_EPSILON_10000 - || fabsf(max.x - rulerDomain.max) > Math::MACHINE_EPSILON_10000 ) + if( fabsf(min.x - rulerDomain.min) > Math::MACHINE_EPSILON_100 + || fabsf(max.x - rulerDomain.max) > Math::MACHINE_EPSILON_100 ) { domainChanged = true; min.x = rulerDomain.min; @@ -929,18 +955,27 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size) scrollPositionChanged = true; mScrollPrePosition.x = Clamp(mScrollPrePosition.x, -(max.x - size.x), -min.x); } - if((fabsf(max.x - min.x) - size.x) > Math::MACHINE_EPSILON_10000) - { - canScrollHorizontal = true; - } } + if( (fabsf(rulerDomain.max - rulerDomain.min) - size.x) > Math::MACHINE_EPSILON_100 ) + { + canScrollHorizontal = true; + } + } + else if( fabs(min.x) > Math::MACHINE_EPSILON_100 + || fabs(max.x) > Math::MACHINE_EPSILON_100 ) + { + // need to reset to 0 + domainChanged = true; + min.x = 0.0f; + max.x = 0.0f; + canScrollHorizontal = false; } if(mRulerY->IsEnabled()) { const Toolkit::RulerDomain& rulerDomain = mRulerY->GetDomain(); - if( fabsf(min.y - rulerDomain.min) > Math::MACHINE_EPSILON_10000 - || fabsf(max.y - rulerDomain.max) > Math::MACHINE_EPSILON_10000 ) + if( fabsf(min.y - rulerDomain.min) > Math::MACHINE_EPSILON_100 + || fabsf(max.y - rulerDomain.max) > Math::MACHINE_EPSILON_100 ) { domainChanged = true; min.y = rulerDomain.min; @@ -953,20 +988,32 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size) scrollPositionChanged = true; mScrollPrePosition.y = Clamp(mScrollPrePosition.y, -(max.y - size.y), -min.y); } - if((fabsf(max.y - min.y) - size.y) > Math::MACHINE_EPSILON_10000) - { - canScrollVertical = true; - } + } + if( (fabsf(rulerDomain.max - rulerDomain.min) - size.y) > Math::MACHINE_EPSILON_100 ) + { + canScrollVertical = true; } } + else if( fabs(min.y) > Math::MACHINE_EPSILON_100 + || fabs(max.y) > Math::MACHINE_EPSILON_100 ) + { + // need to reset to 0 + domainChanged = true; + min.y = 0.0f; + max.y = 0.0f; + canScrollHorizontal = false; + } + // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update - if( self.GetProperty(mPropertyCanScrollVertical) != canScrollVertical ) + if( mCanScrollVertical != canScrollVertical ) { + mCanScrollVertical = canScrollVertical; self.SetProperty(mPropertyCanScrollVertical, canScrollVertical); } - if( self.GetProperty(mPropertyCanScrollHorizontal) != canScrollHorizontal ) + if( mCanScrollHorizontal != canScrollHorizontal ) { - self.SetProperty(mPropertyCanScrollHorizontal, canScrollVertical); + mCanScrollHorizontal = canScrollHorizontal; + self.SetProperty(mPropertyCanScrollHorizontal, canScrollHorizontal); } if( scrollPositionChanged ) { @@ -974,8 +1021,10 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size) } if( domainChanged ) { - self.SetProperty(mPropertyPositionMin, min ); - self.SetProperty(mPropertyPositionMax, max ); + mMinScroll = min; + mMaxScroll = max; + self.SetProperty(mPropertyPositionMin, mMinScroll ); + self.SetProperty(mPropertyPositionMax, mMaxScroll ); } } @@ -1002,6 +1051,8 @@ void ScrollView::SetScrollSensitive(bool sensitive) Actor self = Self(); PanGestureDetector panGesture( GetPanGestureDetector() ); + DALI_LOG_SCROLL_STATE("[0x%X] sensitive: before:[%d] setting[%d]", this, int(mSensitive), int(sensitive)); + if((!mSensitive) && (sensitive)) { mSensitive = sensitive; @@ -1010,8 +1061,7 @@ void ScrollView::SetScrollSensitive(bool sensitive) else if((mSensitive) && (!sensitive)) { // while the scroll view is panning, the state needs to be reset. - bool isPanning = self.GetProperty( mPropertyPanning ); - if ( isPanning ) + if ( mPanning ) { PanGesture cancelGesture( Gesture::Cancelled ); OnPan( cancelGesture ); @@ -1086,12 +1136,22 @@ void ScrollView::SetWrapMode(bool enable) int ScrollView::GetRefreshInterval() const { - return mRefreshIntervalMilliseconds; + return mScrollUpdateDistance; } void ScrollView::SetRefreshInterval(int milliseconds) { - mRefreshIntervalMilliseconds = milliseconds; + mScrollUpdateDistance = milliseconds; +} + +int ScrollView::GetScrollUpdateDistance() const +{ + return mScrollUpdateDistance; +} + +void ScrollView::SetScrollUpdateDistance(int distance) +{ + mScrollUpdateDistance = distance; } bool ScrollView::GetAxisAutoLock() const @@ -1212,22 +1272,42 @@ void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, floa void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration, DirectionBias horizontalBias, DirectionBias verticalBias) { + Actor self( Self() ); + // Guard against destruction during signal emission // Note that Emit() methods are called indirectly e.g. from within ScrollView::AnimateTo() Toolkit::ScrollView handle( GetOwner() ); + DALI_LOG_SCROLL_STATE("[0x%X] pos[%.2f,%.2f], scale[%.2f,%.2f], rot[%.2f], duration[%.2f] bias[%d, %d]", + this, position.x, position.y, scale.x, scale.y, rotation, duration, int(horizontalBias), int(verticalBias)); + Vector3 currentScrollPosition = GetCurrentScrollPosition(); - Self().SetProperty( mPropertyScrollStartPagePosition, currentScrollPosition ); + self.SetProperty( mPropertyScrollStartPagePosition, currentScrollPosition ); - if(mScrolling) // are we interrupting a current scroll? + if( mScrolling ) // are we interrupting a current scroll? { // set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete. mScrolling = false; + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); mScrollCompletedSignalV2.Emit( currentScrollPosition ); } - Self().SetProperty(mPropertyScrolling, true); + if( mPanning ) // are we interrupting a current pan? + { + DALI_LOG_SCROLL_STATE("[0x%X] Interrupting Pan, set to false", this ); + mPanning = false; + self.SetProperty( mPropertyPanning, false ); + + if( mScrollMainInternalPrePositionConstraint ) + { + self.RemoveConstraint(mScrollMainInternalPrePositionConstraint); + } + } + + self.SetProperty(mPropertyScrolling, true); mScrolling = true; + + DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); mScrollStartedSignalV2.Emit( currentScrollPosition ); bool animating = AnimateTo(-position, Vector3::ONE * duration, @@ -1244,9 +1324,20 @@ void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, floa if(!animating) { // if not animating, then this pan has completed right now. - Self().SetProperty(mPropertyScrolling, false); + self.SetProperty(mPropertyScrolling, false); mScrolling = false; - mScrollCompletedSignalV2.Emit( currentScrollPosition ); + + // If we have no duration, then in the next update frame, we will be at the position specified as we just set. + // In this scenario, we cannot return the currentScrollPosition as this is out-of-date and should instead return the requested final position + Vector3 completedPosition( currentScrollPosition ); + if( duration <= Math::MACHINE_EPSILON_10 ) + { + completedPosition = position; + } + + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 2 [%.2f, %.2f]", this, completedPosition.x, completedPosition.y); + SetScrollUpdateNotification(false); + mScrollCompletedSignalV2.Emit( completedPosition ); } } @@ -1263,6 +1354,9 @@ void ScrollView::ScrollTo(const Vector3& position, float duration) void ScrollView::ScrollTo(const Vector3& position, float duration, DirectionBias horizontalBias, DirectionBias verticalBias) { + DALI_LOG_SCROLL_STATE("[0x%X] position[%.2f, %.2f] duration[%.2f]", + this, position.x, position.y, duration, int(horizontalBias), int(verticalBias)); + TransformTo(position, mScrollPostScale, mScrollPostRotation, duration, horizontalBias, verticalBias); } @@ -1720,14 +1814,14 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat if(mRulerX->IsEnabled()) { - float dir = VectorInDomain(-mScrollPostPosition.x, -mScrollTargetPosition.x, rulerDomainX.min, rulerDomainX.max, horizontalBias); - mScrollTargetPosition.x = mScrollPostPosition.x + -dir; + float dir = VectorInDomain(-mScrollPrePosition.x, -mScrollTargetPosition.x, rulerDomainX.min, rulerDomainX.max, horizontalBias); + mScrollTargetPosition.x = mScrollPrePosition.x + -dir; } if(mRulerY->IsEnabled()) { - float dir = VectorInDomain(-mScrollPostPosition.y, -mScrollTargetPosition.y, rulerDomainY.min, rulerDomainY.max, verticalBias); - mScrollTargetPosition.y = mScrollPostPosition.y + -dir; + float dir = VectorInDomain(-mScrollPrePosition.y, -mScrollTargetPosition.y, rulerDomainY.min, rulerDomainY.max, verticalBias); + mScrollTargetPosition.y = mScrollPrePosition.y + -dir; } } @@ -1740,6 +1834,8 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat { self.SetProperty(mPropertyPrePosition, mScrollTargetPosition); mScrollPrePosition = mScrollTargetPosition; + mScrollPostPosition = mScrollTargetPosition; + WrapPosition(mScrollPostPosition); } } @@ -1764,7 +1860,7 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat mScrollPreScale = mScrollPostScale = scale; } } - StartRefreshTimer(); + SetScrollUpdateNotification(true); // Always send a snap event when AnimateTo is called. Toolkit::ScrollView::SnapEvent snapEvent; @@ -1774,6 +1870,7 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat snapEvent.rotation = rotation; snapEvent.duration = totalDuration; + DALI_LOG_SCROLL_STATE("[0x%X] mSnapStartedSignalV2 [%.2f, %.2f]", this, snapEvent.position.x, snapEvent.position.y); mSnapStartedSignalV2.Emit( snapEvent ); return (mScrollStateFlags & SCROLL_ANIMATION_FLAGS) != 0; @@ -1855,8 +1952,7 @@ Vector3 ScrollView::GetPropertyScale() const void ScrollView::HandleStoppedAnimation() { - // Animation has stopped, so stop sending the scroll-update signal. - CancelRefreshTimer(); + SetScrollUpdateNotification(false); } void ScrollView::HandleSnapAnimationFinished() @@ -1873,6 +1969,7 @@ void ScrollView::HandleSnapAnimationFinished() self.SetProperty(mPropertyPrePosition, mScrollPrePosition); Vector3 currentScrollPosition = GetCurrentScrollPosition(); + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 3 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); mScrollCompletedSignalV2.Emit( currentScrollPosition ); mDomainOffset += deltaPosition - mScrollPostPosition; @@ -1880,6 +1977,44 @@ void ScrollView::HandleSnapAnimationFinished() HandleStoppedAnimation(); } +void ScrollView::SetScrollUpdateNotification( bool enabled ) +{ + Actor self = Self(); + if( mScrollXUpdateNotification ) + { + // disconnect now to avoid a notification before removed from update thread + mScrollXUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification); + self.RemovePropertyNotification(mScrollXUpdateNotification); + mScrollXUpdateNotification.Reset(); + } + if( enabled ) + { + mScrollXUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 0, StepCondition(mScrollUpdateDistance, 0.0f)); + mScrollXUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification ); + } + if( mScrollYUpdateNotification ) + { + // disconnect now to avoid a notification before removed from update thread + mScrollYUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification); + self.RemovePropertyNotification(mScrollYUpdateNotification); + mScrollYUpdateNotification.Reset(); + } + if( enabled ) + { + mScrollYUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 1, StepCondition(mScrollUpdateDistance, 0.0f)); + mScrollYUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification ); + } +} + +void ScrollView::OnScrollUpdateNotification(Dali::PropertyNotification& source) +{ + // Guard against destruction during signal emission + Toolkit::ScrollView handle( GetOwner() ); + + Vector3 currentScrollPosition = GetCurrentScrollPosition(); + mScrollUpdatedSignalV2.Emit( currentScrollPosition ); +} + bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { Dali::BaseHandle handle( object ); @@ -1957,6 +2092,7 @@ void ScrollView::OnPropertySet( Property::Index index, Property::Value propertyV } else if( index == mPropertyPrePosition ) { + DALI_LOG_SCROLL_STATE("[0x%X]", this); propertyValue.Get(mScrollPrePosition); } } @@ -1996,6 +2132,7 @@ bool ScrollView::OnTouchDownTimeout() UpdateLocalScrollProperties(); Vector3 currentScrollPosition = GetCurrentScrollPosition(); + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 4 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); mScrollCompletedSignalV2.Emit( currentScrollPosition ); } } @@ -2223,9 +2360,14 @@ void ScrollView::OnScrollAnimationFinished( Animation& source ) scrollingFinished = true; } mInternalXAnimation.Reset(); - - // erase current state flags - mScrollStateFlags &= ~SCROLL_X_STATE_MASK; + // wrap pre scroll x position and set it + if( mWrapMode ) + { + const RulerDomain rulerDomain = mRulerX->GetDomain(); + mScrollPrePosition.x = -WrapInDomain(-mScrollPrePosition.x, rulerDomain.min, rulerDomain.max); + handle.SetProperty(mPropertyPrePosition, mScrollPrePosition); + } + SnapInternalXTo(mScrollPostPosition.x); } if( source == mInternalYAnimation ) @@ -2235,9 +2377,14 @@ void ScrollView::OnScrollAnimationFinished( Animation& source ) scrollingFinished = true; } mInternalYAnimation.Reset(); - - // erase current state flags - mScrollStateFlags &= ~SCROLL_Y_STATE_MASK; + if( mWrapMode ) + { + // wrap pre scroll y position and set it + const RulerDomain rulerDomain = mRulerY->GetDomain(); + mScrollPrePosition.y = -WrapInDomain(-mScrollPrePosition.y, rulerDomain.min, rulerDomain.max); + handle.SetProperty(mPropertyPrePosition, mScrollPrePosition); + } + SnapInternalYTo(mScrollPostPosition.y); } if(scrollingFinished) @@ -2246,6 +2393,71 @@ void ScrollView::OnScrollAnimationFinished( Animation& source ) } } +void ScrollView::OnSnapInternalPositionFinished( Animation& source ) +{ + Actor self = Self(); + UpdateLocalScrollProperties(); + if( source == mInternalXAnimation ) + { + // clear internal x animation flags + mScrollStateFlags &= ~SCROLL_X_STATE_MASK; + mInternalXAnimation.Reset(); + WrapPosition(mScrollPrePosition); + } + if( source == mInternalYAnimation ) + { + mScrollStateFlags &= ~SCROLL_Y_STATE_MASK; + mInternalYAnimation.Reset(); + WrapPosition(mScrollPrePosition); + } +} + +void ScrollView::SnapInternalXTo(float position) +{ + Actor self = Self(); + + StopAnimation(mInternalXAnimation); + + // erase current state flags + mScrollStateFlags &= ~SCROLL_X_STATE_MASK; + + // if internal x not equal to inputed parameter, animate it + float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration); + if( duration > Math::MACHINE_EPSILON_1 ) + { + mInternalXAnimation = Animation::New(duration); + mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished); + mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position); + mInternalXAnimation.Play(); + + // add internal animation state flag + mScrollStateFlags |= SnappingInternalX; + } +} + +void ScrollView::SnapInternalYTo(float position) +{ + Actor self = Self(); + + StopAnimation(mInternalYAnimation); + + // erase current state flags + mScrollStateFlags &= ~SCROLL_Y_STATE_MASK; + + // if internal y not equal to inputed parameter, animate it + float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration); + if( duration > Math::MACHINE_EPSILON_1 ) + { + mInternalYAnimation = Animation::New(duration); + mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished); + mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position); + mInternalYAnimation.Play(); + + // add internal animation state flag + mScrollStateFlags |= SnappingInternalY; + } +} + void ScrollView::GestureStarted() { // we handle the first gesture. @@ -2281,6 +2493,7 @@ void ScrollView::GestureStarted() mScrolling = false; // send negative scroll position since scroll internal scroll position works as an offset for actors, // give applications the position within the domain from the scroll view's anchor position + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 5 [%.2f, %.2f]", this, -mScrollPostPosition.x, -mScrollPostPosition.y); mScrollCompletedSignalV2.Emit( -mScrollPostPosition ); } } @@ -2320,6 +2533,8 @@ void ScrollView::OnPan(PanGesture gesture) if(!mSensitive) { + DALI_LOG_SCROLL_STATE("[0x%X] Pan Ignored, Insensitive", this); + // If another callback on the same original signal disables sensitivity, // this callback will still be called, so we must suppress it. return; @@ -2330,6 +2545,7 @@ void ScrollView::OnPan(PanGesture gesture) { case Gesture::Started: { + DALI_LOG_SCROLL_STATE("[0x%X] Pan Started", this); UpdateLocalScrollProperties(); GestureStarted(); mPanning = true; @@ -2342,21 +2558,40 @@ void ScrollView::OnPan(PanGesture gesture) case Gesture::Continuing: { - GestureContinuing(gesture.screenDisplacement, Vector2::ZERO, 0.0f); + if ( mPanning ) + { + DALI_LOG_SCROLL_STATE("[0x%X] Pan Continuing", this); + GestureContinuing(gesture.screenDisplacement, Vector2::ZERO, 0.0f); + } + else + { + // If we do not think we are panning, then we should not do anything here + return; + } break; } case Gesture::Finished: case Gesture::Cancelled: { - UpdateLocalScrollProperties(); - mLastVelocity = gesture.velocity; - mPanning = false; - self.SetProperty( mPropertyPanning, false ); + if ( mPanning ) + { + DALI_LOG_SCROLL_STATE("[0x%X] Pan %s", this, ( ( gesture.state == Gesture::Finished ) ? "Finished" : "Cancelled" ) ); + + UpdateLocalScrollProperties(); + mLastVelocity = gesture.velocity; + mPanning = false; + self.SetProperty( mPropertyPanning, false ); - if( mScrollMainInternalPrePositionConstraint ) + if( mScrollMainInternalPrePositionConstraint ) + { + self.RemoveConstraint(mScrollMainInternalPrePositionConstraint); + } + } + else { - self.RemoveConstraint(mScrollMainInternalPrePositionConstraint); + // If we do not think we are panning, then we should not do anything here + return; } break; } @@ -2382,6 +2617,7 @@ void ScrollView::OnGestureEx(Gesture::State state) Vector3 currentScrollPosition = GetCurrentScrollPosition(); Self().SetProperty(mPropertyScrolling, true); mScrolling = true; + DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); mScrollStartedSignalV2.Emit( currentScrollPosition ); } else if( (state == Gesture::Finished) || @@ -2416,9 +2652,20 @@ void ScrollView::FinishTransform() if(!animating) { // if not animating, then this pan has completed right now. + SetScrollUpdateNotification(false); mScrolling = false; Self().SetProperty(mPropertyScrolling, false); + + if( fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10 ) + { + SnapInternalXTo(mScrollTargetPosition.x); + } + if( fabs(mScrollPrePosition.y - mScrollTargetPosition.y) > Math::MACHINE_EPSILON_10 ) + { + SnapInternalYTo(mScrollTargetPosition.y); + } Vector3 currentScrollPosition = GetCurrentScrollPosition(); + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 6 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); mScrollCompletedSignalV2.Emit( currentScrollPosition ); } } @@ -2641,12 +2888,14 @@ void ScrollView::SetOvershootConstraintsEnabled(bool enabled) Constraint constraint = Constraint::New( mPropertyOvershootX, LocalSource( mPropertyPrePosition ), LocalSource( mPropertyPosition ), + LocalSource( mPropertyCanScrollHorizontal ), OvershootXConstraint(mMaxOvershoot.x) ); mScrollMainInternalOvershootXConstraint = self.ApplyConstraint( constraint ); constraint = Constraint::New( mPropertyOvershootY, LocalSource( mPropertyPrePosition ), LocalSource( mPropertyPosition ), + LocalSource( mPropertyCanScrollVertical ), OvershootYConstraint(mMaxOvershoot.y) ); mScrollMainInternalOvershootYConstraint = self.ApplyConstraint( constraint ); } @@ -2701,42 +2950,6 @@ void ScrollView::SetInternalConstraints() ApplyConstraintToBoundActors(constraint); } -void ScrollView::StartRefreshTimer() -{ - if(mRefreshIntervalMilliseconds > 0) - { - if (!mRefreshTimer) - { - mRefreshTimer = Timer::New( mRefreshIntervalMilliseconds ); - mRefreshTimer.TickSignal().Connect( this, &ScrollView::OnRefreshTick ); - } - - if (!mRefreshTimer.IsRunning()) - { - mRefreshTimer.Start(); - } - } -} - -void ScrollView::CancelRefreshTimer() -{ - if (mRefreshTimer) - { - mRefreshTimer.Stop(); - } -} - -bool ScrollView::OnRefreshTick() -{ - // Guard against destruction during signal emission - Toolkit::ScrollView handle( GetOwner() ); - - Vector3 currentScrollPosition = GetCurrentScrollPosition(); - mScrollUpdatedSignalV2.Emit( currentScrollPosition ); - - return true; -} - } // namespace Internal } // namespace Toolkit