(ItemView) Implemented SetOvershootEnabled which is used by Scrollable::Enable/Disabl...
authorJulien Heanley <j.heanley@partner.samsung.com>
Tue, 22 Apr 2014 14:35:22 +0000 (15:35 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 15 May 2014 11:52:10 +0000 (12:52 +0100)
Change-Id: I2c5fa803add707508884b022ae06956fc35c441a

base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp
base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h
base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp

index 001291f..8bebcd5 100644 (file)
@@ -425,16 +425,6 @@ void ItemView::OnInitialize()
 
   Actor self = Self();
 
-  mOvershootEffect = OvershootRippleEffect::New();
-  Image overshootImage = Image::New( OVERSHOOT_OVERLAY_RIPPLE_IMAGE_PATH );
-  mOvershootOverlay = ImageActor::New( overshootImage );
-  mOvershootOverlay.SetParentOrigin(ParentOrigin::TOP_LEFT);
-  mOvershootOverlay.SetAnchorPoint(AnchorPoint::TOP_LEFT);
-  mOvershootOverlay.SetDrawMode(DrawMode::OVERLAY);
-  mOvershootOverlay.SetShaderEffect(mOvershootEffect);
-  mOvershootOverlay.SetPixelArea(OVERSHOOT_BOUNCE_IMAGE_1_PIXEL_AREA);
-  self.Add(mOvershootOverlay);
-
   mScrollConnector = Dali::Toolkit::ScrollConnector::New();
   mScrollPositionObject = mScrollConnector.GetScrollPositionObject();
 
@@ -442,7 +432,7 @@ void ItemView::OnInitialize()
   mPropertyPosition = self.RegisterProperty(POSITION_PROPERTY_NAME, 0.0f);
   mPropertyScrollSpeed = self.RegisterProperty(SCROLL_SPEED_PROPERTY_NAME, 0.0f);
 
-  ApplyOvershootOverlayConstraints();
+  EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator);
 
   Constraint constraint = Constraint::New<Vector3>(mPropertyRelativePosition,
                                                    LocalSource(mPropertyPosition),
@@ -1672,40 +1662,62 @@ void ItemView::ScrollTo(const Vector3& position, float duration)
   mScrollStartedSignalV2.Emit(GetCurrentScrollPosition());
 }
 
