X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fcontrols%2Fscrollable%2Fscrollable-impl.cpp;h=3db2f3e852d8028f9bd14e0be4a6305e06eb89fc;hb=56d412791a44c2a79135d2293c13fddb135c9d54;hp=1421d3ea2849af31df0dcc5d0ac5c02b4325cc4a;hpb=e2eda444afbe82e9591fe198eef339227f90a616;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp b/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp index 1421d3e..3db2f3e 100644 --- a/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp +++ b/dali-toolkit/internal/controls/scrollable/scrollable-impl.cpp @@ -1,30 +1,30 @@ -// -// 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 +#include // INTERNAL INCLUDES #include -#include +#include using namespace Dali; -namespace -{ - -} // unnamed namespace - namespace Dali { @@ -43,28 +43,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) -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_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 ) + +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 +87,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,16 +100,19 @@ 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() ) { // Create ScrollComponent Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Self()); - Toolkit::ScrollComponent scrollComponent = ScrollComponent::New(scrollable, type); - Toolkit::Internal::ScrollComponent& component = static_cast(scrollComponent.GetImplementation()); + Toolkit::ScrollComponent scrollComponent = NewScrollComponent(scrollable, type); + Toolkit::ScrollComponentImpl& component = static_cast(scrollComponent.GetImplementation()); ScrollComponentPtr componentPtr(&component); mComponents[type] = componentPtr; @@ -121,8 +123,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 +144,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 mScrollUpdatedSignalV2; + return mOvershootAnimationSpeed; +}; + +Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal() +{ + 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 +181,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 +202,82 @@ 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; + + switch(type) + { + case Toolkit::Scrollable::VerticalScrollBar: + { + instance = static_cast(Toolkit::ScrollBarInternal::New(scrollable, true)); + break; + } + case Toolkit::Scrollable::HorizontalScrollBar: + { + instance = static_cast(Toolkit::ScrollBarInternal::New(scrollable, false)); + break; + } + case Toolkit::Scrollable::OvershootIndicator: + { + DALI_ASSERT_ALWAYS(!"Unrecognized component type"); + break; + } + } + + return instance; +} + } // namespace Internal } // namespace Toolkit