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=22272428088cf6492b8262dfe2da3bcde384238e;hp=f10dfb515594d83dca83808da8dd1e1423ee85ed;hb=5e937a6322849b76d49d5b3f41cb5d91c94acd3e;hpb=7e315e8b217ab571598d8db28df867a5da0b99d7 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 f10dfb5..2227242 100755 --- a/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp +++ b/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,11 @@ #include #include #include +#include +#include // INTERNAL INCLUDES +#include #include #include @@ -37,7 +40,7 @@ using namespace Dali; namespace { -const char* DEFAULT_INDICATOR_IMAGE_PATH = DALI_IMAGE_DIR "popup_scroll.9.png"; +const char* DEFAULT_INDICATOR_IMAGE_FILE_NAME = "popup_scroll.9.png"; const float DEFAULT_SLIDER_DEPTH(1.0f); const float DEFAULT_INDICATOR_SHOW_DURATION(0.5f); const float DEFAULT_INDICATOR_HIDE_DURATION(0.5f); @@ -46,6 +49,7 @@ const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f); const float DEFAULT_INDICATOR_MINIMUM_HEIGHT(0.0f); const float DEFAULT_INDICATOR_START_PADDING(0.0f); const float DEFAULT_INDICATOR_END_PADDING(0.0f); +const float DEFAULT_INDICATOR_TRANSIENT_DURATION(1.0f); /** * Indicator size constraint @@ -154,19 +158,24 @@ 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, "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_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorMinimumHeight", FLOAT, INDICATOR_MINIMUM_HEIGHT ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorStartPadding", FLOAT, INDICATOR_START_PADDING ) -DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorEndPadding", FLOAT, INDICATOR_END_PADDING ) - -DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL ) +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_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorMinimumHeight", FLOAT, INDICATOR_MINIMUM_HEIGHT ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorStartPadding", FLOAT, INDICATOR_START_PADDING ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorEndPadding", FLOAT, INDICATOR_END_PADDING ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorTransientDuration", FLOAT, INDICATOR_TRANSIENT_DURATION ) + +DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL ) DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervalReached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) +DALI_ACTION_REGISTRATION( Toolkit, ScrollBar, "ShowIndicator", ACTION_SHOW_INDICATOR ) +DALI_ACTION_REGISTRATION( Toolkit, ScrollBar, "HideIndicator", ACTION_HIDE_INDICATOR ) +DALI_ACTION_REGISTRATION( Toolkit, ScrollBar, "ShowTransientIndicator", ACTION_SHOW_TRANSIENT_INDICATOR ) + DALI_TYPE_REGISTRATION_END() const char* SCROLL_DIRECTION_NAME[] = {"Vertical", "Horizontal"}; @@ -175,7 +184,7 @@ const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"}; } ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction) -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mIndicatorShowAlpha(1.0f), mDirection(direction), mScrollableObject(WeakHandleBase()), @@ -185,7 +194,9 @@ ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction) mPropertyScrollContentSize(Property::INVALID_INDEX), mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION), mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION), + mTransientIndicatorDuration(DEFAULT_INDICATOR_TRANSIENT_DURATION), mScrollStart(0.0f), + mGestureDisplacement( Vector3::ZERO ), mCurrentScrollPosition(0.0f), mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable), mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT), @@ -231,10 +242,12 @@ void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index property void ScrollBar::CreateDefaultIndicatorActor() { - Toolkit::ImageView indicator = Toolkit::ImageView::New( DEFAULT_INDICATOR_IMAGE_PATH ); - indicator.SetParentOrigin( ParentOrigin::TOP_LEFT ); - indicator.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - + const std::string imageDirPath = AssetManager::GetDaliImagePath(); + Toolkit::ImageView indicator = Toolkit::ImageView::New( imageDirPath + DEFAULT_INDICATOR_IMAGE_FILE_NAME ); + indicator.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + indicator.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + indicator.SetStyleName( "ScrollBarIndicator" ); + indicator.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); SetScrollIndicator(indicator); } @@ -243,11 +256,17 @@ void ScrollBar::SetScrollIndicator( Actor indicator ) // Don't allow empty handle if( indicator ) { + // Remove current Indicator + if( mIndicator ) + { + Self().Remove( mIndicator ); + } mIndicator = indicator; + mIndicatorFirstShow = true; - Self().Add(mIndicator); + Self().Add( mIndicator ); - EnableGestureDetection(Gesture::Type(Gesture::Pan)); + EnableGestureDetection( Gesture::Type( Gesture::Pan ) ); PanGestureDetector detector( GetPanGestureDetector() ); detector.DetachAll(); @@ -288,7 +307,7 @@ void ScrollBar::ApplyConstraints() // Set indicator height according to the indicator's height policy if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) { - mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight); + mIndicator.SetSize(Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, mIndicatorFixedHeight); } else { @@ -344,7 +363,7 @@ void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source) Handle scrollableHandle = mScrollableObject.GetBaseHandle(); if(scrollableHandle) { - mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty(mPropertyScrollPosition)); + mScrollPositionIntervalReachedSignal.Emit( scrollableHandle.GetCurrentProperty< float >( mPropertyScrollPosition ) ); } } @@ -360,7 +379,7 @@ void ScrollBar::ShowIndicator() if( mIndicatorFirstShow ) { // Preserve the alpha value from the stylesheet - mIndicatorShowAlpha = Self().GetCurrentColor().a; + mIndicatorShowAlpha = Self().GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a; mIndicatorFirstShow = false; } @@ -372,7 +391,7 @@ void ScrollBar::ShowIndicator() } else { - mIndicator.SetOpacity(mIndicatorShowAlpha); + mIndicator.SetProperty( DevelActor::Property::OPACITY,mIndicatorShowAlpha); } } @@ -393,10 +412,34 @@ void ScrollBar::HideIndicator() } else { - mIndicator.SetOpacity(0.0f); + mIndicator.SetProperty( DevelActor::Property::OPACITY,0.0f); } } +void ScrollBar::ShowTransientIndicator() +{ + // Cancel any animation + if(mAnimation) + { + mAnimation.Clear(); + mAnimation.Reset(); + } + + mAnimation = Animation::New( mIndicatorShowDuration + mTransientIndicatorDuration + mIndicatorHideDuration ); + if(mIndicatorShowDuration > 0.0f) + { + mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), + mIndicatorShowAlpha, AlphaFunction::EASE_IN, TimePeriod(0, mIndicatorShowDuration) ); + } + else + { + mIndicator.SetProperty( DevelActor::Property::OPACITY,mIndicatorShowAlpha); + } + mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), + 0.0f, AlphaFunction::EASE_IN, TimePeriod((mIndicatorShowDuration + mTransientIndicatorDuration), mIndicatorHideDuration) ); + mAnimation.Play(); +} + bool ScrollBar::OnPanGestureProcessTick() { // Update the scroll position property. @@ -430,7 +473,7 @@ void ScrollBar::OnPan( const PanGesture& gesture ) } ShowIndicator(); - mScrollStart = scrollableHandle.GetProperty(mPropertyScrollPosition); + mScrollStart = scrollableHandle.GetCurrentProperty< float >( mPropertyScrollPosition ); mGestureDisplacement = Vector3::ZERO; mIsPanning = true; @@ -441,12 +484,12 @@ void ScrollBar::OnPan( const PanGesture& gesture ) mGestureDisplacement.x += gesture.displacement.x; mGestureDisplacement.y += gesture.displacement.y; - float minScrollPosition = scrollableHandle.GetProperty( mPropertyMinScrollPosition ); - float maxScrollPosition = scrollableHandle.GetProperty( mPropertyMaxScrollPosition ); + float minScrollPosition = scrollableHandle.GetCurrentProperty( mPropertyMinScrollPosition ); + float maxScrollPosition = scrollableHandle.GetCurrentProperty( mPropertyMaxScrollPosition ); // The domain size is the internal range float domainSize = maxScrollPosition - minScrollPosition; - float logicalSize = Self().GetCurrentSize().y - ( mIndicator.GetCurrentSize().y + mIndicatorStartPadding + mIndicatorEndPadding ); + float logicalSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).y - ( mIndicator.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).y + mIndicatorStartPadding + mIndicatorEndPadding ); mCurrentScrollPosition = mScrollStart - ( ( mGestureDisplacement.y * domainSize ) / logicalSize ); mCurrentScrollPosition = -std::min( maxScrollPosition, std::max( -mCurrentScrollPosition, minScrollPosition ) ); @@ -491,6 +534,8 @@ void ScrollBar::OnSizeSet( const Vector3& size ) { mIndicator.SetSize(size.width, mIndicatorFixedHeight); } + + Control::OnSizeSet( size ); } void ScrollBar::SetScrollDirection( Toolkit::ScrollBar::Direction direction ) @@ -523,7 +568,7 @@ void ScrollBar::SetIndicatorFixedHeight( float height ) if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) { - mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight); + mIndicator.SetSize(Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, mIndicatorFixedHeight); } } @@ -679,6 +724,11 @@ void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Pr scrollBarImpl.ApplyConstraints(); break; } + case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION: + { + scrollBarImpl.mTransientIndicatorDuration = value.Get(); + break; + } } } } @@ -721,17 +771,20 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde } case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS: { - Property::Value value( Property::ARRAY ); - Property::Array* array = value.GetArray(); + Property::Value tempValue( Property::ARRAY ); + Property::Array* array = tempValue.GetArray(); if( array ) { Dali::Vector positions = scrollBarImpl.GetScrollPositionIntervals(); - size_t positionCount( array->Count() ); + size_t positionCount( positions.Count() ); + for( size_t i( 0 ); i != positionCount; ++i ) { array->PushBack( positions[i] ); } + + value = tempValue; } break; } @@ -750,11 +803,48 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde value = scrollBarImpl.mIndicatorEndPadding; break; } + case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION: + { + value = scrollBarImpl.mTransientIndicatorDuration; + break; + } } } return value; } +bool ScrollBar::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ) +{ + bool ret = false; + + Dali::BaseHandle handle( object ); + + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( handle ); + + DALI_ASSERT_DEBUG( scrollBar ); + + if( scrollBar ) + { + if( 0 == strcmp( actionName.c_str(), ACTION_SHOW_INDICATOR ) ) + { + GetImpl( scrollBar ).ShowIndicator(); + ret = true; + } + else if( 0 == strcmp( actionName.c_str(), ACTION_HIDE_INDICATOR ) ) + { + GetImpl( scrollBar ).HideIndicator(); + ret = true; + } + else if( 0 == strcmp( actionName.c_str(), ACTION_SHOW_TRANSIENT_INDICATOR ) ) + { + GetImpl( scrollBar ).ShowTransientIndicator(); + ret = true; + } + } + + return ret; +} + Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction) { // Create the implementation, temporarily owned by this handle on stack