From 8c897165d6e4c395125aeef6a1ff772672b5d821 Mon Sep 17 00:00:00 2001 From: Julien Heanley Date: Tue, 22 Apr 2014 15:35:22 +0100 Subject: [PATCH] (ItemView) Implemented SetOvershootEnabled which is used by Scrollable::Enable/DisableScrollComponent Change-Id: I2c5fa803add707508884b022ae06956fc35c441a --- .../scrollable/item-view/item-view-impl.cpp | 98 ++++++++++++---------- .../controls/scrollable/item-view/item-view-impl.h | 4 +- .../controls/scrollable/scrollable-impl.cpp | 4 +- 3 files changed, 59 insertions(+), 47 deletions(-) diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp index 001291f..8bebcd5 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp @@ -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(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( 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( Actor::ROTATION, - ParentSource( mPropertyScrollDirection ), - Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), - OvershootOverlayRotationConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::POSITION, - ParentSource( Actor::SIZE ), - ParentSource( mPropertyScrollDirection ), - Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), - OvershootOverlayPositionConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::VISIBLE, - ParentSource( mPropertyCanScrollVertical ), - OvershootOverlayVisibilityConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); - - int effectOvershootPropertyIndex = mOvershootEffect.GetPropertyIndex(mOvershootEffect.GetOvershootPropertyName()); Actor self = Self(); - constraint = Constraint::New( 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( 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( Actor::ROTATION, + ParentSource( mPropertyScrollDirection ), + Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), + OvershootOverlayRotationConstraint() ); + mOvershootOverlay.ApplyConstraint(constraint); + + constraint = Constraint::New( Actor::POSITION, + ParentSource( Actor::SIZE ), + ParentSource( mPropertyScrollDirection ), + Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), + OvershootOverlayPositionConstraint() ); + mOvershootOverlay.ApplyConstraint(constraint); + + constraint = Constraint::New( Actor::VISIBLE, + ParentSource( mPropertyCanScrollVertical ), + OvershootOverlayVisibilityConstraint() ); + mOvershootOverlay.ApplyConstraint(constraint); + + int effectOvershootPropertyIndex = mOvershootEffect.GetPropertyIndex(mOvershootEffect.GetOvershootPropertyName()); + Actor self = Self(); + constraint = Constraint::New( effectOvershootPropertyIndex, + Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), + EqualToConstraint() ); + mOvershootEffect.ApplyConstraint(constraint); + } + else + { + if( mOvershootOverlay ) + { + self.Remove(mOvershootOverlay); + mOvershootOverlay.Reset(); + } + mOvershootEffect.Reset(); + } } float ItemView::CalculateScrollOvershoot() diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h index 5f42a61..d7e1340 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h @@ -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. diff --git a/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp index d99e5e1..021b908 100644 --- a/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp @@ -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; -- 2.7.4