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=e60962f0b4bf4cc2e8b249d8487a103fe1840aa2;hp=b5a0751b8d79657dacbb467f1b8eac4a45fb5334;hb=97b1d370bbe662d6f2b813252b281e77926aa037;hpb=a81e6cdec136b728115431822a2ff3f60e279045 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 b5a0751..e60962f 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 @@ -19,7 +19,11 @@ #include // EXTERNAL INCLUDES +#include +#include #include +#include +#include #include // INTERNAL INCLUDES @@ -72,27 +76,6 @@ const Vector2 ANGLE_OUTER_CUBE_SWING(Math::PI * 0.5f, Math::PI * 0.5f); ///< ou // Helpers //////////////////////////////////////////////////////////////////////////////////////// -// TODO: GetAngle for Vector2 can be moved. -// GetAngle for Vector3 needs to be measured against a normal/plane. - -/** - * @param[in] vector The 3D vector to be measured - * @return angle in radians from 0 to 2PI - */ -float GetAngle(const Vector3& vector) -{ - return atan2(vector.y, vector.x) + Math::PI; -} - -/** - * @param[in] vector The 2D vector to be measured - * @return angle in radians from 0 to 2PI - */ -float GetAngle(const Vector2& vector) -{ - return atan2(vector.y, vector.x) + Math::PI; -} - /** * Find the vector (distance) from (a) to (b) * in domain (start) to (end) @@ -276,13 +259,15 @@ ScrollView::LockAxis GetLockAxis(const Vector2& panDelta, ScrollView::LockAxis c */ struct InternalPrePositionConstraint { - InternalPrePositionConstraint(const Vector2& initialPanMask, + InternalPrePositionConstraint(const Vector2& initialPanPosition, + const Vector2& initialPanMask, bool axisAutoLock, float axisAutoLockGradient, ScrollView::LockAxis initialLockAxis, const Vector2& maxOvershoot, const RulerDomain& domainX, const RulerDomain& domainY) - : mInitialPanMask(initialPanMask), + : mLocalStart(initialPanPosition), + mInitialPanMask(initialPanMask), mDomainMin( -domainX.min, -domainY.min ), mDomainMax( -domainX.max, -domainY.max ), mMaxOvershoot(maxOvershoot), @@ -297,7 +282,6 @@ struct InternalPrePositionConstraint Vector3 operator()(const Vector3& current, const PropertyInput& gesturePositionProperty, - const PropertyInput& gestureDisplacementProperty, const PropertyInput& sizeProperty) { Vector3 scrollPostPosition = current; @@ -305,7 +289,6 @@ struct InternalPrePositionConstraint if(!mWasPanning) { - mLocalStart = gesturePositionProperty.GetVector2() - gestureDisplacementProperty.GetVector2(); mPrePosition = current; mCurrentPanMask = mInitialPanMask; mWasPanning = true; @@ -487,26 +470,6 @@ struct OvershootYConstraint }; /** - * When panning, this constraint updates the X property, otherwise - * it has no effect on the X property. - */ -float InternalXConstraint(const float& current, - const PropertyInput& scrollPosition) -{ - return scrollPosition.GetVector3().x; -} - -/** - * When panning, this constraint updates the Y property, otherwise - * it has no effect on the Y property. - */ -float InternalYConstraint(const float& current, - const PropertyInput& scrollPosition) -{ - return scrollPosition.GetVector3().y; -} - -/** * Internal Position-Delta Property Constraint. * * Generates position-delta property based on scroll-position + scroll-offset properties. @@ -766,84 +729,6 @@ void ScrollView::ApplyEffect(Toolkit::ScrollViewEffect effect) GetImpl(effect).Attach(self); } -Toolkit::ScrollViewEffect ScrollView::ApplyEffect(Toolkit::ScrollView::PageEffect effect) -{ - Toolkit::ScrollViewEffect scrollEffect; - switch(effect) - { - case Toolkit::ScrollView::PageEffectNone: - { - break; - } - case Toolkit::ScrollView::PageEffectOuterCube: - { - Toolkit::ScrollViewCustomEffect customEffect; - scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New(); - Vector2 pageSize = Stage::GetCurrent().GetSize(); - // set the page translation to the slide off distance, also add an extra value to space the pages, having a smaller spacing on translationOut will allow the spacing to reduce over time - // the page moving onto screen will start 50.0f further out (1.0f * 50.0f) and the spacing will reduce as its position reaches the centre (0.0f * 50.0f) - // the page moving off screen will slowly build a spacing from 0.0f to 20.0f - // the spacing from each page is added together for the final spacing between the two pages. - customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0) + Vector3(50.0f, 50.0f, 0.0f), Vector3(pageSize.x, pageSize.y, 0) + Vector3(20.0f, 20.0f, 0.0f)); - customEffect.SetSwingAngleOut(ANGLE_CUSTOM_CUBE_SWING.x, Vector3(0.0f, -1.0f, 0.0f)); - customEffect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT); - customEffect.SetOpacityThreshold(0.7f); - break; - } - case Toolkit::ScrollView::PageEffectDepth: - { - Toolkit::ScrollViewCustomEffect customEffect; - scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New(); - break; - } - case Toolkit::ScrollView::PageEffectInnerCube: - { - Toolkit::ScrollViewCustomEffect customEffect; - scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New(); - customEffect.SetPageSpacing(Vector2(30.0f, 30.0f)); - customEffect.SetAngledOriginPageRotation(ANGLE_CUBE_PAGE_ROTATE); - customEffect.SetSwingAngle(ANGLE_CUBE_PAGE_ROTATE.x, Vector3(0,-1,0)); - customEffect.SetOpacityThreshold(0.5f); - break; - } - case Toolkit::ScrollView::PageEffectCarousel: - { - Toolkit::ScrollViewCustomEffect customEffect; - scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New(); - customEffect.SetPageTranslation(Vector3(0,0,0), Vector3(-30, 0, 0)); - customEffect.SetPageSpacing(Vector2(60.0f, 60.0f)); - customEffect.SetAngledOriginPageRotation(-ANGLE_CUBE_PAGE_ROTATE); - customEffect.SetOpacityThreshold(0.2f, 0.6f); - break; - } - case Toolkit::ScrollView::PageEffectSpiral: - { - Toolkit::ScrollViewCustomEffect customEffect; - scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New(); - - Vector2 pageSize = Stage::GetCurrent().GetSize(); - customEffect.SetSwingAngle(-ANGLE_SPIRAL_SWING_IN.x, Vector3(0.0f, -1.0f, 0.0f), ANGLE_SPIRAL_SWING_OUT.x, Vector3(0.0f, -1.0f, 0.0f)); - //customEffect.SetSwingAngleAlphaFunctionOut(AlphaFunctions::EaseOut); - customEffect.SetSwingAnchor(AnchorPoint::CENTER_RIGHT); - customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0) + Vector3(100.0f, 100.0f, 0.0f), Vector3(pageSize.x, pageSize.y, -pageSize.y * 2.0f) * 0.33f); - //customEffect.SetPageTranslateAlphaFunctionOut(AlphaFunctions::EaseOut); - customEffect.SetOpacityThreshold(0.75f, 0.6f); - customEffect.SetOpacityAlphaFunctionIn(AlphaFunctions::EaseInOut); - break; - } - default: - { - DALI_ASSERT_DEBUG(0 && "unknown scroll view effect"); - } - } - RemoveConstraintsFromChildren(); - if(scrollEffect) - { - ApplyEffect(scrollEffect); - } - return scrollEffect; -} - void ScrollView::RemoveEffect(Toolkit::ScrollViewEffect effect) { Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self()); @@ -994,7 +879,7 @@ void ScrollView::UpdatePropertyDomain(const Vector3& size) domainChanged = true; min.y = 0.0f; max.y = 0.0f; - canScrollHorizontal = false; + canScrollVertical = false; } // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update @@ -1113,16 +998,6 @@ void ScrollView::SetWrapMode(bool enable) Self().SetProperty(mPropertyWrap, enable); } -int ScrollView::GetRefreshInterval() const -{ - return mScrollUpdateDistance; -} - -void ScrollView::SetRefreshInterval(int milliseconds) -{ - mScrollUpdateDistance = milliseconds; -} - int ScrollView::GetScrollUpdateDistance() const { return mScrollUpdateDistance; @@ -1259,10 +1134,10 @@ Vector3 ScrollView::GetDomainSize() const void ScrollView::TransformTo(const Vector3& position, DirectionBias horizontalBias, DirectionBias verticalBias) { - TransformTo(position, mSnapDuration, horizontalBias, verticalBias); + TransformTo(position, mSnapDuration, mSnapAlphaFunction, horizontalBias, verticalBias); } -void ScrollView::TransformTo(const Vector3& position, float duration, +void ScrollView::TransformTo(const Vector3& position, float duration, AlphaFunction alpha, DirectionBias horizontalBias, DirectionBias verticalBias) { Actor self( Self() ); @@ -1305,7 +1180,7 @@ void ScrollView::TransformTo(const Vector3& position, float duration, mScrollStartedSignalV2.Emit( currentScrollPosition ); bool animating = AnimateTo(-position, Vector3::ONE * duration, - mSnapAlphaFunction, + alpha, true, horizontalBias, verticalBias, @@ -1341,13 +1216,22 @@ void ScrollView::ScrollTo(const Vector3& position, float duration) ScrollTo(position, duration, DirectionBiasNone, DirectionBiasNone); } +void ScrollView::ScrollTo(const Vector3& position, float duration, AlphaFunction alpha) +{ + ScrollTo(position, duration, alpha, DirectionBiasNone, DirectionBiasNone); +} + 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)); + ScrollTo(position, duration, mSnapAlphaFunction, horizontalBias, verticalBias); +} - TransformTo(position, duration, horizontalBias, verticalBias); +void ScrollView::ScrollTo(const Vector3& position, float duration, AlphaFunction alpha, + 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, duration, alpha, horizontalBias, verticalBias); } void ScrollView::ScrollTo(unsigned int page) @@ -2013,21 +1897,7 @@ void ScrollView::OnChildRemove(Actor& child) void ScrollView::OnPropertySet( Property::Index index, Property::Value propertyValue ) { Actor self = Self(); - if( index == mPropertyX ) - { - self.GetProperty(mPropertyPrePosition).Get(mScrollPrePosition); - propertyValue.Get(mScrollPrePosition.x); - DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y ); - self.SetProperty(mPropertyPrePosition, mScrollPrePosition); - } - else if( index == mPropertyY ) - { - self.GetProperty(mPropertyPrePosition).Get(mScrollPrePosition); - propertyValue.Get(mScrollPrePosition.y); - DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y ); - self.SetProperty(mPropertyPrePosition, mScrollPrePosition); - } - else if( index == mPropertyPrePosition ) + if( index == mPropertyPrePosition ) { DALI_LOG_SCROLL_STATE("[0x%X]: mPropertyPrePosition[%.2f, %.2f]", this, propertyValue.Get().x, propertyValue.Get().y); propertyValue.Get(mScrollPrePosition); @@ -2487,7 +2357,7 @@ void ScrollView::GestureContinuing(const Vector2& panDelta) // TODO: Upgrade to use a more powerful gesture detector (one that supports multiple touches on pan - so works as pan and flick gesture) // BUG: Gesture::Finished doesn't always return velocity on release (due to // timeDelta between last two events being 0 sometimes, or posiiton being the same) -void ScrollView::OnPan(PanGesture gesture) +void ScrollView::OnPan( const PanGesture& gesture ) { // Guard against destruction during signal emission // Note that Emit() methods are called indirectly e.g. from within ScrollView::OnGestureEx() @@ -2508,6 +2378,7 @@ void ScrollView::OnPan(PanGesture gesture) case Gesture::Started: { DALI_LOG_SCROLL_STATE("[0x%X] Pan Started", this); + mPanStartPosition = gesture.position - gesture.displacement; UpdateLocalScrollProperties(); GestureStarted(); mPanning = true; @@ -2741,8 +2612,6 @@ void ScrollView::UpdateMainInternalConstraint() self.RemoveConstraint(mScrollMainInternalDeltaConstraint); self.RemoveConstraint(mScrollMainInternalFinalConstraint); self.RemoveConstraint(mScrollMainInternalRelativeConstraint); - self.RemoveConstraint(mScrollMainInternalXConstraint); - self.RemoveConstraint(mScrollMainInternalYConstraint); } if( mScrollMainInternalPrePositionConstraint ) { @@ -2769,9 +2638,8 @@ void ScrollView::UpdateMainInternalConstraint() { constraint = Constraint::New( mPropertyPrePosition, Source( detector, PanGestureDetector::LOCAL_POSITION ), - Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ), Source( self, Actor::SIZE ), - InternalPrePositionConstraint( initialPanMask, mAxisAutoLock, mAxisAutoLockGradient, mLockAxis, mMaxOvershoot, mRulerX->GetDomain(), mRulerY->GetDomain() ) ); + InternalPrePositionConstraint( mPanStartPosition, initialPanMask, mAxisAutoLock, mAxisAutoLockGradient, mLockAxis, mMaxOvershoot, mRulerX->GetDomain(), mRulerY->GetDomain() ) ); mScrollMainInternalPrePositionConstraint = self.ApplyConstraint( constraint ); } @@ -2807,16 +2675,6 @@ void ScrollView::UpdateMainInternalConstraint() InternalRelativePositionConstraint ); mScrollMainInternalRelativeConstraint = self.ApplyConstraint( constraint ); - constraint = Constraint::New( mPropertyX, - LocalSource( mPropertyPrePosition ), - InternalXConstraint ); - mScrollMainInternalXConstraint = self.ApplyConstraint( constraint ); - - constraint = Constraint::New( mPropertyY, - LocalSource( mPropertyPrePosition ), - InternalYConstraint ); - mScrollMainInternalYConstraint = self.ApplyConstraint( constraint ); - // When panning we want to make sure overshoot values are affected by pre position and post position SetOvershootConstraintsEnabled(!mWrapMode); }