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=ff6fbb944a168c4fce23800ce30ef489f1d79d5c;hp=277936926ef949b850113bf36192e3095f17605f;hb=c708912335770047488e65100410cfc71ab15854;hpb=63106d0a9407c87ff624f4b93e2627a0c7cc1e2a 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 2779369..ff6fbb9 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 @@ -15,21 +15,30 @@ * */ -// INTERNAL INCLUDES +// CLASS HEADER +#include + +// EXTERNAL INCLUDES #include +#include +// INTERNAL INCLUDES #include #include -#include #include #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) +// 1. DraggableActor (is an actor which can be dragged anywhere, 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) -// TODO: Rotation -// TODO: Asymetrical scaling // TODO: external components (page and status overlays). // TODO: Orientation. // TODO: upgrade Vector2/3 to support returning Unit vectors, normals, & cross product (dot product is already provided) @@ -40,16 +49,18 @@ namespace { const int DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 50; ///< Refresh rate TODO: Animation should have an update signal (and see item-view-impl) -const float FLICK_SPEED_THRESHOLD = 500.0f; ///< Flick threshold in pixels/ms +const Vector2 DEFAULT_MIN_FLICK_DISTANCE(30.0f, 30.0f); ///< minimum distance for pan before flick allowed +const float DEFAULT_MIN_FLICK_SPEED_THRESHOLD(500.0f); ///< Minimum pan speed required for flick in pixels/s const float FREE_FLICK_SPEED_THRESHOLD = 200.0f; ///< Free-Flick threshold in pixels/ms const float AUTOLOCK_AXIS_MINIMUM_DISTANCE2 = 100.0f; ///< Auto-lock axis after minimum distance squared. -const float FLICK_ORTHO_ANGLE_RANGE = 60.0f; ///< degrees. (if >45, then supports diagonal flicking) +const float FLICK_ORTHO_ANGLE_RANGE = 75.0f; ///< degrees. (if >45, then supports diagonal flicking) const unsigned int MAXIMUM_NUMBER_OF_VALUES = 5; ///< Number of values to use for weighted pan calculation. const Vector2 DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION = Vector2(0.17f, 0.1f); ///< The step of horizontal scroll distance in the proportion of stage size for each mouse wheel event received. 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); @@ -61,27 +72,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) @@ -262,17 +252,18 @@ ScrollView::LockAxis GetLockAxis(const Vector2& panDelta, ScrollView::LockAxis c * Generates position property based on current position + gesture displacement. * Or generates position property based on positionX/Y. * Note: This is the position prior to any clamping at scroll boundaries. - * TODO: Scale & Rotation Transforms. */ 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), @@ -287,7 +278,6 @@ struct InternalPrePositionConstraint Vector3 operator()(const Vector3& current, const PropertyInput& gesturePositionProperty, - const PropertyInput& gestureDisplacementProperty, const PropertyInput& sizeProperty) { Vector3 scrollPostPosition = current; @@ -295,7 +285,6 @@ struct InternalPrePositionConstraint if(!mWasPanning) { - mLocalStart = gesturePositionProperty.GetVector2() - gestureDisplacementProperty.GetVector2(); mPrePosition = current; mCurrentPanMask = mInitialPanMask; mWasPanning = true; @@ -434,12 +423,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,38 +449,23 @@ 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; }; /** - * 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. @@ -571,14 +550,11 @@ ScrollView::ScrollView() : ScrollBase(), mTouchDownTime(0u), mGestureStackDepth(0), - mRotationDelta(0.0f), mScrollStateFlags(0), - mScrollPreRotation(0.0f), - mScrollPostRotation(0.0f), 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), @@ -586,6 +562,8 @@ ScrollView::ScrollView() mSnapOvershootAlphaFunction(AlphaFunctions::EaseOut), mSnapDuration(Toolkit::ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION), mSnapAlphaFunction(AlphaFunctions::EaseOut), + mMinFlickDistance(DEFAULT_MIN_FLICK_DISTANCE), + mFlickSpeedThreshold(DEFAULT_MIN_FLICK_SPEED_THRESHOLD), mFlickDuration(Toolkit::ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION), mFlickAlphaFunction(AlphaFunctions::EaseOut), mAxisAutoLockGradient(Toolkit::ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT), @@ -604,7 +582,9 @@ ScrollView::ScrollView() mWrapMode(false), mAxisAutoLock(false), mAlterChild(false), - mDefaultMaxOvershoot(true) + mDefaultMaxOvershoot(true), + mCanScrollHorizontal(true), + mCanScrollVertical(true) { SetRequiresMouseWheelEvents(true); } @@ -628,8 +608,6 @@ void ScrollView::OnInitialize() RegisterProperties(); mScrollPostPosition = mScrollPrePosition = Vector3::ZERO; - mScrollPostScale = mScrollPreScale = Vector3::ONE; - mScrollPostRotation = mScrollPreRotation = 0.0f; mMouseWheelScrollDistanceStep = Stage::GetCurrent().GetSize() * DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION; @@ -645,13 +623,8 @@ void ScrollView::OnInitialize() // By default we'll allow the user to freely drag the scroll view, // while disabling the other rulers. RulerPtr ruler = new DefaultRuler(); - RulerPtr rulerDisabled = new DefaultRuler(); - rulerDisabled->Disable(); mRulerX = ruler; mRulerY = ruler; - mRulerScaleX = rulerDisabled; - mRulerScaleY = rulerDisabled; - mRulerRotation = rulerDisabled; EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator); @@ -662,6 +635,8 @@ void ScrollView::OnInitialize() void ScrollView::OnControlStageConnection() { + DALI_LOG_SCROLL_STATE("[0x%X]", this); + if ( mSensitive ) { SetScrollSensitive( false ); @@ -676,11 +651,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 +882,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 +893,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 +907,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,55 +940,54 @@ 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; + canScrollVertical = 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 ) { + DALI_LOG_SCROLL_STATE("[0x%X] Domain Changed, setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y ); self.SetProperty(mPropertyPrePosition, mScrollPrePosition); } if( domainChanged ) { - self.SetProperty(mPropertyPositionMin, min ); - self.SetProperty(mPropertyPositionMax, max ); + mMinScroll = min; + mMaxScroll = max; + self.SetProperty(mPropertyPositionMin, mMinScroll ); + self.SetProperty(mPropertyPositionMax, mMaxScroll ); } } -void ScrollView::SetRulerScaleX(RulerPtr ruler) -{ - mRulerScaleX = ruler; - UpdateMainInternalConstraint(); -} - -void ScrollView::SetRulerScaleY(RulerPtr ruler) -{ - mRulerScaleY = ruler; - UpdateMainInternalConstraint(); -} - -void ScrollView::SetRulerRotation(RulerPtr ruler) -{ - mRulerRotation = ruler; - UpdateMainInternalConstraint(); -} - 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; @@ -1009,9 +995,10 @@ void ScrollView::SetScrollSensitive(bool sensitive) } else if((mSensitive) && (!sensitive)) { + DALI_LOG_SCROLL_STATE("[0x%X] BEFORE: panning:[%d]", this, int(mPanning)); + // 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 ); @@ -1021,6 +1008,7 @@ void ScrollView::SetScrollSensitive(bool sensitive) mSensitive = sensitive; mGestureStackDepth = 0; + DALI_LOG_SCROLL_STATE("[0x%X] AFTER: panning:[%d]", this, int(mPanning)); } } @@ -1084,14 +1072,14 @@ void ScrollView::SetWrapMode(bool enable) Self().SetProperty(mPropertyWrap, enable); } -int ScrollView::GetRefreshInterval() const +int ScrollView::GetScrollUpdateDistance() const { - return mRefreshIntervalMilliseconds; + return mScrollUpdateDistance; } -void ScrollView::SetRefreshInterval(int milliseconds) +void ScrollView::SetScrollUpdateDistance(int distance) { - mRefreshIntervalMilliseconds = milliseconds; + mScrollUpdateDistance = distance; } bool ScrollView::GetAxisAutoLock() const @@ -1138,6 +1126,26 @@ void ScrollView::SetFlickSpeedCoefficient(float speed) mFlickSpeedCoefficient = speed; } +Vector2 ScrollView::GetMinimumDistanceForFlick() const +{ + return mMinFlickDistance; +} + +void ScrollView::SetMinimumDistanceForFlick( const Vector2& distance ) +{ + mMinFlickDistance = distance; +} + +float ScrollView::GetMinimumSpeedForFlick() const +{ + return mFlickSpeedThreshold; +} + +void ScrollView::SetMinimumSpeedForFlick( float speed ) +{ + mFlickSpeedThreshold = speed; +} + float ScrollView::GetMaxFlickSpeed() const { return mMaxFlickSpeed; @@ -1186,12 +1194,6 @@ void ScrollView::SetScrollPosition(const Vector3& position) mScrollPrePosition = position; } -Vector3 ScrollView::GetCurrentScrollScale() const -{ - // in case animation is currently taking place. - return GetPropertyScale(); -} - Vector3 ScrollView::GetDomainSize() const { Vector3 size = Self().GetCurrentSize(); @@ -1203,38 +1205,55 @@ Vector3 ScrollView::GetDomainSize() const return domainSize; } -void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, +void ScrollView::TransformTo(const Vector3& position, DirectionBias horizontalBias, DirectionBias verticalBias) { - TransformTo(position, scale, rotation, mSnapDuration, horizontalBias, verticalBias); + TransformTo(position, mSnapDuration, horizontalBias, verticalBias); } -void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration, +void ScrollView::TransformTo(const Vector3& position, 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], duration[%.2f] bias[%d, %d]", + this, position.x, position.y, 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; + mGestureStackDepth = 0; + 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, - scale, - Vector3::ONE * duration, - rotation, - duration, mSnapAlphaFunction, true, horizontalBias, @@ -1244,9 +1263,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,7 +1293,10 @@ void ScrollView::ScrollTo(const Vector3& position, float duration) void ScrollView::ScrollTo(const Vector3& position, float duration, DirectionBias horizontalBias, DirectionBias verticalBias) { - TransformTo(position, mScrollPostScale, mScrollPostRotation, duration, horizontalBias, 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, horizontalBias, verticalBias); } void ScrollView::ScrollTo(unsigned int page) @@ -1404,21 +1437,11 @@ Actor ScrollView::FindClosestActorToPosition(const Vector3& position, FindDirect bool ScrollView::ScrollToSnapPoint() { + DALI_LOG_SCROLL_STATE("[0x%X]", this ); Vector2 stationaryVelocity = Vector2(0.0f, 0.0f); return SnapWithVelocity( stationaryVelocity ); } -void ScrollView::ScaleTo(const Vector3& scale) -{ - ScaleTo(scale, mSnapDuration); -} - -void ScrollView::ScaleTo(const Vector3& scale, float duration) -{ - TransformTo(mScrollPostPosition, scale, mScrollPostRotation, duration); -} - - // TODO: In situations where axes are different (X snap, Y free) // Each axis should really have their own independent animation (time and equation) // Consider, X axis snapping to nearest grid point (EaseOut over fixed time) @@ -1435,8 +1458,6 @@ bool ScrollView::SnapWithVelocity(Vector2 velocity) float speed2 = velocity.LengthSquared(); AlphaFunction alphaFunction = mSnapAlphaFunction; Vector3 positionDuration = Vector3::ONE * mSnapDuration; - Vector3 scaleDuration = Vector3::ONE * mSnapDuration; - float rotationDuration = mSnapDuration; float biasX = 0.5f; float biasY = 0.5f; FindDirection horizontal = None; @@ -1446,7 +1467,7 @@ bool ScrollView::SnapWithVelocity(Vector2 velocity) // that will be accepted as a general N,E,S,W flick direction. const float orthoAngleRange = FLICK_ORTHO_ANGLE_RANGE * M_PI / 180.0f; - const float flickSpeedThreshold2 = FLICK_SPEED_THRESHOLD*FLICK_SPEED_THRESHOLD; + const float flickSpeedThreshold2 = mFlickSpeedThreshold * mFlickSpeedThreshold; Vector3 positionSnap = mScrollPrePosition; @@ -1626,21 +1647,7 @@ bool ScrollView::SnapWithVelocity(Vector2 velocity) } positionSnap += clampDelta; - // Scale Snap /////////////////////////////////////////////////////////////// - Vector3 scaleSnap = mScrollPostScale; - - scaleSnap.x = mRulerScaleX->Snap(scaleSnap.x); - scaleSnap.y = mRulerScaleY->Snap(scaleSnap.y); - - ClampScale(scaleSnap); - - // Rotation Snap //////////////////////////////////////////////////////////// - float rotationSnap = mScrollPostRotation; - // TODO: implement rotation snap - bool animating = AnimateTo(positionSnap, positionDuration, - scaleSnap, scaleDuration, - rotationSnap, rotationDuration, alphaFunction, false, DirectionBiasNone, DirectionBiasNone, isFlick || isFreeFlick ? Flick : Snap); @@ -1651,7 +1658,6 @@ bool ScrollView::SnapWithVelocity(Vector2 velocity) void ScrollView::StopAnimation(void) { // Clear Snap animation if exists. - StopAnimation(mSnapAnimation); StopAnimation(mInternalXAnimation); StopAnimation(mInternalYAnimation); mScrollStateFlags = 0; @@ -1669,8 +1675,6 @@ void ScrollView::StopAnimation(Animation& animation) } bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDuration, - const Vector3& scale, const Vector3& scaleDuration, - float rotation, float rotationDuration, AlphaFunction alpha, bool findShortcuts, DirectionBias horizontalBias, DirectionBias verticalBias, SnapType snapType) @@ -1682,8 +1686,6 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat float totalDuration = 0.0f; bool positionChanged = (mScrollTargetPosition != mScrollPostPosition); - bool scaleChanged = (scale != mScrollPostScale); - bool rotationChanged = fabsf(rotation - mScrollPostRotation) > Math::MACHINE_EPSILON_0; if(positionChanged) { @@ -1697,16 +1699,6 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat positionChanged = true; } - if(scaleChanged) - { - totalDuration = std::max(totalDuration, scaleDuration.x); - totalDuration = std::max(totalDuration, scaleDuration.y); - } - - if(rotationChanged) - { - totalDuration = std::max(totalDuration, rotationDuration); - } StopAnimation(); // Position Delta /////////////////////////////////////////////////////// @@ -1720,14 +1712,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; } } @@ -1738,42 +1730,26 @@ bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDurat if( !(mScrollStateFlags & SCROLL_ANIMATION_FLAGS) ) { + DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y ); self.SetProperty(mPropertyPrePosition, mScrollTargetPosition); mScrollPrePosition = mScrollTargetPosition; + mScrollPostPosition = mScrollTargetPosition; + WrapPosition(mScrollPostPosition); } - } - // Scale Delta /////////////////////////////////////////////////////// - if(scaleChanged) - { - if(totalDuration > Math::MACHINE_EPSILON_1) - { - mSnapAnimation = Animation::New(totalDuration); - mSnapAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished); - // TODO: for non-uniform scaling to different bounds e.g. scaling a square to a 4:3 aspect ratio screen with a velocity - // the height will hit first, and then the width, so that would require two different animation times just like position. - mSnapAnimation.AnimateTo( Property(self, mPropertyScale), scale, alpha, TimePeriod(0.0f, scaleDuration.x)); - - mSnapAnimation.AnimateTo( Property(self, mPropertyTime), totalDuration, AlphaFunctions::Linear ); - mSnapAnimation.Play(); - } - else - { - self.SetProperty(mPropertyScale, scale); - - mScrollPreScale = mScrollPostScale = scale; - } + DALI_LOG_SCROLL_STATE("[0x%X] position-changed, mScrollTargetPosition[%.2f, %.2f], mScrollPrePosition[%.2f, %.2f], mScrollPostPosition[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y, mScrollPrePosition.x, mScrollPrePosition.y, mScrollPostPosition.x, mScrollPostPosition.y ); + DALI_LOG_SCROLL_STATE("[0x%X] mPropertyPrePosition[%.2f, %.2f], mPropertyPosition[%.2f, %.2f]", this, self.GetProperty( mPropertyPrePosition ).Get().x, self.GetProperty( mPropertyPrePosition ).Get().y, self.GetProperty( mPropertyPosition ).Get().x, self.GetProperty( mPropertyPosition ).Get().y ); } - StartRefreshTimer(); + + SetScrollUpdateNotification(true); // Always send a snap event when AnimateTo is called. Toolkit::ScrollView::SnapEvent snapEvent; snapEvent.type = snapType; snapEvent.position = -mScrollTargetPosition; - snapEvent.scale = scale; - 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; @@ -1808,6 +1784,15 @@ void ScrollView::RemoveOverlay(Actor actor) mInternalActor.Remove( actor ); } +void ScrollView::SetOvershootEffectColor( const Vector4& color ) +{ + mOvershootEffectColor = color; + if( mOvershootIndicator ) + { + mOvershootIndicator->SetOvershootEffectColor( color ); + } +} + void ScrollView::SetScrollingDirection( Radian direction, Radian threshold ) { PanGestureDetector panGesture( GetPanGestureDetector() ); @@ -1848,15 +1833,9 @@ Vector3 ScrollView::GetPropertyPosition() const return position; } -Vector3 ScrollView::GetPropertyScale() const -{ - return Self().GetProperty(mPropertyScale); -} - void ScrollView::HandleStoppedAnimation() { - // Animation has stopped, so stop sending the scroll-update signal. - CancelRefreshTimer(); + SetScrollUpdateNotification(false); } void ScrollView::HandleSnapAnimationFinished() @@ -1870,9 +1849,11 @@ void ScrollView::HandleSnapAnimationFinished() UpdateLocalScrollProperties(); WrapPosition(mScrollPrePosition); + DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y ); self.SetProperty(mPropertyPrePosition, mScrollPrePosition); Vector3 currentScrollPosition = GetCurrentScrollPosition(); + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 3 current[%.2f, %.2f], mScrollTargetPosition[%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y, -mScrollTargetPosition.x, -mScrollTargetPosition.y ); mScrollCompletedSignalV2.Emit( currentScrollPosition ); mDomainOffset += deltaPosition - mScrollPostPosition; @@ -1880,6 +1861,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 ); @@ -1943,20 +1962,9 @@ 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); - self.SetProperty(mPropertyPrePosition, mScrollPrePosition); - } - else if( index == mPropertyY ) - { - self.GetProperty(mPropertyPrePosition).Get(mScrollPrePosition); - propertyValue.Get(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); } } @@ -1982,13 +1990,20 @@ void ScrollView::StopTouchDownTimer() bool ScrollView::OnTouchDownTimeout() { + DALI_LOG_SCROLL_STATE("[0x%X]", this); + mTouchDownTimeoutReached = true; - if( mScrollStateFlags & (SCROLL_ANIMATION_FLAGS | SNAP_ANIMATION_FLAGS) ) + unsigned int currentScrollStateFlags( mScrollStateFlags ); // Cleared in StopAnimation so keep local copy for comparison + if( currentScrollStateFlags & (SCROLL_ANIMATION_FLAGS | SNAP_ANIMATION_FLAGS) ) { + DALI_LOG_SCROLL_STATE("[0x%X] Scrolling Or snapping flags set, stopping animation", this); + StopAnimation(); - if( mScrollStateFlags & SCROLL_ANIMATION_FLAGS ) + if( currentScrollStateFlags & SCROLL_ANIMATION_FLAGS ) { + DALI_LOG_SCROLL_STATE("[0x%X] Scrolling flags set, emitting signal", this); + mScrollInterrupted = true; // reset domain offset as scrolling from original plane. mDomainOffset = Vector3::ZERO; @@ -1996,6 +2011,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 ); } } @@ -2007,6 +2023,8 @@ bool ScrollView::OnTouchEvent(const TouchEvent& event) { if(!mSensitive) { + DALI_LOG_SCROLL_STATE("[0x%X], Not Sensitive, ignoring", this); + // Ignore this touch event, if scrollview is insensitive. return false; } @@ -2014,22 +2032,32 @@ bool ScrollView::OnTouchEvent(const TouchEvent& event) // Ignore events with multiple-touch points if (event.GetPointCount() != 1) { + DALI_LOG_SCROLL_STATE("[0x%X], multiple touch, ignoring", this); + return false; } - if( event.GetPoint(0).state == TouchPoint::Down ) + const TouchPoint::State pointState = event.GetPoint(0).state; + if( pointState == TouchPoint::Down ) { + DALI_LOG_SCROLL_STATE("[0x%X] Down", this); + if(mGestureStackDepth==0) { mTouchDownTime = event.time; // This allows time for a pan-gesture to start, to avoid breaking snap-animation behavior with fast flicks. // If touch-down does not become a pan (after timeout interval), then snap-animation can be interrupted. + mTouchDownTimeoutReached = false; + mScrollInterrupted = false; StartTouchDownTimer(); } } - else if( event.GetPoint(0).state == TouchPoint::Up ) + else if( ( pointState == TouchPoint::Up ) || + ( ( pointState == TouchPoint::Interrupted ) && ( event.GetPoint(0).hitActor == Self() ) ) ) { + DALI_LOG_SCROLL_STATE("[0x%X] %s", this, ( ( pointState == TouchPoint::Up ) ? "Up" : "Interrupted" ) ); + StopTouchDownTimer(); // if the user touches and releases without enough movement to go @@ -2037,8 +2065,8 @@ bool ScrollView::OnTouchEvent(const TouchEvent& event) // otherwise our scroll could be stopped (interrupted) half way through an animation. if(mGestureStackDepth==0 && mTouchDownTimeoutReached) { - unsigned timeDelta( event.time - mTouchDownTime ); - if ( timeDelta >= MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET ) + if( ( event.GetPoint(0).state == TouchPoint::Interrupted ) || + ( ( event.time - mTouchDownTime ) >= MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET ) ) { // Reset the velocity only if down was received a while ago mLastVelocity = Vector2( 0.0f, 0.0f ); @@ -2048,6 +2076,8 @@ bool ScrollView::OnTouchEvent(const TouchEvent& event) // Only finish the transform if scrolling was interrupted on down or if we are scrolling if ( mScrollInterrupted || mScrolling ) { + DALI_LOG_SCROLL_STATE("[0x%X] Calling FinishTransform", this); + FinishTransform(); } } @@ -2109,6 +2139,7 @@ void ScrollView::ResetScrolling() Actor self = Self(); self.GetProperty(mPropertyPosition).Get(mScrollPostPosition); mScrollPrePosition = mScrollPostPosition; + DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPostPosition.x, mScrollPostPosition.y ); self.SetProperty(mPropertyPrePosition, mScrollPostPosition); } @@ -2147,13 +2178,7 @@ void ScrollView::PreAnimatedScrollSetup() mScrollStateFlags = 0; - mScrollPostScale = GetPropertyScale(); - // Update Actor position with this wrapped value. - // TODO Rotation - - mScrollPreScale = mScrollPostScale; - mScrollPreRotation = mScrollPostRotation; } void ScrollView::FinaliseAnimatedScroll() @@ -2168,7 +2193,9 @@ void ScrollView::AnimateInternalXTo( float position, float duration, AlphaFuncti if( duration > Math::MACHINE_EPSILON_10 ) { Actor self = Self(); + DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(mPropertyPrePosition).Get().x, position ); mInternalXAnimation = Animation::New(duration); + DALI_LOG_SCROLL_STATE("[0x%X], mInternalXAnimation[0x%X]", this, mInternalXAnimation.GetObjectPtr() ); mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished); mInternalXAnimation.AnimateTo( Property(self, mPropertyPrePosition, 0), position, alpha, duration); mInternalXAnimation.Play(); @@ -2187,7 +2214,9 @@ void ScrollView::AnimateInternalYTo( float position, float duration, AlphaFuncti if( duration > Math::MACHINE_EPSILON_10 ) { Actor self = Self(); + DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(mPropertyPrePosition).Get().y, position ); mInternalYAnimation = Animation::New(duration); + DALI_LOG_SCROLL_STATE("[0x%X], mInternalYAnimation[0x%X]", this, mInternalYAnimation.GetObjectPtr() ); mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished); mInternalYAnimation.AnimateTo( Property(self, mPropertyPrePosition, 1), position, alpha, TimePeriod(duration)); mInternalYAnimation.Play(); @@ -2210,32 +2239,48 @@ void ScrollView::OnScrollAnimationFinished( Animation& source ) // update our local scroll positions UpdateLocalScrollProperties(); - if( source == mSnapAnimation ) - { - // generic snap animation used for scaling and rotation - mSnapAnimation.Reset(); - } - if( source == mInternalXAnimation ) { + DALI_LOG_SCROLL_STATE("[0x%X] mInternalXAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalXAnimation.GetObjectPtr(), mScrollTargetPosition.x, Self().GetProperty(mPropertyPrePosition).Get().x, mScrollPostPosition.x ); + if( !(mScrollStateFlags & AnimatingInternalY) ) { scrollingFinished = true; } mInternalXAnimation.Reset(); + // wrap pre scroll x position and set it + if( mWrapMode ) + { + const RulerDomain rulerDomain = mRulerX->GetDomain(); + mScrollPrePosition.x = -WrapInDomain(-mScrollPrePosition.x, rulerDomain.min, rulerDomain.max); + DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y ); + handle.SetProperty(mPropertyPrePosition, mScrollPrePosition); + } SnapInternalXTo(mScrollPostPosition.x); } if( source == mInternalYAnimation ) { + DALI_LOG_SCROLL_STATE("[0x%X] mInternalYAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalYAnimation.GetObjectPtr(), mScrollTargetPosition.y, Self().GetProperty(mPropertyPrePosition).Get().y, mScrollPostPosition.y ); + if( !(mScrollStateFlags & AnimatingInternalX) ) { scrollingFinished = true; } mInternalYAnimation.Reset(); + if( mWrapMode ) + { + // wrap pre scroll y position and set it + const RulerDomain rulerDomain = mRulerY->GetDomain(); + mScrollPrePosition.y = -WrapInDomain(-mScrollPrePosition.y, rulerDomain.min, rulerDomain.max); + DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y ); + handle.SetProperty(mPropertyPrePosition, mScrollPrePosition); + } SnapInternalYTo(mScrollPostPosition.y); } + DALI_LOG_SCROLL_STATE("[0x%X] scrollingFinished[%d] Animation[0x%X]", this, scrollingFinished, source.GetObjectPtr()); + if(scrollingFinished) { HandleSnapAnimationFinished(); @@ -2248,6 +2293,8 @@ void ScrollView::OnSnapInternalPositionFinished( Animation& source ) UpdateLocalScrollProperties(); if( source == mInternalXAnimation ) { + DALI_LOG_SCROLL_STATE("[0x%X] Finished X PostPosition Animation", this ); + // clear internal x animation flags mScrollStateFlags &= ~SCROLL_X_STATE_MASK; mInternalXAnimation.Reset(); @@ -2255,6 +2302,8 @@ void ScrollView::OnSnapInternalPositionFinished( Animation& source ) } if( source == mInternalYAnimation ) { + DALI_LOG_SCROLL_STATE("[0x%X] Finished Y PostPosition Animation", this ); + mScrollStateFlags &= ~SCROLL_Y_STATE_MASK; mInternalYAnimation.Reset(); WrapPosition(mScrollPrePosition); @@ -2271,15 +2320,20 @@ void ScrollView::SnapInternalXTo(float position) mScrollStateFlags &= ~SCROLL_X_STATE_MASK; // if internal x not equal to inputed parameter, animate it - float current = self.GetProperty(mPropertyPrePosition).x; - float duration = fabsf(position - current); - mInternalXAnimation = Animation::New(duration); - mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished); - mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position); - mInternalXAnimation.Play(); + float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration); + DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration ); + if( duration > Math::MACHINE_EPSILON_1 ) + { + DALI_LOG_SCROLL_STATE("[0x%X] Starting X Snap Animation to[%.2f]", this, position ); - // add internal animation state flag - mScrollStateFlags |= SnappingInternalX; + 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) @@ -2292,15 +2346,20 @@ void ScrollView::SnapInternalYTo(float position) mScrollStateFlags &= ~SCROLL_Y_STATE_MASK; // if internal y not equal to inputed parameter, animate it - float current = self.GetProperty(mPropertyPrePosition).y; - float duration = fabsf(position - current); - mInternalYAnimation = Animation::New(duration); - mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished); - mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position); - mInternalYAnimation.Play(); + float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration); + DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration ); + if( duration > Math::MACHINE_EPSILON_1 ) + { + DALI_LOG_SCROLL_STATE("[0x%X] Starting Y Snap Animation to[%.2f]", this, position ); + + 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; + // add internal animation state flag + mScrollStateFlags |= SnappingInternalY; + } } void ScrollView::GestureStarted() @@ -2314,8 +2373,6 @@ void ScrollView::GestureStarted() StopTouchDownTimer(); StopAnimation(); mPanDelta = Vector3::ZERO; - mScaleDelta = Vector3::ONE; - mRotationDelta = 0.0f; mLastVelocity = Vector2(0.0f, 0.0f); if( !mScrolling ) { @@ -2338,18 +2395,16 @@ 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 ); } } } -void ScrollView::GestureContinuing(const Vector2& panDelta, const Vector2& scaleDelta, float rotationDelta) +void ScrollView::GestureContinuing(const Vector2& panDelta) { mPanDelta.x+= panDelta.x; mPanDelta.y+= panDelta.y; - mScaleDelta.x*= scaleDelta.x; - mScaleDelta.y*= scaleDelta.y; - mRotationDelta+= rotationDelta; // Save the velocity, there is a bug in PanGesture // Whereby the Gesture::Finished's velocity is either: @@ -2365,8 +2420,6 @@ void ScrollView::GestureContinuing(const Vector2& panDelta, const Vector2& scale } // TODO: Upgrade to use a more powerful gesture detector (one that supports multiple touches on pan - so works as pan and flick gesture) -// TODO: Reimplement Scaling (pinching 2+ points) -// TODO: Reimplment Rotation (pinching 2+ points) // 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) @@ -2377,6 +2430,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; @@ -2387,6 +2442,8 @@ 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; @@ -2399,21 +2456,45 @@ 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); + } + 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( mScrollMainInternalPrePositionConstraint ) + if ( mPanning ) { - self.RemoveConstraint(mScrollMainInternalPrePositionConstraint); + 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 ) + { + self.RemoveConstraint(mScrollMainInternalPrePositionConstraint); + } + + if( mOvershootIndicator ) + { + mOvershootIndicator->ClearOvershoot(); + } + } + else + { + // If we do not think we are panning, then we should not do anything here + return; } break; } @@ -2439,6 +2520,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) || @@ -2451,16 +2533,22 @@ void ScrollView::OnGestureEx(Gesture::State state) mGestureStackDepth--; if(mGestureStackDepth==0) { + // no flick if we have not exceeded min flick distance + if( (fabsf(mPanDelta.x) < mMinFlickDistance.x) + && (fabsf(mPanDelta.y) < mMinFlickDistance.y) ) + { + // reset flick velocity + mLastVelocity = Vector2::ZERO; + } FinishTransform(); } + else + { + DALI_LOG_SCROLL_STATE("[0x%X] mGestureStackDepth[%d]", this, mGestureStackDepth); + } } } -void ScrollView::UpdateTransform() -{ -// TODO: notify clamps using property notifications (or see if we need this, can deprecate it) -} - void ScrollView::FinishTransform() { // at this stage internal x and x scroll position should have followed prescroll position exactly @@ -2468,15 +2556,16 @@ void ScrollView::FinishTransform() PreAnimatedScrollSetup(); + // convert pixels/millisecond to pixels per second bool animating = SnapWithVelocity(mLastVelocity * 1000.0f); if(!animating) { // if not animating, then this pan has completed right now. + SetScrollUpdateNotification(false); mScrolling = false; Self().SetProperty(mPropertyScrolling, false); - Vector3 currentScrollPosition = GetCurrentScrollPosition(); - mScrollCompletedSignalV2.Emit( currentScrollPosition ); + if( fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10 ) { SnapInternalXTo(mScrollTargetPosition.x); @@ -2485,6 +2574,9 @@ void ScrollView::FinishTransform() { SnapInternalYTo(mScrollTargetPosition.y); } + Vector3 currentScrollPosition = GetCurrentScrollPosition(); + DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 6 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y); + mScrollCompletedSignalV2.Emit( currentScrollPosition ); } } @@ -2547,18 +2639,6 @@ void ScrollView::ClampPosition(Vector3& position, ClampState3 &clamped) const { Vector3 size = Self().GetCurrentSize(); - // determine size of viewport relative to current scaled size. - // e.g. if you're zoomed in 200%, then each pixel on screen is only 0.5 pixels on subject. - if(fabsf(mScrollPostScale.x) > Math::MACHINE_EPSILON_0) - { - size.x /= mScrollPostScale.x; - } - - if(fabsf(mScrollPostScale.y) > Math::MACHINE_EPSILON_0) - { - size.y /= mScrollPostScale.y; - } - position.x = -mRulerX->Clamp(-position.x, size.width, 1.0f, clamped.x); // NOTE: X & Y rulers think in -ve coordinate system. position.y = -mRulerY->Clamp(-position.y, size.height, 1.0f, clamped.y); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT. @@ -2584,19 +2664,6 @@ void ScrollView::WrapPosition(Vector3& position) const } } -void ScrollView::ClampScale(Vector3& scale) const -{ - ClampState3 clamped; - ClampScale(scale, clamped); -} - -void ScrollView::ClampScale(Vector3& scale, ClampState3 &clamped) const -{ - scale.x = mRulerScaleX->Clamp(scale.x, 0.0f, 1.0f, clamped.x); - scale.y = mRulerScaleY->Clamp(scale.y, 0.0f, 1.0f, clamped.y); - clamped.z = NotClamped; -} - void ScrollView::UpdateMainInternalConstraint() { // TODO: Only update the constraints which have changed, rather than remove all and add all again. @@ -2610,8 +2677,6 @@ void ScrollView::UpdateMainInternalConstraint() self.RemoveConstraint(mScrollMainInternalDeltaConstraint); self.RemoveConstraint(mScrollMainInternalFinalConstraint); self.RemoveConstraint(mScrollMainInternalRelativeConstraint); - self.RemoveConstraint(mScrollMainInternalXConstraint); - self.RemoveConstraint(mScrollMainInternalYConstraint); } if( mScrollMainInternalPrePositionConstraint ) { @@ -2638,9 +2703,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 ); } @@ -2676,16 +2740,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); } @@ -2706,12 +2760,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 ); } @@ -2730,26 +2786,15 @@ void ScrollView::SetInternalConstraints() // User definable constraints to apply to all child actors ////////////////// Actor self = Self(); - // LocalSource - The Actors to be moved. - // self - The ScrollView - - // Apply some default constraints to ScrollView. - // Movement + Scaling + Wrap function + // Apply some default constraints to ScrollView & its bound actors + // Movement + Wrap function Constraint constraint; - // MoveScaledActor (scrolling/zooming) + // MoveActor (scrolling) constraint = Constraint::New( Actor::POSITION, Source( self, mPropertyPosition ), - Source( self, mPropertyScale ), - MoveScaledActorConstraint ); - constraint.SetRemoveAction(Constraint::Discard); - ApplyConstraintToBoundActors(constraint); - - // ScaleActor (scrolling/zooming) - constraint = Constraint::New( Actor::SCALE, - Source( self, mPropertyScale ), - ScaleActorConstraint ); + MoveActorConstraint ); constraint.SetRemoveAction(Constraint::Discard); ApplyConstraintToBoundActors(constraint); @@ -2766,42 +2811,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