Merge "Uses TextArray new type definition." into tizen
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-twist-effect-impl.cpp
index 681afe6..c93d264 100755 (executable)
@@ -1,19 +1,20 @@
 
-//
-// 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.
+ *
+ */
 
 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-twist-effect-impl.h>
@@ -178,8 +179,7 @@ struct ScrollDropoffTwistRotationConstraint
                         const PropertyInput& scrollablePositionProperty,
                         const PropertyInput& scrollOvershootXProperty,
                         const PropertyInput& scrollOvershootYProperty,
-                        const PropertyInput& pageSizeProperty,
-                        const PropertyInput& activateProperty)
+                        const PropertyInput& pageSizeProperty)
   {
     const Vector3& position = actorPositionProperty.GetVector3();
     const Vector3& parentPosition = scrollablePositionProperty.GetVector3();
@@ -191,13 +191,6 @@ struct ScrollDropoffTwistRotationConstraint
       return current;
     }
 
-    const float& activate = activateProperty.GetFloat();
-
-    if(activate < Math::MACHINE_EPSILON_0)
-    {
-      return current;
-    }
-
     // get distance from centre of scrollable container
     Vector2 distance = position.GetVectorXY() - parentPosition.GetVectorXY();
 
@@ -274,19 +267,11 @@ struct ScrollTwistRotationConstraint
    */
   Quaternion operator()(const Quaternion& current,
                         const PropertyInput& scrollOvershootXProperty,
-                        const PropertyInput& scrollOvershootYProperty,
-                        const PropertyInput& activateProperty)
+                        const PropertyInput& scrollOvershootYProperty)
   {
     const Vector2 overshoot(scrollOvershootXProperty.GetFloat(), scrollOvershootYProperty.GetFloat());
 
-    if(fabsf(overshoot.x) < Math::MACHINE_EPSILON_0 && fabsf(overshoot.y) < Math::MACHINE_EPSILON_0)
-    {
-      return current;
-    }
-
-    const float& activate = activateProperty.GetFloat();
-
-    if(activate < Math::MACHINE_EPSILON_0)
+    if( fabsf(overshoot.x) < Math::MACHINE_EPSILON_0 && fabsf(overshoot.y) < Math::MACHINE_EPSILON_0 )
     {
       return current;
     }
@@ -542,7 +527,6 @@ void ScrollViewTwistEffect::Apply(Actor child)
                                                 Source(scrollView, scrollView.GetPropertyIndex( Toolkit::ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME ) ),
                                                 Source(scrollView, scrollView.GetPropertyIndex( Toolkit::ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME ) ),
                                                 Source(scrollView, Actor::SIZE ),
-                                                Source(scrollView, scrollView.GetPropertyIndex( EFFECT_ACTIVATE) ),
                                                 ScrollDropoffTwistRotationConstraint(mMaxSwingAngle, mDropOff, mDropOffDistance, mDropOffFunction) );
     }
     else
@@ -550,7 +534,6 @@ void ScrollViewTwistEffect::Apply(Actor child)
       constraint = Constraint::New<Quaternion>( Actor::ROTATION,
                                                 Source(scrollView, scrollView.GetPropertyIndex( Toolkit::ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME ) ),
                                                 Source(scrollView, scrollView.GetPropertyIndex( Toolkit::ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME ) ),
-                                                Source(scrollView, scrollView.GetPropertyIndex( EFFECT_ACTIVATE) ),
                                                 ScrollTwistRotationConstraint(mMaxSwingAngle) );
     }
     constraint.SetRemoveAction( Constraint::Discard );
@@ -558,9 +541,19 @@ void ScrollViewTwistEffect::Apply(Actor child)
   }
 }
 
+void ScrollViewTwistEffect::SetMaxSwingAngle(const Vector2& maxSwingAngle)
+{
+  mMaxSwingAngle = maxSwingAngle;
+}
+
+Vector2 ScrollViewTwistEffect::GetMaxSwingAngle() const
+{
+  return mMaxSwingAngle;
+}
+
 void ScrollViewTwistEffect::SetSwingDropOff(const Vector2& dropOff, const Vector2& distance, AlphaFunction function)
 {
-  if( mDropOffDistance.LengthSquared() > Math::MACHINE_EPSILON_1 && mDropOff.LengthSquared() > Math::MACHINE_EPSILON_1 )
+  if( distance.LengthSquared() > Math::MACHINE_EPSILON_1 && dropOff.LengthSquared() > Math::MACHINE_EPSILON_1 )
   {
     mFlags |= FlagDropOff;
     mDropOff = dropOff;
@@ -575,6 +568,13 @@ void ScrollViewTwistEffect::SetSwingDropOff(const Vector2& dropOff, const Vector
   mFlags = mFlags & ~FlagDefaultDropOff;
 }
 
+void ScrollViewTwistEffect::GetSwingDropOff( Vector2& dropOff, Vector2& distance, AlphaFunction& function ) const
+{
+  dropOff = mDropOff;
+  distance = mDropOffDistance;
+  function = mDropOffFunction;
+}
+
 void ScrollViewTwistEffect::OnAttach(Toolkit::ScrollView& scrollView)
 {
   // Create effect-time property if not already created.
@@ -583,8 +583,10 @@ void ScrollViewTwistEffect::OnAttach(Toolkit::ScrollView& scrollView)
     mPropertyTime = SafeRegisterProperty( scrollView, EFFECT_TIME, 0.0f );
     mPropertyReference = SafeRegisterProperty( scrollView, EFFECT_REFERENCE, Vector3::ZERO );
     mPropertyDepth = SafeRegisterProperty( scrollView, EFFECT_DEPTH, 0.0f);
-    mPropertyActivate = SafeRegisterProperty(scrollView, EFFECT_ACTIVATE, 1.0f);
+    mPropertyActivate = SafeRegisterProperty(scrollView, EFFECT_ACTIVATE, 0.0f);
   }
+  // currently cant change overshoot snap back duration, use the constant one from ScrollView
+  mActivationTime = Toolkit::ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION;
 
   // Connect to the scroll view signals
   scrollView.ScrollStartedSignal().Connect(this, &ScrollViewTwistEffect::OnScrollStart);
@@ -676,7 +678,7 @@ void ScrollViewTwistEffect::OnScrollComplete( const Vector3& position )
   }
   Actor scrollView = GetScrollView();
   scrollView.SetProperty(mPropertyActivate, 1.0f);
-  mActivateAnimation = Animation::New(DELAY);
+  mActivateAnimation = Animation::New(mActivationTime);
   mActivateAnimation.AnimateTo( Property(scrollView, mPropertyActivate), 0.0f, AlphaFunctions::Linear);
   mActivateAnimation.FinishedSignal().Connect(this, &ScrollViewTwistEffect::OnActivateAnimationFinished);
   mActivateAnimation.Play();