2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
22 #include <dali/public-api/events/mouse-wheel-event.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
27 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
28 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
29 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-overshoot-indicator-impl.h>
31 //#define ENABLED_SCROLL_STATE_LOGGING
33 #ifdef ENABLED_SCROLL_STATE_LOGGING
34 #define DALI_LOG_SCROLL_STATE(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ## args)
36 #define DALI_LOG_SCROLL_STATE(format, args...)
39 // TODO: Change to two class system:
40 // 1. DraggableActor (is an actor which can be dragged anywhere, can be set to range using the ruler)
41 // 2. ScrollView (contains a draggable actor that can a) be dragged in the negative X, and Y domain, b) has a hitArea for touches)
42 // TODO: external components (page and status overlays).
44 // TODO: upgrade Vector2/3 to support returning Unit vectors, normals, & cross product (dot product is already provided)
51 const int DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 50; ///< Refresh rate TODO: Animation should have an update signal (and see item-view-impl)
52 const Vector2 DEFAULT_MIN_FLICK_DISTANCE(30.0f, 30.0f); ///< minimum distance for pan before flick allowed
53 const float DEFAULT_MIN_FLICK_SPEED_THRESHOLD(500.0f); ///< Minimum pan speed required for flick in pixels/s
54 const float FREE_FLICK_SPEED_THRESHOLD = 200.0f; ///< Free-Flick threshold in pixels/ms
55 const float AUTOLOCK_AXIS_MINIMUM_DISTANCE2 = 100.0f; ///< Auto-lock axis after minimum distance squared.
56 const float FLICK_ORTHO_ANGLE_RANGE = 75.0f; ///< degrees. (if >45, then supports diagonal flicking)
57 const unsigned int MAXIMUM_NUMBER_OF_VALUES = 5; ///< Number of values to use for weighted pan calculation.
58 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.
59 const unsigned long MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET( 150u );
60 const float DEFAULT_OVERSHOOT_ANIMATION_DURATION = 0.35f; // time in seconds
61 const Vector2 OVERSCROLL_CLAMP(1.0f, 1.0f); // maximum overscroll allowed in pixels when overshoot indicator is being used
62 const float TOUCH_DOWN_TIMER_INTERVAL = 100.0f;
63 const float DEFAULT_SCROLL_UPDATE_DISTANCE( 30.0f ); ///< Default distance to travel in pixels for scroll update signal
65 // predefined effect values
66 const Vector3 ANGLE_CAROUSEL_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f);
67 const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.2f, Math::PI * 0.2f, 0.0f); ///< Cube page rotates as if it has ten sides with the camera positioned inside
68 const Vector2 ANGLE_CUSTOM_CUBE_SWING(-Math::PI * 0.45f, -Math::PI * 0.45f); ///< outer cube pages swing 90 degrees as they pan offscreen
69 const Vector2 ANGLE_SPIRAL_SWING_IN(Math::PI * 0.5f, Math::PI * 0.5f);
70 const Vector2 ANGLE_SPIRAL_SWING_OUT(Math::PI * 0.35f, Math::PI * 0.35f);
71 const Vector2 ANGLE_OUTER_CUBE_SWING(Math::PI * 0.5f, Math::PI * 0.5f); ///< outer cube pages swing 90 degrees as they pan offscreen
73 // Helpers ////////////////////////////////////////////////////////////////////////////////////////
75 // TODO: GetAngle for Vector2 can be moved.
76 // GetAngle for Vector3 needs to be measured against a normal/plane.
79 * @param[in] vector The 3D vector to be measured
80 * @return angle in radians from 0 to 2PI
82 float GetAngle(const Vector3& vector)
84 return atan2(vector.y, vector.x) + Math::PI;
88 * @param[in] vector The 2D vector to be measured
89 * @return angle in radians from 0 to 2PI
91 float GetAngle(const Vector2& vector)
93 return atan2(vector.y, vector.x) + Math::PI;
97 * Find the vector (distance) from (a) to (b)
98 * in domain (start) to (end)
99 * (\ / start) (\ / end)
102 * @note assumes both (a) and (b) are already with the domain
105 * @param[in] a the current point
106 * @param[in] b the target point
107 * @param[in] start the start of the domain
108 * @param[in] end the end of the domain
109 * @param[in] bias whether to only take the right direction or the left direction,
110 * or the shortest direction.
111 * @return the shortest direction and distance
113 float VectorInDomain(float a, float b, float start, float end, Dali::Toolkit::DirectionBias bias)
115 if(bias == Dali::Toolkit::DirectionBiasNone)
117 return ShortestDistanceInDomain( a, b, start, end );
120 float size = end-start;
126 if(bias == Dali::Toolkit::DirectionBiasRight) // going right, take the vector.
132 float aRight = a+size;
139 if(bias == Dali::Toolkit::DirectionBiasLeft) // going left, take the vector.
145 float aLeft = a-size;
152 * Returns the position of the anchor within actor
154 * @param actor The Actor
155 * @param anchor The Anchor point of interest.
156 * @return The position of the Anchor
158 Vector3 GetPositionOfAnchor(Actor &actor, const Vector3 &anchor)
160 Vector3 childPosition = actor.GetCurrentPosition();
161 Vector3 childAnchor = - actor.GetCurrentAnchorPoint() + anchor;
162 Vector3 childSize = actor.GetCurrentSize();
164 return childPosition + childAnchor * childSize;
167 // AlphaFunctions /////////////////////////////////////////////////////////////////////////////////
169 float FinalDefaultAlphaFunction(float offset)
171 return offset * 0.5f;
175 * ConstantDecelerationAlphaFunction
176 * Newtoninan distance for constant deceleration
177 * v = 1 - t, s = t - 1/2 t^2
178 * when t = 0, s = 0.0 (min distance)
179 * when t = 1, s = 0.5 (max distance)
180 * progress = s / (max-min) = 2t - t^2
182 * @param[in] offset The input progress
183 * @return The output progress
185 float ConstantDecelerationAlphaFunction(float progress)
187 return progress * 2.0f - progress * progress;
190 // Internal Constraints ///////////////////////////////////////////////////////////////////////////
193 * Internal Relative position Constraint
194 * Generates the relative position value of the scroll view
195 * based on the absolute position, and it's relation to the
196 * scroll domain. This is a value from 0.0f to 1.0f in each
197 * scroll position axis.
199 Vector3 InternalRelativePositionConstraint(const Vector3& current,
200 const PropertyInput& scrollPositionProperty,
201 const PropertyInput& scrollMinProperty,
202 const PropertyInput& scrollMaxProperty,
203 const PropertyInput& scrollSizeProperty)
205 Vector3 position = -scrollPositionProperty.GetVector3();
206 const Vector3& min = scrollMinProperty.GetVector3();
207 const Vector3& max = scrollMaxProperty.GetVector3();
208 const Vector3& size = scrollSizeProperty.GetVector3();
210 position.x = WrapInDomain(position.x, min.x, max.x);
211 position.y = WrapInDomain(position.y, min.y, max.y);
213 Vector3 relativePosition;
214 Vector3 domainSize = (max - min) - size;
216 relativePosition.x = domainSize.x > Math::MACHINE_EPSILON_1 ? fabsf((position.x - min.x) / domainSize.x) : 0.0f;
217 relativePosition.y = domainSize.y > Math::MACHINE_EPSILON_1 ? fabsf((position.y - min.y) / domainSize.y) : 0.0f;
219 return relativePosition;
222 } // unnamed namespace
237 * Returns whether to lock scrolling to a particular axis
239 * @param[in] panDelta Distance panned since gesture started
240 * @param[in] currentLockAxis The current lock axis value
241 * @param[in] lockGradient How quickly to lock to a particular axis
243 * @return The new axis lock state
245 ScrollView::LockAxis GetLockAxis(const Vector2& panDelta, ScrollView::LockAxis currentLockAxis, float lockGradient)
247 if(panDelta.LengthSquared() > AUTOLOCK_AXIS_MINIMUM_DISTANCE2 &&
248 currentLockAxis == ScrollView::LockPossible)
250 float dx = fabsf(panDelta.x);
251 float dy = fabsf(panDelta.y);
252 if(dx * lockGradient >= dy)
254 // 0.36:1 gradient to the horizontal (deviate < 20 degrees)
255 currentLockAxis = ScrollView::LockVertical;
257 else if(dy * lockGradient > dx)
259 // 0.36:1 gradient to the vertical (deviate < 20 degrees)
260 currentLockAxis = ScrollView::LockHorizontal;
264 currentLockAxis = ScrollView::LockNone;
267 return currentLockAxis;
271 * Internal Pre-Position Property Constraint.
273 * Generates position property based on current position + gesture displacement.
274 * Or generates position property based on positionX/Y.
275 * Note: This is the position prior to any clamping at scroll boundaries.
277 struct InternalPrePositionConstraint
279 InternalPrePositionConstraint(const Vector2& initialPanMask,
281 float axisAutoLockGradient,
282 ScrollView::LockAxis initialLockAxis,
283 const Vector2& maxOvershoot,
284 const RulerDomain& domainX, const RulerDomain& domainY)
285 : mInitialPanMask(initialPanMask),
286 mDomainMin( -domainX.min, -domainY.min ),
287 mDomainMax( -domainX.max, -domainY.max ),
288 mMaxOvershoot(maxOvershoot),
289 mAxisAutoLockGradient(axisAutoLockGradient),
290 mLockAxis(initialLockAxis),
291 mAxisAutoLock(axisAutoLock),
293 mClampX( domainX.enabled ),
294 mClampY( domainY.enabled )
298 Vector3 operator()(const Vector3& current,
299 const PropertyInput& gesturePositionProperty,
300 const PropertyInput& gestureDisplacementProperty,
301 const PropertyInput& sizeProperty)
303 Vector3 scrollPostPosition = current;
304 Vector2 panPosition = gesturePositionProperty.GetVector2();
308 mLocalStart = gesturePositionProperty.GetVector2() - gestureDisplacementProperty.GetVector2();
309 mPrePosition = current;
310 mCurrentPanMask = mInitialPanMask;
314 // Calculate Deltas...
315 Vector2 currentPosition = gesturePositionProperty.GetVector2();
316 Vector2 panDelta( currentPosition - mLocalStart );
318 // Axis Auto Lock - locks the panning to the horizontal or vertical axis if the pan
319 // appears mostly horizontal or mostly vertical respectively...
322 mLockAxis = GetLockAxis(panDelta, mLockAxis, mAxisAutoLockGradient);
323 if( mLockAxis == ScrollView::LockVertical )
325 mCurrentPanMask.y = 0.0f;
327 else if( mLockAxis == ScrollView::LockHorizontal )
329 mCurrentPanMask.x = 0.0f;
333 // Restrict deltas based on ruler enable/disable and axis-lock state...
334 panDelta *= mCurrentPanMask;
336 // Perform Position transform based on input deltas...
337 scrollPostPosition = mPrePosition;
338 scrollPostPosition.GetVectorXY() += panDelta;
340 // if no wrapping then clamp preposition to maximum overshoot amount
341 const Vector3& size = sizeProperty.GetVector3();
344 float newXPosition = Clamp(scrollPostPosition.x, (mDomainMax.x + size.x) - mMaxOvershoot.x, mDomainMin.x + mMaxOvershoot.x );
345 if( (newXPosition < scrollPostPosition.x - Math::MACHINE_EPSILON_1)
346 || (newXPosition > scrollPostPosition.x + Math::MACHINE_EPSILON_1) )
348 mPrePosition.x = newXPosition;
349 mLocalStart.x = panPosition.x;
351 scrollPostPosition.x = newXPosition;
355 float newYPosition = Clamp(scrollPostPosition.y, (mDomainMax.y + size.y) - mMaxOvershoot.y, mDomainMin.y + mMaxOvershoot.y );
356 if( (newYPosition < scrollPostPosition.y - Math::MACHINE_EPSILON_1)
357 || (newYPosition > scrollPostPosition.y + Math::MACHINE_EPSILON_1) )
359 mPrePosition.y = newYPosition;
360 mLocalStart.y = panPosition.y;
362 scrollPostPosition.y = newYPosition;
365 return scrollPostPosition;
368 Vector3 mPrePosition;
370 Vector2 mInitialPanMask; ///< Initial pan mask (based on ruler settings)
371 Vector2 mCurrentPanMask; ///< Current pan mask that can be altered by axis lock mode.
374 Vector2 mMaxOvershoot;
376 float mAxisAutoLockGradient; ///< Set by ScrollView
377 ScrollView::LockAxis mLockAxis;
379 bool mAxisAutoLock:1; ///< Set by ScrollView
386 * Internal Position Property Constraint.
388 * Generates position property based on pre-position
389 * Note: This is the position after clamping.
390 * (uses result of InternalPrePositionConstraint)
392 struct InternalPositionConstraint
394 InternalPositionConstraint(const RulerDomain& domainX, const RulerDomain& domainY, bool wrap)
395 : mDomainMin( -domainX.min, -domainY.min ),
396 mDomainMax( -domainX.max, -domainY.max ),
397 mClampX( domainX.enabled ),
398 mClampY( domainY.enabled ),
403 Vector3 operator()(const Vector3& current,
404 const PropertyInput& scrollPositionProperty,
405 const PropertyInput& scrollMinProperty,
406 const PropertyInput& scrollMaxProperty,
407 const PropertyInput& scrollSizeProperty)
409 Vector3 position = scrollPositionProperty.GetVector3();
410 const Vector2& size = scrollSizeProperty.GetVector3().GetVectorXY();
411 const Vector3& min = scrollMinProperty.GetVector3();
412 const Vector3& max = scrollMaxProperty.GetVector3();
416 position.x = -WrapInDomain(-position.x, min.x, max.x);
417 position.y = -WrapInDomain(-position.y, min.y, max.y);
421 // clamp post position to domain
422 position.x = mClampX ? Clamp(position.x, mDomainMax.x + size.x, mDomainMin.x ) : position.x;
423 position.y = mClampY ? Clamp(position.y, mDomainMax.y + size.y, mDomainMin.y ) : position.y;
438 * This constraint updates the X overshoot property using the difference
439 * mPropertyPrePosition.x and mPropertyPosition.x, returning a relative value between 0.0f and 1.0f
441 struct OvershootXConstraint
443 OvershootXConstraint(float maxOvershoot) : mMaxOvershoot(maxOvershoot) {}
445 float operator()(const float& current,
446 const PropertyInput& scrollPrePositionProperty,
447 const PropertyInput& scrollPostPositionProperty,
448 const PropertyInput& canScrollProperty)
450 if( canScrollProperty.GetBoolean() )
452 const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
453 const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
454 float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
455 return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
464 * This constraint updates the Y overshoot property using the difference
465 * mPropertyPrePosition.y and mPropertyPosition.y, returning a relative value between 0.0f and 1.0f
467 struct OvershootYConstraint
469 OvershootYConstraint(float maxOvershoot) : mMaxOvershoot(maxOvershoot) {}
471 float operator()(const float& current,
472 const PropertyInput& scrollPrePositionProperty,
473 const PropertyInput& scrollPostPositionProperty,
474 const PropertyInput& canScrollProperty)
476 if( canScrollProperty.GetBoolean() )
478 const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
479 const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
480 float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
481 return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
490 * When panning, this constraint updates the X property, otherwise
491 * it has no effect on the X property.
493 float InternalXConstraint(const float& current,
494 const PropertyInput& scrollPosition)
496 return scrollPosition.GetVector3().x;
500 * When panning, this constraint updates the Y property, otherwise
501 * it has no effect on the Y property.
503 float InternalYConstraint(const float& current,
504 const PropertyInput& scrollPosition)
506 return scrollPosition.GetVector3().y;
510 * Internal Position-Delta Property Constraint.
512 * Generates position-delta property based on scroll-position + scroll-offset properties.
514 Vector3 InternalPositionDeltaConstraint(const Vector3& current,
515 const PropertyInput& scrollPositionProperty,
516 const PropertyInput& scrollOffsetProperty)
518 const Vector3& scrollPosition = scrollPositionProperty.GetVector3();
519 const Vector3& scrollOffset = scrollOffsetProperty.GetVector3();
521 return scrollPosition + scrollOffset;
525 * Internal Final Position Constraint
526 * The position of content is:
527 * of scroll-position + f(scroll-overshoot)
528 * where f(...) function defines how overshoot
529 * should affect final-position.
531 struct InternalFinalConstraint
533 InternalFinalConstraint(AlphaFunction functionX,
534 AlphaFunction functionY)
535 : mFunctionX(functionX),
536 mFunctionY(functionY)
540 Vector3 operator()(const Vector3& current,
541 const PropertyInput& scrollPositionProperty,
542 const PropertyInput& scrollOvershootXProperty,
543 const PropertyInput& scrollOvershootYProperty)
545 const float& overshootx = scrollOvershootXProperty.GetFloat();
546 const float& overshooty = scrollOvershootYProperty.GetFloat();
547 Vector3 offset( mFunctionX(overshootx),
548 mFunctionY(overshooty),
551 return scrollPositionProperty.GetVector3() - offset;
554 AlphaFunction mFunctionX;
555 AlphaFunction mFunctionY;
561 return Toolkit::ScrollView::New();
564 TypeRegistration typeRegistration( typeid(Toolkit::ScrollView), typeid(Toolkit::Scrollable), Create );
566 SignalConnectorType signalConnector1( typeRegistration, Toolkit::ScrollView::SIGNAL_SNAP_STARTED, &ScrollView::DoConnectSignal );
571 ///////////////////////////////////////////////////////////////////////////////////////////////////
573 ///////////////////////////////////////////////////////////////////////////////////////////////////
575 Dali::Toolkit::ScrollView ScrollView::New()
577 // Create the implementation
578 ScrollViewPtr scrollView(new ScrollView());
580 // Pass ownership to CustomActor via derived handle
581 Dali::Toolkit::ScrollView handle(*scrollView);
583 // Second-phase init of the implementation
584 // This can only be done after the CustomActor connection has been made...
585 scrollView->Initialize();
590 ScrollView::ScrollView()
593 mGestureStackDepth(0),
594 mScrollStateFlags(0),
595 mMinTouchesForPanning(1),
596 mMaxTouchesForPanning(1),
597 mLockAxis(LockPossible),
598 mScrollUpdateDistance(DEFAULT_SCROLL_UPDATE_DISTANCE),
599 mOvershootDelay(1.0f),
600 mMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
601 mUserMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
602 mSnapOvershootDuration(Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION),
603 mSnapOvershootAlphaFunction(AlphaFunctions::EaseOut),
604 mSnapDuration(Toolkit::ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION),
605 mSnapAlphaFunction(AlphaFunctions::EaseOut),
606 mMinFlickDistance(DEFAULT_MIN_FLICK_DISTANCE),
607 mFlickSpeedThreshold(DEFAULT_MIN_FLICK_SPEED_THRESHOLD),
608 mFlickDuration(Toolkit::ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION),
609 mFlickAlphaFunction(AlphaFunctions::EaseOut),
610 mAxisAutoLockGradient(Toolkit::ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT),
611 mFrictionCoefficient(Toolkit::ScrollView::DEFAULT_FRICTION_COEFFICIENT),
612 mFlickSpeedCoefficient(Toolkit::ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT),
613 mMaxFlickSpeed(Toolkit::ScrollView::DEFAULT_MAX_FLICK_SPEED),
614 mInAccessibilityPan(false),
617 mScrollInterrupted(false),
620 mTouchDownTimeoutReached(false),
621 mActorAutoSnapEnabled(false),
622 mAutoResizeContainerEnabled(false),
624 mAxisAutoLock(false),
626 mDefaultMaxOvershoot(true),
627 mCanScrollHorizontal(true),
628 mCanScrollVertical(true)
630 SetRequiresMouseWheelEvents(true);
633 void ScrollView::OnInitialize()
637 // Internal Actor, used to hide actors from enumerations.
638 // Also actors added to Internal actor appear as overlays e.g. ScrollBar components.
639 mInternalActor = Actor::New();
640 mInternalActor.SetDrawMode(DrawMode::OVERLAY);
641 self.Add(mInternalActor);
642 mInternalActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
643 mInternalActor.SetParentOrigin(ParentOrigin::CENTER);
644 mInternalActor.SetAnchorPoint(AnchorPoint::CENTER);
648 // Register Scroll Properties.
649 RegisterProperties();
651 mScrollPostPosition = mScrollPrePosition = Vector3::ZERO;
653 mMouseWheelScrollDistanceStep = Stage::GetCurrent().GetSize() * DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION;
657 mGestureStackDepth = 0;
659 EnableGestureDetection( Gesture::Type( Gesture::Pan ) );
661 // For pan, default to only 1 touch required, ignoring touches outside this range.
662 SetTouchesRequiredForPanning(1, 1, false);
664 // By default we'll allow the user to freely drag the scroll view,
665 // while disabling the other rulers.
666 RulerPtr ruler = new DefaultRuler();
670 EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
672 Vector3 size = GetControlSize();
673 UpdatePropertyDomain(size);
674 SetInternalConstraints();
677 void ScrollView::OnControlStageConnection()
679 DALI_LOG_SCROLL_STATE("[0x%X]", this);
683 SetScrollSensitive( false );
684 SetScrollSensitive( true );
686 if(IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator))
688 // try and make sure property notifications are set
689 EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
693 void ScrollView::OnControlStageDisconnection()
695 DALI_LOG_SCROLL_STATE("[0x%X]", this);
700 ScrollView::~ScrollView()
702 DALI_LOG_SCROLL_STATE("[0x%X]", this);
705 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
707 return mSnapAlphaFunction;
710 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
712 mSnapAlphaFunction = alpha;
715 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
717 return mFlickAlphaFunction;
720 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
722 mFlickAlphaFunction = alpha;
725 float ScrollView::GetScrollSnapDuration() const
727 return mSnapDuration;
730 void ScrollView::SetScrollSnapDuration(float time)
732 mSnapDuration = time;
735 float ScrollView::GetScrollFlickDuration() const
737 return mFlickDuration;
740 void ScrollView::SetScrollFlickDuration(float time)
742 mFlickDuration = time;
745 void ScrollView::ApplyEffect(Toolkit::ScrollViewEffect effect)
747 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
749 // Assertion check to ensure effect doesn't already exist in this scrollview
750 bool effectAlreadyExistsInScrollView(false);
751 for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
755 effectAlreadyExistsInScrollView = true;
760 DALI_ASSERT_ALWAYS(!effectAlreadyExistsInScrollView);
762 // add effect to effects list
763 mEffects.push_back(effect);
765 // invoke Attachment request to ScrollView first
766 GetImpl(effect).Attach(self);
769 Toolkit::ScrollViewEffect ScrollView::ApplyEffect(Toolkit::ScrollView::PageEffect effect)
771 Toolkit::ScrollViewEffect scrollEffect;
774 case Toolkit::ScrollView::PageEffectNone:
778 case Toolkit::ScrollView::PageEffectOuterCube:
780 Toolkit::ScrollViewCustomEffect customEffect;
781 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
782 Vector2 pageSize = Stage::GetCurrent().GetSize();
783 // 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
784 // 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)
785 // the page moving off screen will slowly build a spacing from 0.0f to 20.0f
786 // the spacing from each page is added together for the final spacing between the two pages.
787 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));
788 customEffect.SetSwingAngleOut(ANGLE_CUSTOM_CUBE_SWING.x, Vector3(0.0f, -1.0f, 0.0f));
789 customEffect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT);
790 customEffect.SetOpacityThreshold(0.7f);
793 case Toolkit::ScrollView::PageEffectDepth:
795 Toolkit::ScrollViewCustomEffect customEffect;
796 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
799 case Toolkit::ScrollView::PageEffectInnerCube:
801 Toolkit::ScrollViewCustomEffect customEffect;
802 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
803 customEffect.SetPageSpacing(Vector2(30.0f, 30.0f));
804 customEffect.SetAngledOriginPageRotation(ANGLE_CUBE_PAGE_ROTATE);
805 customEffect.SetSwingAngle(ANGLE_CUBE_PAGE_ROTATE.x, Vector3(0,-1,0));
806 customEffect.SetOpacityThreshold(0.5f);
809 case Toolkit::ScrollView::PageEffectCarousel:
811 Toolkit::ScrollViewCustomEffect customEffect;
812 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
813 customEffect.SetPageTranslation(Vector3(0,0,0), Vector3(-30, 0, 0));
814 customEffect.SetPageSpacing(Vector2(60.0f, 60.0f));
815 customEffect.SetAngledOriginPageRotation(-ANGLE_CUBE_PAGE_ROTATE);
816 customEffect.SetOpacityThreshold(0.2f, 0.6f);
819 case Toolkit::ScrollView::PageEffectSpiral:
821 Toolkit::ScrollViewCustomEffect customEffect;
822 scrollEffect = customEffect = Toolkit::ScrollViewCustomEffect::New();
824 Vector2 pageSize = Stage::GetCurrent().GetSize();
825 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));
826 //customEffect.SetSwingAngleAlphaFunctionOut(AlphaFunctions::EaseOut);
827 customEffect.SetSwingAnchor(AnchorPoint::CENTER_RIGHT);
828 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);
829 //customEffect.SetPageTranslateAlphaFunctionOut(AlphaFunctions::EaseOut);
830 customEffect.SetOpacityThreshold(0.75f, 0.6f);
831 customEffect.SetOpacityAlphaFunctionIn(AlphaFunctions::EaseInOut);
836 DALI_ASSERT_DEBUG(0 && "unknown scroll view effect");
839 RemoveConstraintsFromChildren();
842 ApplyEffect(scrollEffect);
847 void ScrollView::RemoveEffect(Toolkit::ScrollViewEffect effect)
849 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
851 // remove effect from effects list
852 bool effectExistedInScrollView(false);
853 for (ScrollViewEffectIter iter = mEffects.begin(); iter != mEffects.end(); ++iter)
857 mEffects.erase(iter);
858 effectExistedInScrollView = true;
863 // Assertion check to ensure effect existed.
864 DALI_ASSERT_ALWAYS(effectExistedInScrollView);
866 // invoke Detachment request to ScrollView last
867 GetImpl(effect).Detach(self);
870 void ScrollView::RemoveAllEffects()
872 Dali::Toolkit::ScrollView self = Dali::Toolkit::ScrollView::DownCast(Self());
874 for (ScrollViewEffectIter effectIter = mEffects.begin(); effectIter != mEffects.end(); ++effectIter)
876 Toolkit::ScrollViewEffect effect = *effectIter;
878 // invoke Detachment request to ScrollView last
879 GetImpl(effect).Detach(self);
885 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
887 ApplyConstraintToBoundActors(constraint);
890 void ScrollView::RemoveConstraintsFromChildren()
892 RemoveConstraintsFromBoundActors();
895 const RulerPtr ScrollView::GetRulerX() const
900 const RulerPtr ScrollView::GetRulerY() const
905 void ScrollView::SetRulerX(RulerPtr ruler)
909 Vector3 size = GetControlSize();
910 UpdatePropertyDomain(size);
911 UpdateMainInternalConstraint();
914 void ScrollView::SetRulerY(RulerPtr ruler)
918 Vector3 size = GetControlSize();
919 UpdatePropertyDomain(size);
920 UpdateMainInternalConstraint();
923 void ScrollView::UpdatePropertyDomain(const Vector3& size)
926 Vector3 min = mMinScroll;
927 Vector3 max = mMaxScroll;
928 bool scrollPositionChanged = false;
929 bool domainChanged = false;
931 bool canScrollVertical = false;
932 bool canScrollHorizontal = false;
933 UpdateLocalScrollProperties();
934 if(mRulerX->IsEnabled())
936 const Toolkit::RulerDomain& rulerDomain = mRulerX->GetDomain();
937 if( fabsf(min.x - rulerDomain.min) > Math::MACHINE_EPSILON_100
938 || fabsf(max.x - rulerDomain.max) > Math::MACHINE_EPSILON_100 )
940 domainChanged = true;
941 min.x = rulerDomain.min;
942 max.x = rulerDomain.max;
944 // make sure new scroll value is within new domain
945 if( mScrollPrePosition.x < min.x
946 || mScrollPrePosition.x > max.x )
948 scrollPositionChanged = true;
949 mScrollPrePosition.x = Clamp(mScrollPrePosition.x, -(max.x - size.x), -min.x);
952 if( (fabsf(rulerDomain.max - rulerDomain.min) - size.x) > Math::MACHINE_EPSILON_100 )
954 canScrollHorizontal = true;
957 else if( fabs(min.x) > Math::MACHINE_EPSILON_100
958 || fabs(max.x) > Math::MACHINE_EPSILON_100 )
960 // need to reset to 0
961 domainChanged = true;
964 canScrollHorizontal = false;
967 if(mRulerY->IsEnabled())
969 const Toolkit::RulerDomain& rulerDomain = mRulerY->GetDomain();
970 if( fabsf(min.y - rulerDomain.min) > Math::MACHINE_EPSILON_100
971 || fabsf(max.y - rulerDomain.max) > Math::MACHINE_EPSILON_100 )
973 domainChanged = true;
974 min.y = rulerDomain.min;
975 max.y = rulerDomain.max;
977 // make sure new scroll value is within new domain
978 if( mScrollPrePosition.y < min.y
979 || mScrollPrePosition.y > max.y )
981 scrollPositionChanged = true;
982 mScrollPrePosition.y = Clamp(mScrollPrePosition.y, -(max.y - size.y), -min.y);
985 if( (fabsf(rulerDomain.max - rulerDomain.min) - size.y) > Math::MACHINE_EPSILON_100 )
987 canScrollVertical = true;
990 else if( fabs(min.y) > Math::MACHINE_EPSILON_100
991 || fabs(max.y) > Math::MACHINE_EPSILON_100 )
993 // need to reset to 0
994 domainChanged = true;
997 canScrollHorizontal = false;
1000 // avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update
1001 if( mCanScrollVertical != canScrollVertical )
1003 mCanScrollVertical = canScrollVertical;
1004 self.SetProperty(mPropertyCanScrollVertical, canScrollVertical);
1006 if( mCanScrollHorizontal != canScrollHorizontal )
1008 mCanScrollHorizontal = canScrollHorizontal;
1009 self.SetProperty(mPropertyCanScrollHorizontal, canScrollHorizontal);
1011 if( scrollPositionChanged )
1013 DALI_LOG_SCROLL_STATE("[0x%X] Domain Changed, setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
1014 self.SetProperty(mPropertyPrePosition, mScrollPrePosition);
1020 self.SetProperty(mPropertyPositionMin, mMinScroll );
1021 self.SetProperty(mPropertyPositionMax, mMaxScroll );
1025 void ScrollView::SetScrollSensitive(bool sensitive)
1027 Actor self = Self();
1028 PanGestureDetector panGesture( GetPanGestureDetector() );
1030 DALI_LOG_SCROLL_STATE("[0x%X] sensitive: before:[%d] setting[%d]", this, int(mSensitive), int(sensitive));
1032 if((!mSensitive) && (sensitive))
1034 mSensitive = sensitive;
1035 panGesture.Attach(self);
1037 else if((mSensitive) && (!sensitive))
1039 DALI_LOG_SCROLL_STATE("[0x%X] BEFORE: panning:[%d]", this, int(mPanning));
1041 // while the scroll view is panning, the state needs to be reset.
1044 PanGesture cancelGesture( Gesture::Cancelled );
1045 OnPan( cancelGesture );
1048 panGesture.Detach(self);
1049 mSensitive = sensitive;
1051 mGestureStackDepth = 0;
1052 DALI_LOG_SCROLL_STATE("[0x%X] AFTER: panning:[%d]", this, int(mPanning));
1056 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
1058 mMaxOvershoot.x = overshootX;
1059 mMaxOvershoot.y = overshootY;
1060 mUserMaxOvershoot = mMaxOvershoot;
1061 mDefaultMaxOvershoot = false;
1062 UpdateMainInternalConstraint();
1065 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
1067 mSnapOvershootAlphaFunction = alpha;
1070 void ScrollView::SetSnapOvershootDuration(float duration)
1072 mSnapOvershootDuration = duration;
1075 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
1077 PanGestureDetector panGesture( GetPanGestureDetector() );
1079 mMinTouchesForPanning = minTouches;
1080 mMaxTouchesForPanning = maxTouches;
1084 panGesture.SetMinimumTouchesRequired(minTouches);
1085 panGesture.SetMaximumTouchesRequired(maxTouches);
1089 panGesture.SetMinimumTouchesRequired(1);
1090 panGesture.SetMaximumTouchesRequired(UINT_MAX);
1094 void ScrollView::SetActorAutoSnap(bool enable)
1096 mActorAutoSnapEnabled = enable;
1099 void ScrollView::SetAutoResize(bool enable)
1101 mAutoResizeContainerEnabled = enable;
1102 // TODO: This needs a lot of issues to be addressed before working.
1105 bool ScrollView::GetWrapMode() const
1110 void ScrollView::SetWrapMode(bool enable)
1113 Self().SetProperty(mPropertyWrap, enable);
1116 int ScrollView::GetRefreshInterval() const
1118 return mScrollUpdateDistance;
1121 void ScrollView::SetRefreshInterval(int milliseconds)
1123 mScrollUpdateDistance = milliseconds;
1126 int ScrollView::GetScrollUpdateDistance() const
1128 return mScrollUpdateDistance;
1131 void ScrollView::SetScrollUpdateDistance(int distance)
1133 mScrollUpdateDistance = distance;
1136 bool ScrollView::GetAxisAutoLock() const
1138 return mAxisAutoLock;
1141 void ScrollView::SetAxisAutoLock(bool enable)
1143 mAxisAutoLock = enable;
1144 UpdateMainInternalConstraint();
1147 float ScrollView::GetAxisAutoLockGradient() const
1149 return mAxisAutoLockGradient;
1152 void ScrollView::SetAxisAutoLockGradient(float gradient)
1154 DALI_ASSERT_DEBUG( gradient >= 0.0f && gradient <= 1.0f );
1155 mAxisAutoLockGradient = gradient;
1156 UpdateMainInternalConstraint();
1159 float ScrollView::GetFrictionCoefficient() const
1161 return mFrictionCoefficient;
1164 void ScrollView::SetFrictionCoefficient(float friction)
1166 DALI_ASSERT_DEBUG( friction > 0.0f );
1167 mFrictionCoefficient = friction;
1170 float ScrollView::GetFlickSpeedCoefficient() const
1172 return mFlickSpeedCoefficient;
1175 void ScrollView::SetFlickSpeedCoefficient(float speed)
1177 mFlickSpeedCoefficient = speed;
1180 Vector2 ScrollView::GetMinimumDistanceForFlick() const
1182 return mMinFlickDistance;
1185 void ScrollView::SetMinimumDistanceForFlick( const Vector2& distance )
1187 mMinFlickDistance = distance;
1190 float ScrollView::GetMinimumSpeedForFlick() const
1192 return mFlickSpeedThreshold;
1195 void ScrollView::SetMinimumSpeedForFlick( float speed )
1197 mFlickSpeedThreshold = speed;
1200 float ScrollView::GetMaxFlickSpeed() const
1202 return mMaxFlickSpeed;
1205 void ScrollView::SetMaxFlickSpeed(float speed)
1207 mMaxFlickSpeed = speed;
1210 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
1212 mMouseWheelScrollDistanceStep = step;
1215 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
1217 return mMouseWheelScrollDistanceStep;
1220 unsigned int ScrollView::GetCurrentPage() const
1222 // in case animation is currently taking place.
1223 Vector3 position = GetPropertyPosition();
1225 Actor self = Self();
1226 unsigned int page = 0;
1227 unsigned int pagesPerVolume = 1;
1228 unsigned int volume = 0;
1230 // if rulerX is enabled, then get page count (columns)
1231 page = mRulerX->GetPageFromPosition(-position.x, mWrapMode);
1232 volume = mRulerY->GetPageFromPosition(-position.y, mWrapMode);
1233 pagesPerVolume = mRulerX->GetTotalPages();
1235 return volume * pagesPerVolume + page;
1238 Vector3 ScrollView::GetCurrentScrollPosition() const
1240 return -GetPropertyPosition();
1243 void ScrollView::SetScrollPosition(const Vector3& position)
1245 mScrollPrePosition = position;
1248 Vector3 ScrollView::GetDomainSize() const
1250 Vector3 size = Self().GetCurrentSize();
1252 const RulerDomain& xDomain = GetRulerX()->GetDomain();
1253 const RulerDomain& yDomain = GetRulerY()->GetDomain();
1255 Vector3 domainSize = Vector3( xDomain.max - xDomain.min, yDomain.max - yDomain.min, 0.0f ) - size;
1259 void ScrollView::TransformTo(const Vector3& position,
1260 DirectionBias horizontalBias, DirectionBias verticalBias)
1262 TransformTo(position, mSnapDuration, horizontalBias, verticalBias);
1265 void ScrollView::TransformTo(const Vector3& position, float duration,
1266 DirectionBias horizontalBias, DirectionBias verticalBias)
1268 Actor self( Self() );
1270 // Guard against destruction during signal emission
1271 // Note that Emit() methods are called indirectly e.g. from within ScrollView::AnimateTo()
1272 Toolkit::ScrollView handle( GetOwner() );
1274 DALI_LOG_SCROLL_STATE("[0x%X] pos[%.2f,%.2f], duration[%.2f] bias[%d, %d]",
1275 this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
1277 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1278 self.SetProperty( mPropertyScrollStartPagePosition, currentScrollPosition );
1280 if( mScrolling ) // are we interrupting a current scroll?
1282 // set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
1284 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
1285 mScrollCompletedSignalV2.Emit( currentScrollPosition );
1288 if( mPanning ) // are we interrupting a current pan?
1290 DALI_LOG_SCROLL_STATE("[0x%X] Interrupting Pan, set to false", this );
1292 mGestureStackDepth = 0;
1293 self.SetProperty( mPropertyPanning, false );
1295 if( mScrollMainInternalPrePositionConstraint )
1297 self.RemoveConstraint(mScrollMainInternalPrePositionConstraint);
1301 self.SetProperty(mPropertyScrolling, true);
1304 DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
1305 mScrollStartedSignalV2.Emit( currentScrollPosition );
1306 bool animating = AnimateTo(-position,
1307 Vector3::ONE * duration,
1316 // if not animating, then this pan has completed right now.
1317 self.SetProperty(mPropertyScrolling, false);
1320 // If we have no duration, then in the next update frame, we will be at the position specified as we just set.
1321 // In this scenario, we cannot return the currentScrollPosition as this is out-of-date and should instead return the requested final position
1322 Vector3 completedPosition( currentScrollPosition );
1323 if( duration <= Math::MACHINE_EPSILON_10 )
1325 completedPosition = position;
1328 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 2 [%.2f, %.2f]", this, completedPosition.x, completedPosition.y);
1329 SetScrollUpdateNotification(false);
1330 mScrollCompletedSignalV2.Emit( completedPosition );
1334 void ScrollView::ScrollTo(const Vector3& position)
1336 ScrollTo(position, mSnapDuration );
1339 void ScrollView::ScrollTo(const Vector3& position, float duration)
1341 ScrollTo(position, duration, DirectionBiasNone, DirectionBiasNone);
1344 void ScrollView::ScrollTo(const Vector3& position, float duration,
1345 DirectionBias horizontalBias, DirectionBias verticalBias)
1347 DALI_LOG_SCROLL_STATE("[0x%X] position[%.2f, %.2f] duration[%.2f]",
1348 this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
1350 TransformTo(position, duration, horizontalBias, verticalBias);
1353 void ScrollView::ScrollTo(unsigned int page)
1355 ScrollTo(page, mSnapDuration);
1358 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
1361 unsigned int volume;
1362 unsigned int libraries;
1364 // The position to scroll to is continuous and linear
1365 // unless a domain has been enabled on the X axis.
1366 // or if WrapMode has been enabled.
1367 bool carryX = mRulerX->GetDomain().enabled | mWrapMode;
1368 bool carryY = mRulerY->GetDomain().enabled | mWrapMode;
1370 position.x = mRulerX->GetPositionFromPage(page, volume, carryX);
1371 position.y = mRulerY->GetPositionFromPage(volume, libraries, carryY);
1373 ScrollTo(position, duration, bias, bias);
1376 void ScrollView::ScrollTo(Actor &actor)
1378 ScrollTo(actor, mSnapDuration);
1381 void ScrollView::ScrollTo(Actor &actor, float duration)
1383 DALI_ASSERT_ALWAYS(actor.GetParent() == Self());
1385 Actor self = Self();
1386 Vector3 size = self.GetCurrentSize();
1387 Vector3 position = actor.GetCurrentPosition();
1388 position -= GetPropertyPrePosition();
1390 ScrollTo(Vector3(position.x - size.width * 0.5f, position.y - size.height * 0.5f, 0.0f), duration);
1393 Actor ScrollView::FindClosestActor()
1395 Actor self = Self();
1396 Vector3 size = self.GetCurrentSize();
1398 return FindClosestActorToPosition(Vector3(size.width * 0.5f,size.height * 0.5f,0.0f));
1401 Actor ScrollView::FindClosestActorToPosition(const Vector3& position, FindDirection dirX, FindDirection dirY, FindDirection dirZ)
1404 float closestDistance2 = 0.0f;
1405 Vector3 actualPosition = position;
1407 unsigned int numChildren = Self().GetChildCount();
1409 for(unsigned int i = 0; i < numChildren; ++i)
1411 Actor child = Self().GetChildAt(i);
1413 if(mInternalActor == child) // ignore internal actor.
1418 Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
1420 Vector3 delta = childPosition - actualPosition;
1422 // X-axis checking (only find Actors to the [dirX] of actualPosition)
1423 if(dirX > All) // != All,None
1425 FindDirection deltaH = delta.x > 0 ? Right : Left;
1432 // Y-axis checking (only find Actors to the [dirY] of actualPosition)
1433 if(dirY > All) // != All,None
1435 FindDirection deltaV = delta.y > 0 ? Down : Up;
1442 // Z-axis checking (only find Actors to the [dirZ] of actualPosition)
1443 if(dirZ > All) // != All,None
1445 FindDirection deltaV = delta.y > 0 ? In : Out;
1452 // compare child to closest child in terms of distance.
1453 float distance2 = 0.0f;
1455 // distance2 = the Square of the relevant dimensions of delta
1458 distance2 += delta.x * delta.x;
1463 distance2 += delta.y * delta.y;
1468 distance2 += delta.z * delta.z;
1471 if(closestChild) // Next time.
1473 if(distance2 < closestDistance2)
1475 closestChild = child;
1476 closestDistance2 = distance2;
1481 closestChild = child;
1482 closestDistance2 = distance2;
1486 return closestChild;
1489 bool ScrollView::ScrollToSnapPoint()
1491 DALI_LOG_SCROLL_STATE("[0x%X]", this );
1492 Vector2 stationaryVelocity = Vector2(0.0f, 0.0f);
1493 return SnapWithVelocity( stationaryVelocity );
1496 // TODO: In situations where axes are different (X snap, Y free)
1497 // Each axis should really have their own independent animation (time and equation)
1498 // Consider, X axis snapping to nearest grid point (EaseOut over fixed time)
1499 // Consider, Y axis simulating physics to arrive at a point (Physics equation over variable time)
1500 // Currently, the axes have been split however, they both use the same EaseOut equation.
1501 bool ScrollView::SnapWithVelocity(Vector2 velocity)
1503 // Animator takes over now, touches are assumed not to interfere.
1504 // And if touches do interfere, then we'll stop animation, update PrePosition
1505 // to current mScroll's properties, and then resume.
1506 // Note: For Flicking this may work a bit different...
1508 float angle = atan2(velocity.y, velocity.x);
1509 float speed2 = velocity.LengthSquared();
1510 AlphaFunction alphaFunction = mSnapAlphaFunction;
1511 Vector3 positionDuration = Vector3::ONE * mSnapDuration;
1514 FindDirection horizontal = None;
1515 FindDirection vertical = None;
1517 // orthoAngleRange = Angle tolerance within the Exact N,E,S,W direction
1518 // that will be accepted as a general N,E,S,W flick direction.
1520 const float orthoAngleRange = FLICK_ORTHO_ANGLE_RANGE * M_PI / 180.0f;
1521 const float flickSpeedThreshold2 = mFlickSpeedThreshold * mFlickSpeedThreshold;
1523 Vector3 positionSnap = mScrollPrePosition;
1525 // Flick logic X Axis
1527 if(mRulerX->IsEnabled() && mLockAxis != LockHorizontal)
1531 if( speed2 > flickSpeedThreshold2 || // exceeds flick threshold
1532 mInAccessibilityPan ) // With AccessibilityPan its easier to move between snap positions
1534 if((angle >= -orthoAngleRange) && (angle < orthoAngleRange)) // Swiping East
1536 biasX = 0.0f, horizontal = Left;
1538 // This guards against an error where no movement occurs, due to the flick finishing
1539 // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
1540 positionSnap.x += 1.0f;
1542 else if((angle >= M_PI-orthoAngleRange) || (angle < -M_PI+orthoAngleRange)) // Swiping West
1544 biasX = 1.0f, horizontal = Right;
1546 // This guards against an error where no movement occurs, due to the flick finishing
1547 // before the update-thread has advanced mScrollPostPosition past the the previous snap point.
1548 positionSnap.x -= 1.0f;
1553 // Flick logic Y Axis
1555 if(mRulerY->IsEnabled() && mLockAxis != LockVertical)
1559 if( speed2 > flickSpeedThreshold2 || // exceeds flick threshold
1560 mInAccessibilityPan ) // With AccessibilityPan its easier to move between snap positions
1562 if((angle >= M_PI_2-orthoAngleRange) && (angle < M_PI_2+orthoAngleRange)) // Swiping South
1564 biasY = 0.0f, vertical = Up;
1566 else if((angle >= -M_PI_2-orthoAngleRange) && (angle < -M_PI_2+orthoAngleRange)) // Swiping North
1568 biasY = 1.0f, vertical = Down;
1573 // isFlick: Whether this gesture is a flick or not.
1574 bool isFlick = (horizontal != All || vertical != All);
1575 // isFreeFlick: Whether this gesture is a flick under free panning criteria.
1576 bool isFreeFlick = velocity.LengthSquared() > (FREE_FLICK_SPEED_THRESHOLD*FREE_FLICK_SPEED_THRESHOLD);
1578 if(isFlick || isFreeFlick)
1580 positionDuration = Vector3::ONE * mFlickDuration;
1581 alphaFunction = mFlickAlphaFunction;
1584 // Calculate next positionSnap ////////////////////////////////////////////////////////////
1586 if(mActorAutoSnapEnabled)
1588 Vector3 size = Self().GetCurrentSize();
1590 Actor child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f), horizontal, vertical );
1592 if(!child && isFlick )
1594 // If we conducted a direction limited search and found no actor, then just snap to the closest actor.
1595 child = FindClosestActorToPosition( Vector3(size.width * 0.5f,size.height * 0.5f,0.0f) );
1600 Vector3 position = Self().GetProperty<Vector3>(mPropertyPosition);
1602 // Get center-point of the Actor.
1603 Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
1605 if(mRulerX->IsEnabled())
1607 positionSnap.x = position.x - childPosition.x + size.width * 0.5f;
1609 if(mRulerY->IsEnabled())
1611 positionSnap.y = position.y - childPosition.y + size.height * 0.5f;
1616 Vector3 startPosition = positionSnap;
1617 positionSnap.x = -mRulerX->Snap(-positionSnap.x, biasX); // NOTE: X & Y rulers think in -ve coordinate system.
1618 positionSnap.y = -mRulerY->Snap(-positionSnap.y, biasY); // That is scrolling RIGHT (e.g. 100.0, 0.0) means moving LEFT.
1620 Vector3 clampDelta(Vector3::ZERO);
1621 ClampPosition(positionSnap);
1623 if( (mRulerX->GetType() == Ruler::Free || mRulerY->GetType() == Ruler::Free)
1624 && isFreeFlick && !mActorAutoSnapEnabled)
1626 // Calculate target position based on velocity of flick.
1628 // a = Deceleration (Set to diagonal stage length * friction coefficient)
1629 // u = Initial Velocity (Flick velocity)
1630 // v = 0 (Final Velocity)
1631 // t = Time (Velocity / Deceleration)
1632 Vector2 stageSize = Stage::GetCurrent().GetSize();
1633 float stageLength = Vector3(stageSize.x, stageSize.y, 0.0f).Length();
1634 float a = (stageLength * mFrictionCoefficient);
1635 Vector3 u = Vector3(velocity.x, velocity.y, 0.0f) * mFlickSpeedCoefficient;
1636 float speed = u.Length();
1639 // TODO: Change this to a decay function. (faster you flick, the slower it should be)
1640 speed = std::min(speed, stageLength * mMaxFlickSpeed );
1642 alphaFunction = ConstantDecelerationAlphaFunction;
1644 float t = speed / a;
1646 if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
1648 positionSnap.x += t*u.x*0.5f;
1651 if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
1653 positionSnap.y += t*u.y*0.5f;
1656 clampDelta = positionSnap;
1657 ClampPosition(positionSnap);
1658 if((positionSnap - startPosition).LengthSquared() > Math::MACHINE_EPSILON_0)
1660 clampDelta -= positionSnap;
1661 clampDelta.x = clampDelta.x > 0.0f ? std::min(clampDelta.x, mMaxOvershoot.x) : std::max(clampDelta.x, -mMaxOvershoot.x);
1662 clampDelta.y = clampDelta.y > 0.0f ? std::min(clampDelta.y, mMaxOvershoot.y) : std::max(clampDelta.y, -mMaxOvershoot.y);
1666 clampDelta = Vector3::ZERO;
1669 // If Axis is Free and has velocity, then calculate time taken
1670 // to reach target based on velocity in axis.
1671 if(mRulerX->IsEnabled() && mRulerX->GetType() == Ruler::Free)
1673 float deltaX = fabsf(startPosition.x - positionSnap.x);
1675 if(fabsf(u.x) > Math::MACHINE_EPSILON_1)
1677 positionDuration.x = fabsf(deltaX / u.x);
1681 positionDuration.x = 0;
1685 if(mRulerY->IsEnabled() && mRulerY->GetType() == Ruler::Free)
1687 float deltaY = fabsf(startPosition.y - positionSnap.y);
1689 if(fabsf(u.y) > Math::MACHINE_EPSILON_1)
1691 positionDuration.y = fabsf(deltaY / u.y);
1695 positionDuration.y = 0;
1699 positionSnap += clampDelta;
1701 bool animating = AnimateTo(positionSnap, positionDuration,
1702 alphaFunction, false,
1703 DirectionBiasNone, DirectionBiasNone,
1704 isFlick || isFreeFlick ? Flick : Snap);
1709 void ScrollView::StopAnimation(void)
1711 // Clear Snap animation if exists.
1712 StopAnimation(mInternalXAnimation);
1713 StopAnimation(mInternalYAnimation);
1714 mScrollStateFlags = 0;
1715 // remove scroll animation flags
1716 HandleStoppedAnimation();
1719 void ScrollView::StopAnimation(Animation& animation)
1728 bool ScrollView::AnimateTo(const Vector3& position, const Vector3& positionDuration,
1729 AlphaFunction alpha, bool findShortcuts,
1730 DirectionBias horizontalBias, DirectionBias verticalBias,
1733 // Here we perform an animation on a number of properties (depending on which have changed)
1734 // The animation is applied to all ScrollBases
1735 Actor self = Self();
1736 mScrollTargetPosition = position;
1737 float totalDuration = 0.0f;
1739 bool positionChanged = (mScrollTargetPosition != mScrollPostPosition);
1743 totalDuration = std::max(totalDuration, positionDuration.x);
1744 totalDuration = std::max(totalDuration, positionDuration.y);
1748 // try to animate for a frame, on some occasions update will be changing scroll value while event side thinks it hasnt changed
1749 totalDuration = 0.01f;
1750 positionChanged = true;
1755 // Position Delta ///////////////////////////////////////////////////////
1758 if(mWrapMode && findShortcuts)
1760 // In Wrap Mode, the shortest distance is a little less intuitive...
1761 const RulerDomain rulerDomainX = mRulerX->GetDomain();
1762 const RulerDomain rulerDomainY = mRulerY->GetDomain();
1764 if(mRulerX->IsEnabled())
1766 float dir = VectorInDomain(-mScrollPrePosition.x, -mScrollTargetPosition.x, rulerDomainX.min, rulerDomainX.max, horizontalBias);
1767 mScrollTargetPosition.x = mScrollPrePosition.x + -dir;
1770 if(mRulerY->IsEnabled())
1772 float dir = VectorInDomain(-mScrollPrePosition.y, -mScrollTargetPosition.y, rulerDomainY.min, rulerDomainY.max, verticalBias);
1773 mScrollTargetPosition.y = mScrollPrePosition.y + -dir;
1777 // note we have two separate animations for X & Y, this deals with sliding diagonally and hitting
1778 // a horizonal/vertical wall.delay
1779 AnimateInternalXTo(mScrollTargetPosition.x, positionDuration.x, alpha);
1780 AnimateInternalYTo(mScrollTargetPosition.y, positionDuration.y, alpha);
1782 if( !(mScrollStateFlags & SCROLL_ANIMATION_FLAGS) )
1784 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y );
1785 self.SetProperty(mPropertyPrePosition, mScrollTargetPosition);
1786 mScrollPrePosition = mScrollTargetPosition;
1787 mScrollPostPosition = mScrollTargetPosition;
1788 WrapPosition(mScrollPostPosition);
1791 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 );
1792 DALI_LOG_SCROLL_STATE("[0x%X] mPropertyPrePosition[%.2f, %.2f], mPropertyPosition[%.2f, %.2f]", this, self.GetProperty( mPropertyPrePosition ).Get<Vector3>().x, self.GetProperty( mPropertyPrePosition ).Get<Vector3>().y, self.GetProperty( mPropertyPosition ).Get<Vector3>().x, self.GetProperty( mPropertyPosition ).Get<Vector3>().y );
1795 SetScrollUpdateNotification(true);
1797 // Always send a snap event when AnimateTo is called.
1798 Toolkit::ScrollView::SnapEvent snapEvent;
1799 snapEvent.type = snapType;
1800 snapEvent.position = -mScrollTargetPosition;
1801 snapEvent.duration = totalDuration;
1803 DALI_LOG_SCROLL_STATE("[0x%X] mSnapStartedSignalV2 [%.2f, %.2f]", this, snapEvent.position.x, snapEvent.position.y);
1804 mSnapStartedSignalV2.Emit( snapEvent );
1806 return (mScrollStateFlags & SCROLL_ANIMATION_FLAGS) != 0;
1809 void ScrollView::SetOvershootEnabled(bool enabled)
1811 if(enabled && !mOvershootIndicator)
1813 mOvershootIndicator = ScrollOvershootIndicator::New();
1817 mMaxOvershoot = OVERSCROLL_CLAMP;
1818 mOvershootIndicator->AttachToScrollable(*this);
1822 mMaxOvershoot = mUserMaxOvershoot;
1823 mOvershootIndicator->DetachFromScrollable(*this);
1825 UpdateMainInternalConstraint();
1828 void ScrollView::AddOverlay(Actor actor)
1830 mInternalActor.Add( actor );
1833 void ScrollView::RemoveOverlay(Actor actor)
1835 mInternalActor.Remove( actor );
1838 void ScrollView::SetOvershootEffectColor( const Vector4& color )
1840 mOvershootEffectColor = color;
1841 if( mOvershootIndicator )
1843 mOvershootIndicator->SetOvershootEffectColor( color );
1847 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
1849 PanGestureDetector panGesture( GetPanGestureDetector() );
1851 // First remove just in case we have some set, then add.
1852 panGesture.RemoveDirection( direction );
1853 panGesture.AddDirection( direction, threshold );
1856 void ScrollView::RemoveScrollingDirection( Radian direction )
1858 PanGestureDetector panGesture( GetPanGestureDetector() );
1859 panGesture.RemoveDirection( direction );
1862 Toolkit::ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
1864 return mSnapStartedSignalV2;
1867 void ScrollView::FindAndUnbindActor(Actor child)
1872 Vector3 ScrollView::GetPropertyPrePosition() const
1874 Vector3 position = Self().GetProperty<Vector3>(mPropertyPrePosition);
1875 WrapPosition(position);
1879 Vector3 ScrollView::GetPropertyPosition() const
1881 Vector3 position = Self().GetProperty<Vector3>(mPropertyPosition);
1882 WrapPosition(position);
1887 void ScrollView::HandleStoppedAnimation()
1889 SetScrollUpdateNotification(false);
1892 void ScrollView::HandleSnapAnimationFinished()
1894 // Emit Signal that scrolling has completed.
1896 Actor self = Self();
1897 self.SetProperty(mPropertyScrolling, false);
1899 Vector3 deltaPosition(mScrollPrePosition);
1901 UpdateLocalScrollProperties();
1902 WrapPosition(mScrollPrePosition);
1903 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
1904 self.SetProperty(mPropertyPrePosition, mScrollPrePosition);
1906 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1907 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 3 current[%.2f, %.2f], mScrollTargetPosition[%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y, -mScrollTargetPosition.x, -mScrollTargetPosition.y );
1908 mScrollCompletedSignalV2.Emit( currentScrollPosition );
1910 mDomainOffset += deltaPosition - mScrollPostPosition;
1911 self.SetProperty(mPropertyDomainOffset, mDomainOffset);
1912 HandleStoppedAnimation();
1915 void ScrollView::SetScrollUpdateNotification( bool enabled )
1917 Actor self = Self();
1918 if( mScrollXUpdateNotification )
1920 // disconnect now to avoid a notification before removed from update thread
1921 mScrollXUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
1922 self.RemovePropertyNotification(mScrollXUpdateNotification);
1923 mScrollXUpdateNotification.Reset();
1927 mScrollXUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 0, StepCondition(mScrollUpdateDistance, 0.0f));
1928 mScrollXUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
1930 if( mScrollYUpdateNotification )
1932 // disconnect now to avoid a notification before removed from update thread
1933 mScrollYUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
1934 self.RemovePropertyNotification(mScrollYUpdateNotification);
1935 mScrollYUpdateNotification.Reset();
1939 mScrollYUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 1, StepCondition(mScrollUpdateDistance, 0.0f));
1940 mScrollYUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
1944 void ScrollView::OnScrollUpdateNotification(Dali::PropertyNotification& source)
1946 // Guard against destruction during signal emission
1947 Toolkit::ScrollView handle( GetOwner() );
1949 Vector3 currentScrollPosition = GetCurrentScrollPosition();
1950 mScrollUpdatedSignalV2.Emit( currentScrollPosition );
1953 bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1955 Dali::BaseHandle handle( object );
1957 bool connected( true );
1958 Toolkit::ScrollView view = Toolkit::ScrollView::DownCast( handle );
1960 if( Toolkit::ScrollView::SIGNAL_SNAP_STARTED == signalName )
1962 view.SnapStartedSignal().Connect( tracker, functor );
1966 // signalName does not match any signal
1973 void ScrollView::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1975 // need to update domain properties for new size
1976 UpdatePropertyDomain(targetSize);
1979 void ScrollView::OnControlSizeSet( const Vector3& size )
1981 // need to update domain properties for new size
1982 if( mDefaultMaxOvershoot )
1984 mUserMaxOvershoot.x = size.x * 0.5f;
1985 mUserMaxOvershoot.y = size.y * 0.5f;
1986 if( !IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
1988 mMaxOvershoot = mUserMaxOvershoot;
1991 UpdatePropertyDomain(size);
1992 UpdateMainInternalConstraint();
1993 if( IsScrollComponentEnabled(Toolkit::Scrollable::OvershootIndicator) )
1995 mOvershootIndicator->Reset();
1999 void ScrollView::OnChildAdd(Actor& child)
2007 void ScrollView::OnChildRemove(Actor& child)
2009 // TODO: Actor needs a RemoveConstraint method to take out an individual constraint.
2013 void ScrollView::OnPropertySet( Property::Index index, Property::Value propertyValue )
2015 Actor self = Self();
2016 if( index == mPropertyX )
2018 self.GetProperty(mPropertyPrePosition).Get(mScrollPrePosition);
2019 propertyValue.Get(mScrollPrePosition.x);
2020 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2021 self.SetProperty(mPropertyPrePosition, mScrollPrePosition);
2023 else if( index == mPropertyY )
2025 self.GetProperty(mPropertyPrePosition).Get(mScrollPrePosition);
2026 propertyValue.Get(mScrollPrePosition.y);
2027 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2028 self.SetProperty(mPropertyPrePosition, mScrollPrePosition);
2030 else if( index == mPropertyPrePosition )
2032 DALI_LOG_SCROLL_STATE("[0x%X]: mPropertyPrePosition[%.2f, %.2f]", this, propertyValue.Get<Vector3>().x, propertyValue.Get<Vector3>().y);
2033 propertyValue.Get(mScrollPrePosition);
2037 void ScrollView::StartTouchDownTimer()
2039 if ( !mTouchDownTimer )
2041 mTouchDownTimer = Timer::New( TOUCH_DOWN_TIMER_INTERVAL );
2042 mTouchDownTimer.TickSignal().Connect( this, &ScrollView::OnTouchDownTimeout );
2045 mTouchDownTimer.Start();
2048 void ScrollView::StopTouchDownTimer()
2050 if ( mTouchDownTimer )
2052 mTouchDownTimer.Stop();
2056 bool ScrollView::OnTouchDownTimeout()
2058 DALI_LOG_SCROLL_STATE("[0x%X]", this);
2060 mTouchDownTimeoutReached = true;
2062 unsigned int currentScrollStateFlags( mScrollStateFlags ); // Cleared in StopAnimation so keep local copy for comparison
2063 if( currentScrollStateFlags & (SCROLL_ANIMATION_FLAGS | SNAP_ANIMATION_FLAGS) )
2065 DALI_LOG_SCROLL_STATE("[0x%X] Scrolling Or snapping flags set, stopping animation", this);
2068 if( currentScrollStateFlags & SCROLL_ANIMATION_FLAGS )
2070 DALI_LOG_SCROLL_STATE("[0x%X] Scrolling flags set, emitting signal", this);
2072 mScrollInterrupted = true;
2073 // reset domain offset as scrolling from original plane.
2074 mDomainOffset = Vector3::ZERO;
2075 Self().SetProperty(mPropertyDomainOffset, Vector3::ZERO);
2077 UpdateLocalScrollProperties();
2078 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2079 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 4 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2080 mScrollCompletedSignalV2.Emit( currentScrollPosition );
2087 bool ScrollView::OnTouchEvent(const TouchEvent& event)
2091 DALI_LOG_SCROLL_STATE("[0x%X], Not Sensitive, ignoring", this);
2093 // Ignore this touch event, if scrollview is insensitive.
2097 // Ignore events with multiple-touch points
2098 if (event.GetPointCount() != 1)
2100 DALI_LOG_SCROLL_STATE("[0x%X], multiple touch, ignoring", this);
2105 const TouchPoint::State pointState = event.GetPoint(0).state;
2106 if( pointState == TouchPoint::Down )
2108 DALI_LOG_SCROLL_STATE("[0x%X] Down", this);
2110 if(mGestureStackDepth==0)
2112 mTouchDownTime = event.time;
2114 // This allows time for a pan-gesture to start, to avoid breaking snap-animation behavior with fast flicks.
2115 // If touch-down does not become a pan (after timeout interval), then snap-animation can be interrupted.
2116 mTouchDownTimeoutReached = false;
2117 mScrollInterrupted = false;
2118 StartTouchDownTimer();
2121 else if( ( pointState == TouchPoint::Up ) ||
2122 ( ( pointState == TouchPoint::Interrupted ) && ( event.GetPoint(0).hitActor == Self() ) ) )
2124 DALI_LOG_SCROLL_STATE("[0x%X] %s", this, ( ( pointState == TouchPoint::Up ) ? "Up" : "Interrupted" ) );
2126 StopTouchDownTimer();
2128 // if the user touches and releases without enough movement to go
2129 // into a gesture state, then we should snap to nearest point.
2130 // otherwise our scroll could be stopped (interrupted) half way through an animation.
2131 if(mGestureStackDepth==0 && mTouchDownTimeoutReached)
2133 if( ( event.GetPoint(0).state == TouchPoint::Interrupted ) ||
2134 ( ( event.time - mTouchDownTime ) >= MINIMUM_TIME_BETWEEN_DOWN_AND_UP_FOR_RESET ) )
2136 // Reset the velocity only if down was received a while ago
2137 mLastVelocity = Vector2( 0.0f, 0.0f );
2140 UpdateLocalScrollProperties();
2141 // Only finish the transform if scrolling was interrupted on down or if we are scrolling
2142 if ( mScrollInterrupted || mScrolling )
2144 DALI_LOG_SCROLL_STATE("[0x%X] Calling FinishTransform", this);
2149 mTouchDownTimeoutReached = false;
2150 mScrollInterrupted = false;
2156 bool ScrollView::OnMouseWheelEvent(const MouseWheelEvent& event)
2160 // Ignore this mouse wheel event, if scrollview is insensitive.
2164 Vector3 targetScrollPosition = GetPropertyPosition();
2166 if(mRulerX->IsEnabled() && !mRulerY->IsEnabled())
2168 // If only the ruler in the X axis is enabled, scroll in the X axis.
2169 if(mRulerX->GetType() == Ruler::Free)
2171 // Free panning mode
2172 targetScrollPosition.x += event.z * mMouseWheelScrollDistanceStep.x;
2173 ClampPosition(targetScrollPosition);
2174 ScrollTo(-targetScrollPosition);
2176 else if(!mScrolling)
2178 // Snap mode, only respond to the event when the previous snap animation is finished.
2179 ScrollTo(GetCurrentPage() - event.z);
2184 // If the ruler in the Y axis is enabled, scroll in the Y axis.
2185 if(mRulerY->GetType() == Ruler::Free)
2187 // Free panning mode
2188 targetScrollPosition.y += event.z * mMouseWheelScrollDistanceStep.y;
2189 ClampPosition(targetScrollPosition);
2190 ScrollTo(-targetScrollPosition);
2192 else if(!mScrolling)
2194 // Snap mode, only respond to the event when the previous snap animation is finished.
2195 ScrollTo(GetCurrentPage() - event.z * mRulerX->GetTotalPages());
2202 void ScrollView::ResetScrolling()
2204 Actor self = Self();
2205 self.GetProperty(mPropertyPosition).Get(mScrollPostPosition);
2206 mScrollPrePosition = mScrollPostPosition;
2207 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPostPosition.x, mScrollPostPosition.y );
2208 self.SetProperty(mPropertyPrePosition, mScrollPostPosition);
2211 void ScrollView::UpdateLocalScrollProperties()
2213 Actor self = Self();
2214 self.GetProperty(mPropertyPrePosition).Get(mScrollPrePosition);
2215 self.GetProperty(mPropertyPosition).Get(mScrollPostPosition);
2218 // private functions
2220 void ScrollView::PreAnimatedScrollSetup()
2222 // mPropertyPrePosition is our unclamped property with wrapping
2223 // mPropertyPosition is our final scroll position after clamping
2225 Actor self = Self();
2227 Vector3 deltaPosition(mScrollPostPosition);
2228 WrapPosition(mScrollPostPosition);
2229 mDomainOffset += deltaPosition - mScrollPostPosition;
2230 Self().SetProperty(mPropertyDomainOffset, mDomainOffset);
2232 if( mScrollStateFlags & SCROLL_X_STATE_MASK )
2234 // already performing animation on internal x position
2235 StopAnimation(mInternalXAnimation);
2238 if( mScrollStateFlags & SCROLL_Y_STATE_MASK )
2240 // already performing animation on internal y position
2241 StopAnimation(mInternalYAnimation);
2244 mScrollStateFlags = 0;
2246 // Update Actor position with this wrapped value.
2249 void ScrollView::FinaliseAnimatedScroll()
2251 // TODO - common animation finishing code in here
2254 void ScrollView::AnimateInternalXTo( float position, float duration, AlphaFunction alpha )
2256 StopAnimation(mInternalXAnimation);
2258 if( duration > Math::MACHINE_EPSILON_10 )
2260 Actor self = Self();
2261 DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(mPropertyPrePosition).Get<Vector3>().x, position );
2262 mInternalXAnimation = Animation::New(duration);
2263 DALI_LOG_SCROLL_STATE("[0x%X], mInternalXAnimation[0x%X]", this, mInternalXAnimation.GetObjectPtr() );
2264 mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
2265 mInternalXAnimation.AnimateTo( Property(self, mPropertyPrePosition, 0), position, alpha, duration);
2266 mInternalXAnimation.Play();
2268 // erase current state flags
2269 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2270 // add internal animation state flag
2271 mScrollStateFlags |= AnimatingInternalX;
2275 void ScrollView::AnimateInternalYTo( float position, float duration, AlphaFunction alpha )
2277 StopAnimation(mInternalYAnimation);
2279 if( duration > Math::MACHINE_EPSILON_10 )
2281 Actor self = Self();
2282 DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(mPropertyPrePosition).Get<Vector3>().y, position );
2283 mInternalYAnimation = Animation::New(duration);
2284 DALI_LOG_SCROLL_STATE("[0x%X], mInternalYAnimation[0x%X]", this, mInternalYAnimation.GetObjectPtr() );
2285 mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
2286 mInternalYAnimation.AnimateTo( Property(self, mPropertyPrePosition, 1), position, alpha, TimePeriod(duration));
2287 mInternalYAnimation.Play();
2289 // erase current state flags
2290 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2291 // add internal animation state flag
2292 mScrollStateFlags |= AnimatingInternalY;
2296 void ScrollView::OnScrollAnimationFinished( Animation& source )
2298 // Guard against destruction during signal emission
2299 // Note that ScrollCompletedSignal is emitted from HandleSnapAnimationFinished()
2300 Toolkit::ScrollView handle( GetOwner() );
2302 bool scrollingFinished = false;
2304 // update our local scroll positions
2305 UpdateLocalScrollProperties();
2307 if( source == mInternalXAnimation )
2309 DALI_LOG_SCROLL_STATE("[0x%X] mInternalXAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalXAnimation.GetObjectPtr(), mScrollTargetPosition.x, Self().GetProperty(mPropertyPrePosition).Get<Vector3>().x, mScrollPostPosition.x );
2311 if( !(mScrollStateFlags & AnimatingInternalY) )
2313 scrollingFinished = true;
2315 mInternalXAnimation.Reset();
2316 // wrap pre scroll x position and set it
2319 const RulerDomain rulerDomain = mRulerX->GetDomain();
2320 mScrollPrePosition.x = -WrapInDomain(-mScrollPrePosition.x, rulerDomain.min, rulerDomain.max);
2321 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2322 handle.SetProperty(mPropertyPrePosition, mScrollPrePosition);
2324 SnapInternalXTo(mScrollPostPosition.x);
2327 if( source == mInternalYAnimation )
2329 DALI_LOG_SCROLL_STATE("[0x%X] mInternalYAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalYAnimation.GetObjectPtr(), mScrollTargetPosition.y, Self().GetProperty(mPropertyPrePosition).Get<Vector3>().y, mScrollPostPosition.y );
2331 if( !(mScrollStateFlags & AnimatingInternalX) )
2333 scrollingFinished = true;
2335 mInternalYAnimation.Reset();
2338 // wrap pre scroll y position and set it
2339 const RulerDomain rulerDomain = mRulerY->GetDomain();
2340 mScrollPrePosition.y = -WrapInDomain(-mScrollPrePosition.y, rulerDomain.min, rulerDomain.max);
2341 DALI_LOG_SCROLL_STATE("[0x%X] Setting mPropertyPrePosition To[%.2f, %.2f]", this, mScrollPrePosition.x, mScrollPrePosition.y );
2342 handle.SetProperty(mPropertyPrePosition, mScrollPrePosition);
2344 SnapInternalYTo(mScrollPostPosition.y);
2347 DALI_LOG_SCROLL_STATE("[0x%X] scrollingFinished[%d] Animation[0x%X]", this, scrollingFinished, source.GetObjectPtr());
2349 if(scrollingFinished)
2351 HandleSnapAnimationFinished();
2355 void ScrollView::OnSnapInternalPositionFinished( Animation& source )
2357 Actor self = Self();
2358 UpdateLocalScrollProperties();
2359 if( source == mInternalXAnimation )
2361 DALI_LOG_SCROLL_STATE("[0x%X] Finished X PostPosition Animation", this );
2363 // clear internal x animation flags
2364 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2365 mInternalXAnimation.Reset();
2366 WrapPosition(mScrollPrePosition);
2368 if( source == mInternalYAnimation )
2370 DALI_LOG_SCROLL_STATE("[0x%X] Finished Y PostPosition Animation", this );
2372 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2373 mInternalYAnimation.Reset();
2374 WrapPosition(mScrollPrePosition);
2378 void ScrollView::SnapInternalXTo(float position)
2380 Actor self = Self();
2382 StopAnimation(mInternalXAnimation);
2384 // erase current state flags
2385 mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
2387 // if internal x not equal to inputed parameter, animate it
2388 float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration);
2389 DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration );
2390 if( duration > Math::MACHINE_EPSILON_1 )
2392 DALI_LOG_SCROLL_STATE("[0x%X] Starting X Snap Animation to[%.2f]", this, position );
2394 mInternalXAnimation = Animation::New(duration);
2395 mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
2396 mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position);
2397 mInternalXAnimation.Play();
2399 // add internal animation state flag
2400 mScrollStateFlags |= SnappingInternalX;
2404 void ScrollView::SnapInternalYTo(float position)
2406 Actor self = Self();
2408 StopAnimation(mInternalYAnimation);
2410 // erase current state flags
2411 mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
2413 // if internal y not equal to inputed parameter, animate it
2414 float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration);
2415 DALI_LOG_SCROLL_STATE("[0x%X] duration[%.2f]", this, duration );
2416 if( duration > Math::MACHINE_EPSILON_1 )
2418 DALI_LOG_SCROLL_STATE("[0x%X] Starting Y Snap Animation to[%.2f]", this, position );
2420 mInternalYAnimation = Animation::New(duration);
2421 mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
2422 mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position);
2423 mInternalYAnimation.Play();
2425 // add internal animation state flag
2426 mScrollStateFlags |= SnappingInternalY;
2430 void ScrollView::GestureStarted()
2432 // we handle the first gesture.
2433 // if we're currently doing a gesture and receive another
2434 // we continue and combine the effects of the gesture instead of reseting.
2435 if(mGestureStackDepth++==0)
2437 Actor self = Self();
2438 StopTouchDownTimer();
2440 mPanDelta = Vector3::ZERO;
2441 mLastVelocity = Vector2(0.0f, 0.0f);
2444 mLockAxis = LockPossible;
2447 if( mScrollStateFlags & SCROLL_X_STATE_MASK )
2449 StopAnimation(mInternalXAnimation);
2451 if( mScrollStateFlags & SCROLL_Y_STATE_MASK )
2453 StopAnimation(mInternalYAnimation);
2455 mScrollStateFlags = 0;
2457 if(mScrolling) // are we interrupting a current scroll?
2459 // set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
2461 // send negative scroll position since scroll internal scroll position works as an offset for actors,
2462 // give applications the position within the domain from the scroll view's anchor position
2463 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 5 [%.2f, %.2f]", this, -mScrollPostPosition.x, -mScrollPostPosition.y);
2464 mScrollCompletedSignalV2.Emit( -mScrollPostPosition );
2469 void ScrollView::GestureContinuing(const Vector2& panDelta)
2471 mPanDelta.x+= panDelta.x;
2472 mPanDelta.y+= panDelta.y;
2474 // Save the velocity, there is a bug in PanGesture
2475 // Whereby the Gesture::Finished's velocity is either:
2476 // NaN (due to time delta of zero between the last two events)
2477 // or 0 (due to position being the same between the last two events)
2479 // Axis Auto Lock - locks the panning to the horizontal or vertical axis if the pan
2480 // appears mostly horizontal or mostly vertical respectively.
2483 mLockAxis = GetLockAxis(mPanDelta.GetVectorXY(), mLockAxis, mAxisAutoLockGradient);
2484 } // end if mAxisAutoLock
2487 // TODO: Upgrade to use a more powerful gesture detector (one that supports multiple touches on pan - so works as pan and flick gesture)
2488 // BUG: Gesture::Finished doesn't always return velocity on release (due to
2489 // timeDelta between last two events being 0 sometimes, or posiiton being the same)
2490 void ScrollView::OnPan(PanGesture gesture)
2492 // Guard against destruction during signal emission
2493 // Note that Emit() methods are called indirectly e.g. from within ScrollView::OnGestureEx()
2494 Actor self( Self() );
2498 DALI_LOG_SCROLL_STATE("[0x%X] Pan Ignored, Insensitive", this);
2500 // If another callback on the same original signal disables sensitivity,
2501 // this callback will still be called, so we must suppress it.
2505 // translate Gesture input to get useful data...
2506 switch(gesture.state)
2508 case Gesture::Started:
2510 DALI_LOG_SCROLL_STATE("[0x%X] Pan Started", this);
2511 UpdateLocalScrollProperties();
2514 self.SetProperty( mPropertyPanning, true );
2515 self.SetProperty( mPropertyScrollStartPagePosition, Vector3(gesture.position.x, gesture.position.y, 0.0f) );
2517 UpdateMainInternalConstraint();
2521 case Gesture::Continuing:
2525 DALI_LOG_SCROLL_STATE("[0x%X] Pan Continuing", this);
2526 GestureContinuing(gesture.screenDisplacement);
2530 // If we do not think we are panning, then we should not do anything here
2536 case Gesture::Finished:
2537 case Gesture::Cancelled:
2541 DALI_LOG_SCROLL_STATE("[0x%X] Pan %s", this, ( ( gesture.state == Gesture::Finished ) ? "Finished" : "Cancelled" ) );
2543 UpdateLocalScrollProperties();
2544 mLastVelocity = gesture.velocity;
2546 self.SetProperty( mPropertyPanning, false );
2548 if( mScrollMainInternalPrePositionConstraint )
2550 self.RemoveConstraint(mScrollMainInternalPrePositionConstraint);
2553 if( mOvershootIndicator )
2555 mOvershootIndicator->ClearOvershoot();
2560 // If we do not think we are panning, then we should not do anything here
2566 case Gesture::Possible:
2567 case Gesture::Clear:
2569 // Nothing to do, not needed.
2573 } // end switch(gesture.state)
2575 OnGestureEx(gesture.state);
2578 void ScrollView::OnGestureEx(Gesture::State state)
2580 // call necessary signals for application developer
2582 if(state == Gesture::Started)
2584 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2585 Self().SetProperty(mPropertyScrolling, true);
2587 DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2588 mScrollStartedSignalV2.Emit( currentScrollPosition );
2590 else if( (state == Gesture::Finished) ||
2591 (state == Gesture::Cancelled) ) // Finished/default
2593 // when all the gestures have finished, we finish the transform.
2594 // so if a user decides to pan (1 gesture), and then pan+zoom (2 gestures)
2595 // then stop panning (back to 1 gesture), and then stop zooming (0 gestures).
2596 // this is the point we end, and perform necessary snapping.
2597 mGestureStackDepth--;
2598 if(mGestureStackDepth==0)
2600 // no flick if we have not exceeded min flick distance
2601 if( (fabsf(mPanDelta.x) < mMinFlickDistance.x)
2602 && (fabsf(mPanDelta.y) < mMinFlickDistance.y) )
2604 // reset flick velocity
2605 mLastVelocity = Vector2::ZERO;
2611 DALI_LOG_SCROLL_STATE("[0x%X] mGestureStackDepth[%d]", this, mGestureStackDepth);
2616 void ScrollView::FinishTransform()
2618 // at this stage internal x and x scroll position should have followed prescroll position exactly
2619 Actor self = Self();
2621 PreAnimatedScrollSetup();
2623 // convert pixels/millisecond to pixels per second
2624 bool animating = SnapWithVelocity(mLastVelocity * 1000.0f);
2628 // if not animating, then this pan has completed right now.
2629 SetScrollUpdateNotification(false);
2631 Self().SetProperty(mPropertyScrolling, false);
2633 if( fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10 )
2635 SnapInternalXTo(mScrollTargetPosition.x);
2637 if( fabs(mScrollPrePosition.y - mScrollTargetPosition.y) > Math::MACHINE_EPSILON_10 )
2639 SnapInternalYTo(mScrollTargetPosition.y);
2641 Vector3 currentScrollPosition = GetCurrentScrollPosition();
2642 DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 6 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
2643 mScrollCompletedSignalV2.Emit( currentScrollPosition );
2647 Vector3 ScrollView::GetOvershoot(Vector3& position) const
2649 Vector3 size = Self().GetCurrentSize();
2652 const RulerDomain rulerDomainX = mRulerX->GetDomain();
2653 const RulerDomain rulerDomainY = mRulerY->GetDomain();
2655 if(mRulerX->IsEnabled() && rulerDomainX.enabled)
2657 const float left = rulerDomainX.min - position.x;
2658 const float right = size.width - rulerDomainX.max - position.x;
2665 overshoot.x = right;
2669 if(mRulerY->IsEnabled() && rulerDomainY.enabled)
2671 const float top = rulerDomainY.min - position.y;
2672 const float bottom = size.height - rulerDomainY.max - position.y;
2679 overshoot.y = bottom;
2686 bool ScrollView::OnAccessibilityPan(PanGesture gesture)
2688 // Keep track of whether this is an AccessibilityPan
2689 mInAccessibilityPan = true;
2691 mInAccessibilityPan = false;
2696 void ScrollView::ClampPosition(Vector3& position) const
2698 ClampState3 clamped;
2699 ClampPosition(position, clamped);
2702 void ScrollView::ClampPosition(Vector3& position, ClampState3 &clamped) const
2704 Vector3 size = Self().GetCurrentSize();
2706 position.x = -mRulerX->Clamp(-position.x, size.width, 1.0f, clamped.x); // NOTE: X & Y rulers think in -ve coordinate system.
2707 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.
2709 clamped.z = NotClamped;
2712 void ScrollView::WrapPosition(Vector3& position) const
2716 const RulerDomain rulerDomainX = mRulerX->GetDomain();
2717 const RulerDomain rulerDomainY = mRulerY->GetDomain();
2719 if(mRulerX->IsEnabled())
2721 position.x = -WrapInDomain(-position.x, rulerDomainX.min, rulerDomainX.max);
2724 if(mRulerY->IsEnabled())
2726 position.y = -WrapInDomain(-position.y, rulerDomainY.min, rulerDomainY.max);
2731 void ScrollView::UpdateMainInternalConstraint()
2733 // TODO: Only update the constraints which have changed, rather than remove all and add all again.
2734 // Requires a dali-core ApplyConstraintAt, or a ReplaceConstraint. The former is probably more flexible.
2735 Actor self = Self();
2736 PanGestureDetector detector( GetPanGestureDetector() );
2738 if(mScrollMainInternalPositionConstraint)
2740 self.RemoveConstraint(mScrollMainInternalPositionConstraint);
2741 self.RemoveConstraint(mScrollMainInternalDeltaConstraint);
2742 self.RemoveConstraint(mScrollMainInternalFinalConstraint);
2743 self.RemoveConstraint(mScrollMainInternalRelativeConstraint);
2744 self.RemoveConstraint(mScrollMainInternalXConstraint);
2745 self.RemoveConstraint(mScrollMainInternalYConstraint);
2747 if( mScrollMainInternalPrePositionConstraint )
2749 self.RemoveConstraint(mScrollMainInternalPrePositionConstraint);
2752 // TODO: It's probably better to use a local displacement value as this will give a displacement when scrolling just commences
2753 // but we need to make sure than the gesture system gives displacement since last frame (60Hz), not displacement since last touch event (90Hz).
2755 // 1. First calculate the pre-position (this is the scroll position if no clamping has taken place)
2756 Vector2 initialPanMask = Vector2(mRulerX->IsEnabled() ? 1.0f : 0.0f, mRulerY->IsEnabled() ? 1.0f : 0.0f);
2758 if( mLockAxis == LockVertical )
2760 initialPanMask.y = 0.0f;
2762 else if( mLockAxis == LockHorizontal )
2764 initialPanMask.x = 0.0f;
2766 Constraint constraint;
2770 constraint = Constraint::New<Vector3>( mPropertyPrePosition,
2771 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2772 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2773 Source( self, Actor::SIZE ),
2774 InternalPrePositionConstraint( initialPanMask, mAxisAutoLock, mAxisAutoLockGradient, mLockAxis, mMaxOvershoot, mRulerX->GetDomain(), mRulerY->GetDomain() ) );
2775 mScrollMainInternalPrePositionConstraint = self.ApplyConstraint( constraint );
2778 // 2. Second calculate the clamped position (actual position)
2779 constraint = Constraint::New<Vector3>( mPropertyPosition,
2780 LocalSource( mPropertyPrePosition ),
2781 LocalSource( mPropertyPositionMin ),
2782 LocalSource( mPropertyPositionMax ),
2783 Source( self, Actor::SIZE ),
2784 InternalPositionConstraint( mRulerX->GetDomain(),
2785 mRulerY->GetDomain(), mWrapMode ) );
2786 mScrollMainInternalPositionConstraint = self.ApplyConstraint( constraint );
2788 constraint = Constraint::New<Vector3>( mPropertyPositionDelta,
2789 LocalSource( mPropertyPosition ),
2790 LocalSource( mPropertyDomainOffset ),
2791 InternalPositionDeltaConstraint );
2792 mScrollMainInternalDeltaConstraint = self.ApplyConstraint( constraint );
2794 constraint = Constraint::New<Vector3>( mPropertyFinal,
2795 LocalSource( mPropertyPosition ),
2796 LocalSource( mPropertyOvershootX ),
2797 LocalSource( mPropertyOvershootY ),
2798 InternalFinalConstraint( FinalDefaultAlphaFunction,
2799 FinalDefaultAlphaFunction ) );
2800 mScrollMainInternalFinalConstraint = self.ApplyConstraint( constraint );
2802 constraint = Constraint::New<Vector3>( mPropertyRelativePosition,
2803 LocalSource( mPropertyPosition ),
2804 LocalSource( mPropertyPositionMin ),
2805 LocalSource( mPropertyPositionMax ),
2806 LocalSource( Actor::SIZE ),
2807 InternalRelativePositionConstraint );
2808 mScrollMainInternalRelativeConstraint = self.ApplyConstraint( constraint );
2810 constraint = Constraint::New<float>( mPropertyX,
2811 LocalSource( mPropertyPrePosition ),
2812 InternalXConstraint );
2813 mScrollMainInternalXConstraint = self.ApplyConstraint( constraint );
2815 constraint = Constraint::New<float>( mPropertyY,
2816 LocalSource( mPropertyPrePosition ),
2817 InternalYConstraint );
2818 mScrollMainInternalYConstraint = self.ApplyConstraint( constraint );
2820 // When panning we want to make sure overshoot values are affected by pre position and post position
2821 SetOvershootConstraintsEnabled(!mWrapMode);
2824 void ScrollView::SetOvershootConstraintsEnabled(bool enabled)
2826 Actor self( Self() );
2827 // remove and reset, it may now be in wrong order with the main internal constraints
2828 if( mScrollMainInternalOvershootXConstraint )
2830 self.RemoveConstraint(mScrollMainInternalOvershootXConstraint);
2831 mScrollMainInternalOvershootXConstraint.Reset();
2832 self.RemoveConstraint(mScrollMainInternalOvershootYConstraint);
2833 mScrollMainInternalOvershootYConstraint.Reset();
2837 Constraint constraint = Constraint::New<float>( mPropertyOvershootX,
2838 LocalSource( mPropertyPrePosition ),
2839 LocalSource( mPropertyPosition ),
2840 LocalSource( mPropertyCanScrollHorizontal ),
2841 OvershootXConstraint(mMaxOvershoot.x) );
2842 mScrollMainInternalOvershootXConstraint = self.ApplyConstraint( constraint );
2844 constraint = Constraint::New<float>( mPropertyOvershootY,
2845 LocalSource( mPropertyPrePosition ),
2846 LocalSource( mPropertyPosition ),
2847 LocalSource( mPropertyCanScrollVertical ),
2848 OvershootYConstraint(mMaxOvershoot.y) );
2849 mScrollMainInternalOvershootYConstraint = self.ApplyConstraint( constraint );
2853 self.SetProperty(mPropertyOvershootX, 0.0f);
2854 self.SetProperty(mPropertyOvershootY, 0.0f);
2858 void ScrollView::SetInternalConstraints()
2860 // Internal constraints (applied to target ScrollBase Actor itself) /////////
2861 UpdateMainInternalConstraint();
2863 // User definable constraints to apply to all child actors //////////////////
2864 Actor self = Self();
2866 // LocalSource - The Actors to be moved.
2867 // self - The ScrollView
2869 // Apply some default constraints to ScrollView.
2870 // Movement + Wrap function
2871 // TODO: Look into removing some of these constraints
2873 Constraint constraint;
2875 // MoveScaledActor (scrolling/zooming)
2876 constraint = Constraint::New<Vector3>( Actor::POSITION,
2877 Source( self, mPropertyPosition ),
2878 Source( self, mPropertyScale ),
2879 MoveScaledActorConstraint );
2880 constraint.SetRemoveAction(Constraint::Discard);
2881 ApplyConstraintToBoundActors(constraint);
2883 // ScaleActor (scrolling/zooming)
2884 constraint = Constraint::New<Vector3>( Actor::SCALE,
2885 Source( self, mPropertyScale ),
2886 ScaleActorConstraint );
2887 constraint.SetRemoveAction(Constraint::Discard);
2888 ApplyConstraintToBoundActors(constraint);
2890 // WrapActor (wrap functionality)
2891 constraint = Constraint::New<Vector3>( Actor::POSITION,
2892 LocalSource( Actor::SCALE ),
2893 LocalSource( Actor::ANCHOR_POINT ),
2894 LocalSource( Actor::SIZE ),
2895 Source( self, mPropertyPositionMin ),
2896 Source( self, mPropertyPositionMax ),
2897 Source( self, mPropertyWrap ),
2898 WrapActorConstraint );
2899 constraint.SetRemoveAction(Constraint::Discard);
2900 ApplyConstraintToBoundActors(constraint);
2903 } // namespace Internal
2905 } // namespace Toolkit