X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscrollable%2Fscrollable-impl.cpp;h=5f7cf720c164917f6f5383146133eb6fea6881c4;hp=d99e5e1da3efa908f96bdb6fd2147fa1675f3baa;hb=4b347781c8761d2909b235ded2e98d272fa9ac16;hpb=77aecaf3903cb08ea1eea8da87a19eaa02a2a54b diff --git a/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp b/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp index d99e5e1..5f7cf72 100644 --- a/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp +++ b/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp @@ -1,18 +1,24 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include // for strcmp +#include +#include // INTERNAL INCLUDES #include @@ -20,11 +26,6 @@ using namespace Dali; -namespace -{ - -} // unnamed namespace - namespace Dali { @@ -43,28 +44,40 @@ BaseHandle Create() return BaseHandle(); } -TypeRegistration mType( typeid(Toolkit::Scrollable), typeid(Toolkit::Control), Create ); +// Setup properties, signals and actions using the type-registry. +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Scrollable, Toolkit::Control, Create ); -SignalConnectorType s1(mType, Toolkit::Scrollable::SIGNAL_SCROLL_STARTED, &Scrollable::DoConnectSignal); -SignalConnectorType s2(mType, Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED, &Scrollable::DoConnectSignal); -SignalConnectorType s3(mType, Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED, &Scrollable::DoConnectSignal); -SignalConnectorType s4(mType, Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED, &Scrollable::DoConnectSignal); +DALI_PROPERTY_REGISTRATION( Scrollable, "overshoot-effect-color", VECTOR4, OVERSHOOT_EFFECT_COLOR ) +DALI_PROPERTY_REGISTRATION( Scrollable, "overshoot-animation-speed", FLOAT, OVERSHOOT_ANIMATION_SPEED ) -} +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Scrollable, "scroll-relative-position", VECTOR3, SCROLL_RELATIVE_POSITION) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Scrollable, "scroll-position-min", VECTOR3, SCROLL_POSITION_MIN) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Scrollable, "scroll-position-max", VECTOR3, SCROLL_POSITION_MAX) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Scrollable, "scroll-direction", VECTOR3, SCROLL_DIRECTION) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Scrollable, "can-scroll-vertical", BOOLEAN, CAN_SCROLL_VERTICAL) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Scrollable, "can-scroll-horizontal", BOOLEAN, CAN_SCROLL_HORIZONTAL) + +DALI_SIGNAL_REGISTRATION( Scrollable, "scroll-started", SIGNAL_SCROLL_STARTED ) +DALI_SIGNAL_REGISTRATION( Scrollable, "scroll-completed", SIGNAL_SCROLL_COMPLETED ) +DALI_SIGNAL_REGISTRATION( Scrollable, "scroll-updated", SIGNAL_SCROLL_UPDATED ) -const std::string Scrollable::SCROLLABLE_CAN_SCROLL_VERTICAL( "scrollable-can-scroll-vertical" ); -const std::string Scrollable::SCROLLABLE_CAN_SCROLL_HORIZONTAL( "scrollable-can-scroll-horizontal" ); +DALI_TYPE_REGISTRATION_END() + +const Vector4 DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.25f); +const float DEFAULT_OVERSHOOT_ANIMATION_SPEED(120.0f); // 120 pixels per second + +} /////////////////////////////////////////////////////////////////////////////////////////////////// // Scrollable /////////////////////////////////////////////////////////////////////////////////////////////////// +// Scrollable controls are not layout containers so they dont need size negotiation.. +// we dont want size negotiation while scrolling if we can avoid it Scrollable::Scrollable() -: ControlImpl(true/*requires touch*/), - mPropertyRelativePosition(Property::INVALID_INDEX), - mPropertyPositionMin(Property::INVALID_INDEX), - mPropertyPositionMax(Property::INVALID_INDEX), - mPropertyScrollDirection(Property::INVALID_INDEX), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS | NO_SIZE_NEGOTIATION ) ), + mOvershootEffectColor( DEFAULT_OVERSHOOT_COLOUR ), + mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ), mOvershootEnabled(false) { } @@ -75,19 +88,6 @@ Scrollable::~Scrollable() mComponents.clear(); } -void Scrollable::RegisterCommonProperties() -{ - Actor self = Self(); - - // Register properties. - mPropertyRelativePosition = self.RegisterProperty(Toolkit::Scrollable::SCROLL_RELATIVE_POSITION_PROPERTY_NAME, Vector3::ZERO); - mPropertyPositionMin = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MIN_PROPERTY_NAME, Vector3::ZERO); - mPropertyPositionMax = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MAX_PROPERTY_NAME, Vector3::ZERO); - mPropertyScrollDirection = self.RegisterProperty(Toolkit::Scrollable::SCROLL_DIRECTION_PROPERTY_NAME, Vector3::ZERO); - mPropertyCanScrollVertical = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_VERTICAL, true); - mPropertyCanScrollHorizontal = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_HORIZONTAL, true); -} - bool Scrollable::IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentType type) const { if(type == Toolkit::Scrollable::OvershootIndicator) @@ -101,8 +101,11 @@ void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType { if(type == Toolkit::Scrollable::OvershootIndicator) { - SetOvershootEnabled(true); - mOvershootEnabled = true; + if( !mOvershootEnabled ) + { + SetOvershootEnabled(true); + mOvershootEnabled = true; + } return; } if( mComponents.find(type) == mComponents.end() ) @@ -121,8 +124,11 @@ void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType { if(type == Toolkit::Scrollable::OvershootIndicator) { - SetOvershootEnabled(false); - mOvershootEnabled = false; + if( mOvershootEnabled ) + { + SetOvershootEnabled(false); + mOvershootEnabled = false; + } return; } ComponentIter pair = mComponents.find( type ); @@ -139,24 +145,34 @@ void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType } } -Toolkit::Scrollable::ScrollStartedSignalV2& Scrollable::ScrollStartedSignal() +Vector4 Scrollable::GetOvershootEffectColor() const +{ + return mOvershootEffectColor; +}; + +void Scrollable::SetOvershootAnimationSpeed( float pixelsPerSecond ) { - return mScrollStartedSignalV2; + mOvershootAnimationSpeed = pixelsPerSecond; } -Toolkit::Scrollable::ScrollUpdatedSignalV2& Scrollable::ScrollUpdatedSignal() +float Scrollable::GetOvershootAnimationSpeed() const +{ + return mOvershootAnimationSpeed; +}; + +Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal() { - return mScrollUpdatedSignalV2; + return mScrollStartedSignal; } -Toolkit::Scrollable::ScrollCompletedSignalV2& Scrollable::ScrollCompletedSignal() +Toolkit::Scrollable::ScrollUpdatedSignalType& Scrollable::ScrollUpdatedSignal() { - return mScrollCompletedSignalV2; + return mScrollUpdatedSignal; } -Toolkit::Scrollable::ScrollClampedSignalV2& Scrollable::ScrollClampedSignal() +Toolkit::Scrollable::ScrollCompletedSignalType& Scrollable::ScrollCompletedSignal() { - return mScrollClampedSignalV2; + return mScrollCompletedSignal; } bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) @@ -166,22 +182,18 @@ bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface bool connected( true ); Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle ); - if( Toolkit::Scrollable::SIGNAL_SCROLL_STARTED == signalName ) + if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_STARTED ) ) { scrollable.ScrollStartedSignal().Connect( tracker, functor ); } - else if( Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED == signalName ) + else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_UPDATED ) ) { scrollable.ScrollUpdatedSignal().Connect( tracker, functor ); } - else if( Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED == signalName ) + else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_COMPLETED ) ) { scrollable.ScrollCompletedSignal().Connect( tracker, functor ); } - else if( Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED == signalName ) - { - scrollable.ScrollClampedSignal().Connect( tracker, functor ); - } else { // signalName does not match any signal @@ -191,6 +203,56 @@ bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface return connected; } +void Scrollable::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) ); + + if( scrollable ) + { + Scrollable& scrollableImpl( GetImpl( scrollable ) ); + switch( index ) + { + case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR: + { + scrollableImpl.SetOvershootEffectColor( value.Get() ); + break; + } + case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED: + { + scrollableImpl.SetOvershootAnimationSpeed( value.Get() ); + break; + } + } + } +} + +Property::Value Scrollable::GetProperty( BaseObject* object, Property::Index index ) +{ + Property::Value value; + + Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) ); + + if( scrollable ) + { + Scrollable& scrollableImpl( GetImpl( scrollable ) ); + switch( index ) + { + case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR: + { + value = scrollableImpl.GetOvershootEffectColor(); + break; + } + case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED: + { + value = scrollableImpl.GetOvershootAnimationSpeed(); + break; + } + } + } + + return value; +} + Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type) { Toolkit::ScrollComponent instance; @@ -207,9 +269,10 @@ Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scr instance = static_cast(Toolkit::ScrollBarInternal::New(scrollable, false)); break; } - default: + case Toolkit::Scrollable::OvershootIndicator: { - DALI_ASSERT_ALWAYS(true && "Unrecognized component type"); + DALI_ASSERT_ALWAYS(!"Unrecognized component type"); + break; } }