ScrollView - Fix for pixel value used as animation time
authorJulien Heanley <j.heanley@partner.samsung.com>
Tue, 10 Jun 2014 07:53:24 +0000 (08:53 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 11 Jun 2014 08:03:10 +0000 (09:03 +0100)
[problem]      Animation from scroll view had large time preventing update thread from sleeping
[solution]     Clamp animation time

Change-Id: I0d8a26aee100cedf6fb04f69724446dfe3f60354
Signed-off-by: Julien Heanley <j.heanley@partner.samsung.com>
base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp
base/dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h

index d0f05ae..8f54df0 100644 (file)
@@ -2223,9 +2223,7 @@ void ScrollView::OnScrollAnimationFinished( Animation& source )
       scrollingFinished = true;
     }
     mInternalXAnimation.Reset();
       scrollingFinished = true;
     }
     mInternalXAnimation.Reset();
-
-    // erase current state flags
-    mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
+    SnapInternalXTo(mScrollPostPosition.x);
   }
 
   if( source == mInternalYAnimation )
   }
 
   if( source == mInternalYAnimation )
@@ -2235,9 +2233,7 @@ void ScrollView::OnScrollAnimationFinished( Animation& source )
       scrollingFinished = true;
     }
     mInternalYAnimation.Reset();
       scrollingFinished = true;
     }
     mInternalYAnimation.Reset();
-
-    // erase current state flags
-    mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
+    SnapInternalYTo(mScrollPostPosition.y);
   }
 
   if(scrollingFinished)
   }
 
   if(scrollingFinished)
@@ -2246,6 +2242,71 @@ void ScrollView::OnScrollAnimationFinished( Animation& source )
   }
 }
 
   }
 }
 
+void ScrollView::OnSnapInternalPositionFinished( Animation& source )
+{
+  Actor self = Self();
+  UpdateLocalScrollProperties();
+  if( source == mInternalXAnimation )
+  {
+    // clear internal x animation flags
+    mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
+    mInternalXAnimation.Reset();
+    WrapPosition(mScrollPrePosition);
+  }
+  if( source == mInternalYAnimation )
+  {
+    mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
+    mInternalYAnimation.Reset();
+    WrapPosition(mScrollPrePosition);
+  }
+}
+
+void ScrollView::SnapInternalXTo(float position)
+{
+  Actor self = Self();
+
+  StopAnimation(mInternalXAnimation);
+
+  // erase current state flags
+  mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
+
+  // if internal x not equal to inputed parameter, animate it
+  float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration);
+  if( duration > Math::MACHINE_EPSILON_1 )
+  {
+    mInternalXAnimation = Animation::New(duration);
+    mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+    mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position);
+    mInternalXAnimation.Play();
+
+    // add internal animation state flag
+    mScrollStateFlags |= SnappingInternalX;
+  }
+}
+
+void ScrollView::SnapInternalYTo(float position)
+{
+  Actor self = Self();
+
+  StopAnimation(mInternalYAnimation);
+
+  // erase current state flags
+  mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
+
+  // if internal y not equal to inputed parameter, animate it
+  float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration);
+  if( duration > Math::MACHINE_EPSILON_1 )
+  {
+    mInternalYAnimation = Animation::New(duration);
+    mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+    mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position);
+    mInternalYAnimation.Play();
+
+    // add internal animation state flag
+    mScrollStateFlags |= SnappingInternalY;
+  }
+}
+
 void ScrollView::GestureStarted()
 {
   // we handle the first gesture.
 void ScrollView::GestureStarted()
 {
   // we handle the first gesture.
index 1315a66..1591fb6 100644 (file)
@@ -649,6 +649,27 @@ private:
   void OnScrollAnimationFinished( Animation& source );
 
   /**
   void OnScrollAnimationFinished( Animation& source );
 
   /**
+   * Called when either the X or Y internal scroll positions have finished snapping back to mPropertyPrePosition
+   *
+   * @param[in] source the Animation instance that has completed.
+   */
+  void OnSnapInternalPositionFinished( Animation& source );
+
+  /**
+   * Called whenever a snap animation on the x-axis has completed and we need to snap pre scroll
+   * position to our clamped position
+   * @param[in] position The x position to snap pre scroll property to
+   */
+  void SnapInternalXTo( float position );
+
+  /**
+   * Called whenever a snap animation on the y-axis has completed and we need to snap pre scroll
+   * position to our clamped position
+   * @param[in] position The y position to snap pre scroll property to
+   */
+  void SnapInternalYTo( float position );
+
+  /**
    * This is called internally whenever the Scroll Rulers are
    * modified. This will update the properties: 'scroll-position-min'
    * and 'scroll-position-max' to reflect the changes.
    * This is called internally whenever the Scroll Rulers are
    * modified. This will update the properties: 'scroll-position-min'
    * and 'scroll-position-max' to reflect the changes.