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=9d465e4db2a05ddf9d7725e3c61d2b060eb0810f;hp=d0f05aedd753ccd94c2be3d756499bcab8ee5eaf;hb=fb4c5271bfb173434c5ad0e3e0743d9da688eb16;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..9d465e4 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 @@ -434,12 +434,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 +460,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; @@ -929,10 +939,10 @@ 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_10000 ) + { + canScrollHorizontal = true; } } @@ -953,10 +963,10 @@ 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_10000 ) + { + canScrollVertical = true; } } // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update @@ -966,7 +976,7 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size) } if( self.GetProperty(mPropertyCanScrollHorizontal) != canScrollHorizontal ) { - self.SetProperty(mPropertyCanScrollHorizontal, canScrollVertical); + self.SetProperty(mPropertyCanScrollHorizontal, canScrollHorizontal); } if( scrollPositionChanged ) { @@ -2223,9 +2233,7 @@ void ScrollView::OnScrollAnimationFinished( Animation& source ) scrollingFinished = true; } mInternalXAnimation.Reset(); - - // erase current state flags - mScrollStateFlags &= ~SCROLL_X_STATE_MASK; + SnapInternalXTo(mScrollPostPosition.x); } if( source == mInternalYAnimation ) @@ -2235,9 +2243,7 @@ void ScrollView::OnScrollAnimationFinished( Animation& source ) scrollingFinished = true; } mInternalYAnimation.Reset(); - - // erase current state flags - mScrollStateFlags &= ~SCROLL_Y_STATE_MASK; + SnapInternalYTo(mScrollPostPosition.y); } if(scrollingFinished) @@ -2246,6 +2252,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. @@ -2641,12 +2712,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 ); }