X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscroll-bar%2Fscroll-bar-impl.cpp;h=ff3dbb1f76d5076a6e444f85d898f5a1ab396da0;hp=1ef1e470b3d993d881264a5b45726437ff5a11ef;hb=f3da11c2818c6d17706fbb2417f21b602b3190f5;hpb=f60d2ee843df1c81ea988c4a986e9168c905fcc9 diff --git a/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp b/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp index 1ef1e47..ff3dbb1 100755 --- a/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp +++ b/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp @@ -133,15 +133,15 @@ BaseHandle Create() // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollBar, Toolkit::Control, Create ); -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scroll-direction", STRING, SCROLL_DIRECTION ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-height-policy", STRING, INDICATOR_HEIGHT_POLICY ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-fixed-height", FLOAT, INDICATOR_FIXED_HEIGHT ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-show-duration", FLOAT, INDICATOR_SHOW_DURATION ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-hide-duration", FLOAT, INDICATOR_HIDE_DURATION ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scroll-position-intervals", ARRAY, SCROLL_POSITION_INTERVALS ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollDirection", STRING, SCROLL_DIRECTION ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHeightPolicy", STRING, INDICATOR_HEIGHT_POLICY ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorFixedHeight", FLOAT, INDICATOR_FIXED_HEIGHT ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorShowDuration", FLOAT, INDICATOR_SHOW_DURATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHideDuration", FLOAT, INDICATOR_HIDE_DURATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals", ARRAY, SCROLL_POSITION_INTERVALS ) -DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "pan-finished", PAN_FINISHED_SIGNAL ) -DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "scroll-position-interval-reached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) +DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL ) +DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervalReached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) DALI_TYPE_REGISTRATION_END() @@ -152,8 +152,9 @@ const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"}; ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction) : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), + mIndicatorShowAlpha(1.0f), mDirection(direction), - mScrollableObject(Handle()), + mScrollableObject(WeakHandleBase()), mPropertyScrollPosition(Property::INVALID_INDEX), mPropertyMinScrollPosition(Property::INVALID_INDEX), mPropertyMaxScrollPosition(Property::INVALID_INDEX), @@ -161,10 +162,11 @@ ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction) mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION), mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION), mScrollStart(0.0f), - mIsPanning(false), mCurrentScrollPosition(0.0f), mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable), - mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT) + mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT), + mIsPanning(false), + mIndicatorFirstShow(true) { } @@ -175,7 +177,7 @@ ScrollBar::~ScrollBar() void ScrollBar::OnInitialize() { CreateDefaultIndicatorActor(); - Self().SetDrawMode(DrawMode::OVERLAY); + Self().SetDrawMode(DrawMode::OVERLAY_2D); } void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize ) @@ -186,7 +188,7 @@ void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index property && propertyMaxScrollPosition != Property::INVALID_INDEX && propertyScrollContentSize != Property::INVALID_INDEX ) { - mScrollableObject = handle; + mScrollableObject = WeakHandleBase(handle); mPropertyScrollPosition = propertyScrollPosition; mPropertyMinScrollPosition = propertyMinScrollPosition; mPropertyMaxScrollPosition = propertyMaxScrollPosition; @@ -218,16 +220,14 @@ void ScrollBar::SetScrollIndicator( Actor indicator ) if( indicator ) { mIndicator = indicator; + mIndicatorFirstShow = true; Self().Add(mIndicator); - if( !mPanGestureDetector ) - { - mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.DetectedSignal().Connect(this, &ScrollBar::OnPan); - } + EnableGestureDetection(Gesture::Type(Gesture::Pan)); - mPanGestureDetector.DetachAll(); - mPanGestureDetector.Attach( mIndicator ); + PanGestureDetector detector( GetPanGestureDetector() ); + detector.DetachAll(); + detector.Attach( mIndicator ); unsigned int childCount = mIndicator.GetChildCount(); for ( unsigned int index = 0; index < childCount; index++ ) @@ -235,7 +235,7 @@ void ScrollBar::SetScrollIndicator( Actor indicator ) Actor child = mIndicator.GetChildAt( index ); if ( child ) { - mPanGestureDetector.Attach( child ); + detector.Attach( child ); } } } @@ -252,7 +252,9 @@ Actor ScrollBar::GetScrollIndicator() void ScrollBar::ApplyConstraints() { - if( mScrollableObject ) + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + + if( scrollableHandle ) { if(mIndicatorSizeConstraint) { @@ -268,7 +270,7 @@ void ScrollBar::ApplyConstraints() { mIndicatorSizeConstraint = Constraint::New( mIndicator, Actor::Property::SIZE, IndicatorSizeConstraint() ); mIndicatorSizeConstraint.AddSource( ParentSource( Actor::Property::SIZE ) ); - mIndicatorSizeConstraint.AddSource( Source( mScrollableObject, mPropertyScrollContentSize ) ); + mIndicatorSizeConstraint.AddSource( Source( scrollableHandle, mPropertyScrollContentSize ) ); mIndicatorSizeConstraint.Apply(); } @@ -280,9 +282,9 @@ void ScrollBar::ApplyConstraints() mIndicatorPositionConstraint = Constraint::New( mIndicator, Actor::Property::POSITION, IndicatorPositionConstraint() ); mIndicatorPositionConstraint.AddSource( LocalSource( Actor::Property::SIZE ) ); mIndicatorPositionConstraint.AddSource( ParentSource( Actor::Property::SIZE ) ); - mIndicatorPositionConstraint.AddSource( Source( mScrollableObject, mPropertyScrollPosition ) ); - mIndicatorPositionConstraint.AddSource( Source( mScrollableObject, mPropertyMinScrollPosition ) ); - mIndicatorPositionConstraint.AddSource( Source( mScrollableObject, mPropertyMaxScrollPosition ) ); + mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyScrollPosition ) ); + mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMinScrollPosition ) ); + mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMaxScrollPosition ) ); mIndicatorPositionConstraint.Apply(); } } @@ -291,14 +293,16 @@ void ScrollBar::SetScrollPositionIntervals( const Dali::Vector& positions { mScrollPositionIntervals = positions; - if( mScrollableObject ) + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + + if( scrollableHandle ) { if( mPositionNotification ) { - mScrollableObject.RemovePropertyNotification(mPositionNotification); + scrollableHandle.RemovePropertyNotification(mPositionNotification); } - mPositionNotification = mScrollableObject.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) ); + mPositionNotification = scrollableHandle.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) ); mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionIntervalReached ); } } @@ -311,9 +315,10 @@ Dali::Vector ScrollBar::GetScrollPositionIntervals() const void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source) { // Emit the signal to notify the scroll position crossing - if(mScrollableObject) + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + if(scrollableHandle) { - mScrollPositionIntervalReachedSignal.Emit(mScrollableObject.GetProperty(mPropertyScrollPosition)); + mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty(mPropertyScrollPosition)); } } @@ -326,15 +331,22 @@ void ScrollBar::ShowIndicator() mAnimation.Reset(); } + if( mIndicatorFirstShow ) + { + // Preserve the alpha value from the stylesheet + mIndicatorShowAlpha = Self().GetCurrentColor().a; + mIndicatorFirstShow = false; + } + if(mIndicatorShowDuration > 0.0f) { mAnimation = Animation::New( mIndicatorShowDuration ); - mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN ); + mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), mIndicatorShowAlpha, AlphaFunction::EASE_IN ); mAnimation.Play(); } else { - mIndicator.SetOpacity(1.0f); + mIndicator.SetOpacity(mIndicatorShowAlpha); } } @@ -362,19 +374,22 @@ void ScrollBar::HideIndicator() bool ScrollBar::OnPanGestureProcessTick() { // Update the scroll position property. - if( mScrollableObject ) + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + if( scrollableHandle ) { - mScrollableObject.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition); + scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition); } return true; } -void ScrollBar::OnPan( Actor source, const PanGesture& gesture ) +void ScrollBar::OnPan( const PanGesture& gesture ) { - if(mScrollableObject) + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + + if(scrollableHandle) { - Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(mScrollableObject); + Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle); switch(gesture.state) { @@ -389,7 +404,7 @@ void ScrollBar::OnPan( Actor source, const PanGesture& gesture ) } ShowIndicator(); - mScrollStart = mScrollableObject.GetProperty(mPropertyScrollPosition); + mScrollStart = scrollableHandle.GetProperty(mPropertyScrollPosition); mGestureDisplacement = Vector3::ZERO; mIsPanning = true; @@ -401,8 +416,8 @@ void ScrollBar::OnPan( Actor source, const PanGesture& gesture ) mGestureDisplacement+=delta; Vector3 span = Self().GetCurrentSize() - mIndicator.GetCurrentSize(); - float minScrollPosition = mScrollableObject.GetProperty(mPropertyMinScrollPosition); - float maxScrollPosition = mScrollableObject.GetProperty(mPropertyMaxScrollPosition); + float minScrollPosition = scrollableHandle.GetProperty(mPropertyMinScrollPosition); + float maxScrollPosition = scrollableHandle.GetProperty(mPropertyMaxScrollPosition); float domainSize = maxScrollPosition - minScrollPosition; mCurrentScrollPosition = mScrollStart - mGestureDisplacement.y * domainSize / span.y; @@ -437,7 +452,7 @@ void ScrollBar::OnPan( Actor source, const PanGesture& gesture ) if(itemView) { // Disable automatic refresh in ItemView during fast scrolling - GetImpl(itemView).SetRefreshEnabled(true);//!mIsPanning); + GetImpl(itemView).SetRefreshEnabled(!mIsPanning); } } } @@ -659,11 +674,15 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde { Property::Value value( Property::ARRAY ); Property::Array* array = value.GetArray(); - Dali::Vector positions = scrollBarImpl.GetScrollPositionIntervals(); - size_t positionCount( array->Count() ); - for( size_t i( 0 ); i != positionCount; ++i ) + + if( array ) { - array->PushBack( positions[i] ); + Dali::Vector positions = scrollBarImpl.GetScrollPositionIntervals(); + size_t positionCount( array->Count() ); + for( size_t i( 0 ); i != positionCount; ++i ) + { + array->PushBack( positions[i] ); + } } break; }