*
*/
-// INTERNAL INCLUDES
+// CLASS HEADER
+#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
+
+// EXTERNAL INCLUDES
#include <dali/public-api/events/mouse-wheel-event.h>
+#include <dali/integration-api/debug.h>
+// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
#include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
-#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-overshoot-indicator-impl.h>
-#include <dali/integration-api/debug.h>
//#define ENABLED_SCROLL_STATE_LOGGING
#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)
* 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
{
: ScrollBase(),
mTouchDownTime(0u),
mGestureStackDepth(0),
- mRotationDelta(0.0f),
mScrollStateFlags(0),
- mScrollPreRotation(0.0f),
- mScrollPostRotation(0.0f),
mMinTouchesForPanning(1),
mMaxTouchesForPanning(1),
mLockAxis(LockPossible),
RegisterProperties();
mScrollPostPosition = mScrollPrePosition = Vector3::ZERO;
- mScrollPostScale = mScrollPreScale = Vector3::ONE;
- mScrollPostRotation = mScrollPreRotation = 0.0f;
mMouseWheelScrollDistanceStep = Stage::GetCurrent().GetSize() * DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION;
// 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);
}
}
-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();
mScrollPrePosition = position;
}
-Vector3 ScrollView::GetCurrentScrollScale() const
-{
- // in case animation is currently taking place.
- return GetPropertyScale();
-}
-
Vector3 ScrollView::GetDomainSize() const
{
Vector3 size = Self().GetCurrentSize();
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() );
// Note that Emit() methods are called indirectly e.g. from within ScrollView::AnimateTo()
Toolkit::ScrollView handle( GetOwner() );
- DALI_LOG_SCROLL_STATE("[0x%X] pos[%.2f,%.2f], scale[%.2f,%.2f], rot[%.2f], duration[%.2f] bias[%d, %d]",
- this, position.x, position.y, scale.x, scale.y, rotation, duration, int(horizontalBias), int(verticalBias));
+ 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 );
mScrollStartedSignalV2.Emit( currentScrollPosition );
bool animating = AnimateTo(-position,
Vector3::ONE * duration,
- scale,
- Vector3::ONE * duration,
- rotation,
- duration,
mSnapAlphaFunction,
true,
horizontalBias,
DALI_LOG_SCROLL_STATE("[0x%X] position[%.2f, %.2f] duration[%.2f]",
this, position.x, position.y, duration, int(horizontalBias), int(verticalBias));
- TransformTo(position, mScrollPostScale, mScrollPostRotation, duration, horizontalBias, verticalBias);
+ TransformTo(position, duration, horizontalBias, verticalBias);
}
void ScrollView::ScrollTo(unsigned int page)
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)
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;
}
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);
void ScrollView::StopAnimation(void)
{
// Clear Snap animation if exists.
- StopAnimation(mSnapAnimation);
StopAnimation(mInternalXAnimation);
StopAnimation(mInternalYAnimation);
mScrollStateFlags = 0;
}
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)
float totalDuration = 0.0f;
bool positionChanged = (mScrollTargetPosition != mScrollPostPosition);
- bool scaleChanged = (scale != mScrollPostScale);
- bool rotationChanged = fabsf(rotation - mScrollPostRotation) > Math::MACHINE_EPSILON_0;
if(positionChanged)
{
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 ///////////////////////////////////////////////////////
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 );
}
- // 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;
- }
- }
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);
return position;
}
-Vector3 ScrollView::GetPropertyScale() const
-{
- return Self().GetProperty<Vector3>(mPropertyScale);
-}
-
void ScrollView::HandleStoppedAnimation()
{
SetScrollUpdateNotification(false);
mScrollStateFlags = 0;
- mScrollPostScale = GetPropertyScale();
-
// Update Actor position with this wrapped value.
- // TODO Rotation
-
- mScrollPreScale = mScrollPostScale;
- mScrollPreRotation = mScrollPostRotation;
}
void ScrollView::FinaliseAnimatedScroll()
// update our local scroll positions
UpdateLocalScrollProperties();
- if( source == mSnapAnimation )
- {
- DALI_LOG_SCROLL_STATE("[0x%X] mSnapAnimation[0x%X]", this, mSnapAnimation.GetObjectPtr() );
-
- // 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<Vector3>().x, mScrollPostPosition.x );
StopTouchDownTimer();
StopAnimation();
mPanDelta = Vector3::ZERO;
- mScaleDelta = Vector3::ONE;
- mRotationDelta = 0.0f;
mLastVelocity = Vector2(0.0f, 0.0f);
if( !mScrolling )
{
}
}
-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:
}
// 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)
if ( mPanning )
{
DALI_LOG_SCROLL_STATE("[0x%X] Pan Continuing", this);
- GestureContinuing(gesture.screenDisplacement, Vector2::ZERO, 0.0f);
+ GestureContinuing(gesture.screenDisplacement);
}
else
{
}
}
-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
{
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.
}
}
-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.
// self - The ScrollView
// Apply some default constraints to ScrollView.
- // Movement + Scaling + Wrap function
+ // Movement + Wrap function
+ // TODO: Look into removing some of these constraints
Constraint constraint;
void SetRulerY(RulerPtr ruler);
/**
- * @copydoc Toolkit::ScrollView::SetRulerScaleX
- */
- void SetRulerScaleX(RulerPtr ruler);
-
- /**
- * @copydoc Toolkit::ScrollView::SetRulerScaleY
- */
- void SetRulerScaleY(RulerPtr ruler);
-
- /**
- * Set Rotation axis ruler (defines how rotating is snapped in radians)
- * @param[in] ruler The ruler to be used for the Rotation axis
- */
- void SetRulerRotation(RulerPtr ruler);
-
- /**
* @copydoc Toolkit::ScrollView::SetScrollSensitive
*/
void SetScrollSensitive(bool sensitive);
void SetScrollPosition(const Vector3& position);
/**
- * @copydoc Toolkit::ScrollView::GetCurrentScrollScale
- */
- Vector3 GetCurrentScrollScale() const;
-
- /**
* @copydoc Toolkit::Scrollable::GetDomainSize
*/
Vector3 GetDomainSize() const;
/**
- * @copydoc Toolkit::ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation)
+ * @copydoc ScrollTo(const Vector3&)
*/
- void TransformTo(const Vector3& position, const Vector3& scale, float rotation,
+ void TransformTo(const Vector3& position,
DirectionBias horizontalBias = DirectionBiasNone, DirectionBias verticalBias = DirectionBiasNone);
/**
- * @copydoc Toolkit::ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration)
+ * @copydoc ScrollTo(const Vector3&, float, DirectionBias, DirectionBias)
*/
- void TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration,
+ void TransformTo(const Vector3& position, float duration,
DirectionBias horizontalBias = DirectionBiasNone, DirectionBias verticalBias = DirectionBiasNone);
/**
bool ScrollToSnapPoint();
/**
- * @copydoc Toolkit::ScrollView::ScaleTo(const Vector3& scale)
- */
- void ScaleTo(const Vector3& scale);
-
- /**
- * @copydoc Toolkit::ScrollView::ScaleTo(const Vector3& scale, float duration)
- */
- void ScaleTo(const Vector3& scale, float duration);
-
- /**
* Stops animation
*/
void StopAnimation(void);
void StopAnimation(Animation& animation);
/**
- * Animates to position/scale/rotation transform.
+ * Animates to position transform.
*
* @param[in] position The position to animate to
* @param[in] positionDuration The number of seconds this animation should run for in each axis.
- * @param[in] scale The scale to animate to
- * @param[in] scaleDuration The number of seconds this animation should run for in each axis.
- * @param[in] rotation The angle to animate to
- * @param[in] rotationDuration The number of seconds this animation should run for in each axis.
* @param[in] alpha The easing alpha function to use.
* @param[in] findShortcuts (optional) Whether to find the shortest route (in Wrap mode)
* @param[in] horizontalBias (optional) Whether to bias animation to left or right (or no biasing)
* @return True if animation necessary and taking place to reach desired transform.
*/
bool AnimateTo(const Vector3& position, const Vector3& positionDuration,
- const Vector3& scale, const Vector3& scaleDuration,
- float rotation, float rotationDuration,
AlphaFunction alpha, bool findShortcuts = true,
DirectionBias horizontalBias = DirectionBiasNone, DirectionBias verticalBias = DirectionBiasNone,
SnapType snapType = Snap);
* Amalgamated Gesture Continuing event
*
* @param[in] panDelta average panning delta from base position (0)
- * @param[in] scaleDelta average scale delta from base scale (1)
- * @param[in] rotationDelta average rotation delta from base angle (0)
*/
- void GestureContinuing(const Vector2& panDelta, const Vector2& scaleDelta, float rotationDelta);
+ void GestureContinuing(const Vector2& panDelta);
/**
* Called upon pan gesture event.
bool SnapWithVelocity(Vector2 velocity);
/**
- * Updates Container Transform based on Pan, Scale, and Rotation props.
- * (occurs when continuing gesture i.e. dragging/pinching.)
- */
- void UpdateTransform();
-
- /**
* Finishes Container Transform
* (occurs upon finishing gesture i.e. releasing)
*/
void WrapPosition(Vector3& position) const;
/**
- * Clamps scale within the domain set up by Scale-X/Scale-Y Rulers
- *
- * @param[in,out] scale The scale you wish to clamp
- */
- void ClampScale(Vector3& scale) const;
-
- /**
- * Clamps scale within the domain set up by Scale-X/Scale-Y Rulers
- *
- * @param[in,out] scale The scale you wish to clamp
- * @param[out] clamped The results of the clamping.
- */
- void ClampScale(Vector3& scale, ClampState3 &clamped) const;
-
- /**
* Updates the main internal scroll constraints with new ruler and domain
* values
*/
Vector3 GetPropertyPosition() const;
/**
- * Gets scale property.
- *
- * @return The current scale
- */
- Vector3 GetPropertyScale() const;
-
- /**
- * Handles a Stopped animation. Its position/scale/rotation properties need to be
- * saved, and the animation flag switched off.
+ * Handles a Stopped animation. Its position properties need to be saved, and the animation flag
+ * switched off.
*/
void HandleStoppedAnimation();
/**
* Handles a Stopped animation (whether the animation completed, or was
- * manually stopped). Its position/scale/rotation properties need to be
- * saved, and the animation flag switched off.
+ * manually stopped). Its position properties need to be saved, and the
+ * animation flag switched off.
*/
void HandleSnapAnimationFinished();
int mGestureStackDepth; ///< How many gestures are currently occuring.
Vector3 mPanDelta; ///< Amount currently panned.
- Vector3 mScaleDelta; ///< Amount currently scaled.
- float mRotationDelta; ///< Amount currently rotated.
unsigned int mScrollStateFlags; ///< flags indicating current state of scrolling
- // Scroll delegate pre and post position/scale/rotation properties...
+ // Scroll delegate pre and post position properties...
Vector3 mScrollPrePosition; ///< Wrapped scroll position, but not clamped
Vector3 mScrollPostPosition; ///< Wrapped and clamped, this is the final scroll position used
Vector3 mScrollTargetPosition; ///< Final target position for an animated scroll
- Vector3 mScrollPreScale; ///< Scroll delegate pre-scale
- Vector3 mScrollPostScale; ///< Scroll delegate post-scale (affected by current touch)
- float mScrollPreRotation; ///< Scroll delegate pre-rotation
- float mScrollPostRotation; ///< Scroll delegate post-rotation (affected by current touch)
Vector3 mDomainOffset; ///< Domain offset (this keeps track of the domain boundaries that scroll positions traverses)
// Rulers for each axes...
RulerPtr mRulerX;
RulerPtr mRulerY;
- RulerPtr mRulerScaleX;
- RulerPtr mRulerScaleY;
- RulerPtr mRulerRotation;
// Last property values set to ScrollView
Vector3 mMinScroll;
unsigned int mMinTouchesForPanning; ///< Minimum number of touches for panning to be used.
unsigned int mMaxTouchesForPanning; ///< Maximum number of touches for panning to be used.
- Animation mSnapAnimation; ///< Used to animate rotation and scaling of scroll properties
Animation mInternalXAnimation; ///< Animates mPropertyX to a snap position or application requested scroll position
Animation mInternalYAnimation; ///< Animates mPropertyY to a snap position or application requested scroll position