-void ItemView::ApplyOvershootOverlayConstraints()
+void ItemView::SetOvershootEnabled( bool enable )
 {
-  Constraint constraint = Constraint::New<float>( Actor::SIZE_WIDTH,
-                                                    ParentSource( mPropertyScrollDirection ),
-                                                    Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
-                                                    ParentSource( Actor::SIZE ),
-                                                    OvershootOverlaySizeConstraint() );
-  mOvershootOverlay.ApplyConstraint(constraint);
-  mOvershootOverlay.SetSize(OVERSHOOT_BOUNCE_IMAGE_1_PIXEL_AREA.width, OVERSHOOT_BOUNCE_IMAGE_1_PIXEL_AREA.height);
-
-  constraint = Constraint::New<Quaternion>( Actor::ROTATION,
-                                            ParentSource( mPropertyScrollDirection ),
-                                            Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
-                                            OvershootOverlayRotationConstraint() );
-  mOvershootOverlay.ApplyConstraint(constraint);
-
-  constraint = Constraint::New<Vector3>( Actor::POSITION,
-                                         ParentSource( Actor::SIZE ),
-                                         ParentSource( mPropertyScrollDirection ),
-                                         Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
-                                         OvershootOverlayPositionConstraint() );
-  mOvershootOverlay.ApplyConstraint(constraint);
-
-  constraint = Constraint::New<bool>( Actor::VISIBLE,
-                                      ParentSource( mPropertyCanScrollVertical ),
-                                      OvershootOverlayVisibilityConstraint() );
-  mOvershootOverlay.ApplyConstraint(constraint);
-
-  int effectOvershootPropertyIndex = mOvershootEffect.GetPropertyIndex(mOvershootEffect.GetOvershootPropertyName());
   Actor self = Self();
-  constraint = Constraint::New<float>( effectOvershootPropertyIndex,
-                                       Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
-                                       EqualToConstraint() );
-  mOvershootEffect.ApplyConstraint(constraint);
+  if( enable )
+  {
+    mOvershootEffect = OvershootRippleEffect::New();
+    Image overshootImage = Image::New( OVERSHOOT_OVERLAY_RIPPLE_IMAGE_PATH );
+    mOvershootOverlay = ImageActor::New( overshootImage );
+    mOvershootOverlay.SetParentOrigin(ParentOrigin::TOP_LEFT);
+    mOvershootOverlay.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+    mOvershootOverlay.SetDrawMode(DrawMode::OVERLAY);
+    mOvershootOverlay.SetShaderEffect(mOvershootEffect);
+    mOvershootOverlay.SetPixelArea(OVERSHOOT_BOUNCE_IMAGE_1_PIXEL_AREA);
+    self.Add(mOvershootOverlay);
+    Constraint constraint = Constraint::New<float>( Actor::SIZE_WIDTH,
+                                                      ParentSource( mPropertyScrollDirection ),
+                                                      Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
+                                                      ParentSource( Actor::SIZE ),
+                                                      OvershootOverlaySizeConstraint() );
+    mOvershootOverlay.ApplyConstraint(constraint);
+    mOvershootOverlay.SetSize(OVERSHOOT_BOUNCE_IMAGE_1_PIXEL_AREA.width, OVERSHOOT_BOUNCE_IMAGE_1_PIXEL_AREA.height);
+
+    constraint = Constraint::New<Quaternion>( Actor::ROTATION,
+                                              ParentSource( mPropertyScrollDirection ),
+                                              Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
+                                              OvershootOverlayRotationConstraint() );
+    mOvershootOverlay.ApplyConstraint(constraint);
+
+    constraint = Constraint::New<Vector3>( Actor::POSITION,
+                                           ParentSource( Actor::SIZE ),
+                                           ParentSource( mPropertyScrollDirection ),
+                                           Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
+                                           OvershootOverlayPositionConstraint() );
+    mOvershootOverlay.ApplyConstraint(constraint);
+
+    constraint = Constraint::New<bool>( Actor::VISIBLE,
+                                        ParentSource( mPropertyCanScrollVertical ),
+                                        OvershootOverlayVisibilityConstraint() );
+    mOvershootOverlay.ApplyConstraint(constraint);
+
+    int effectOvershootPropertyIndex = mOvershootEffect.GetPropertyIndex(mOvershootEffect.GetOvershootPropertyName());
+    Actor self = Self();
+    constraint = Constraint::New<float>( effectOvershootPropertyIndex,
+                                         Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
+                                         EqualToConstraint() );
+    mOvershootEffect.ApplyConstraint(constraint);
+  }
+  else
+  {
+    if( mOvershootOverlay )
+    {
+      self.Remove(mOvershootOverlay);
+      mOvershootOverlay.Reset();
+    }
+    mOvershootEffect.Reset();
+  }
 }
 
 float ItemView::CalculateScrollOvershoot()
index 5f42a61..d7e1340 100644 (file)
@@ -458,9 +458,9 @@ private:
   void RemoveAnimation(Animation& animation);
 
   /**
-   * Helper to apply constraints to the overshoot overlay actor.
+   * @copydoc Toolkit::Internal::Scrollable::SetOvershootEnabled
    */
-  void ApplyOvershootOverlayConstraints();
+  virtual void SetOvershootEnabled( bool enable );
 
   /**
    * Helper to calculate the scroll overshoot according to the pan gesture displacement.
index d99e5e1..021b908 100644 (file)
@@ -99,7 +99,7 @@ bool Scrollable::IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentTy
 
 void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
 {
-  if(type == Toolkit::Scrollable::OvershootIndicator)
+  if(type == Toolkit::Scrollable::OvershootIndicator && !mOvershootEnabled)
   {
     SetOvershootEnabled(true);
     mOvershootEnabled = true;
@@ -119,7 +119,7 @@ void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType
 
 void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
 {
-  if(type == Toolkit::Scrollable::OvershootIndicator)
+  if(type == Toolkit::Scrollable::OvershootIndicator && mOvershootEnabled)
   {
     SetOvershootEnabled(false);
     mOvershootEnabled = false;