Refactor SceneGraphProperty handling code in event side to make RegisterProperty...
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture-processor.cpp
index 441fb7d..d95fe0f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -101,7 +101,7 @@ struct IsNotAttachedAndOutsideTouchesRangeFunctor
 
 } // unnamed namespace
 
-PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager )
+PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager, SceneGraph::UpdateManager& updateManager )
 : GestureProcessor( Gesture::Pan ),
   mStage( stage ),
   mGestureManager( gestureManager ),
@@ -114,17 +114,13 @@ PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureMana
   mCurrentPanEvent( NULL ),
   mSceneObject( SceneGraph::PanGesture::New() ) // Create scene object to store pan information.
 {
-  // Pass ownership to scene-graph
-  AddGestureMessage( mStage.GetUpdateManager(), mSceneObject );
+  // Pass ownership to scene-graph; scene object lives for the lifecycle of UpdateManager
+  updateManager.SetPanGestureProcessor( mSceneObject );
 }
 
 PanGestureProcessor::~PanGestureProcessor()
 {
-  if( Stage::IsInstalled() && ( mSceneObject != NULL ) )
-  {
-    RemoveGestureMessage( mStage.GetUpdateManager(), mSceneObject );
-    mSceneObject = NULL; // mSceneObject is about to be destroyed
-  }
+  mSceneObject = NULL; // mSceneObject is owned and destroyed by update manager (there is only one of these for now)
 }
 
 void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent )
@@ -199,7 +195,7 @@ void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent
 
           if ( !outsideTouchesRangeEmitters.empty() || !mCurrentPanEmitters.empty() )
           {
-            currentGesturedActor->ScreenToLocal( GetImplementation( mCurrentRenderTask ), actorCoords.x, actorCoords.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
+            currentGesturedActor->ScreenToLocal( *mCurrentRenderTask.Get(), actorCoords.x, actorCoords.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
 
             // EmitPanSignal checks whether we have a valid actor and whether the container we are passing in has emitters before it emits the pan.
             EmitPanSignal( currentGesturedActor, outsideTouchesRangeEmitters, panEvent, actorCoords, Gesture::Finished, mCurrentRenderTask);
@@ -229,8 +225,10 @@ void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent
     }
 
     case Gesture::Clear:
-      DALI_ASSERT_ALWAYS( false && "Incorrect state received from Integration layer: Clear\n" );
+    {
+      DALI_ABORT( "Incorrect state received from Integration layer: Clear\n" );
       break;
+    }
   }
 }
 
@@ -240,9 +238,6 @@ void PanGestureProcessor::AddGestureDetector( PanGestureDetector* gestureDetecto
 
   mGestureDetectors.push_back(gestureDetector);
 
-  // Set the pan scene object on the gesture detector
-  gestureDetector->SetSceneObject( mSceneObject );
-
   if (firstRegistration)
   {
     mMinTouchesRequired = gestureDetector->GetMinimumTouchesRequired();
@@ -362,6 +357,51 @@ void PanGestureProcessor::SetSmoothingAmount(float amount)
   mSceneObject->SetSmoothingAmount(amount);
 }
 
+void PanGestureProcessor::SetUseActualTimes( bool value )
+{
+  mSceneObject->SetUseActualTimes( value );
+}
+
+void PanGestureProcessor::SetInterpolationTimeRange( int value )
+{
+  mSceneObject->SetInterpolationTimeRange( value );
+}
+
+void PanGestureProcessor::SetScalarOnlyPredictionEnabled( bool value )
+{
+  mSceneObject->SetScalarOnlyPredictionEnabled( value );
+}
+
+void PanGestureProcessor::SetTwoPointPredictionEnabled( bool value )
+{
+  mSceneObject->SetTwoPointPredictionEnabled( value );
+}
+
+void PanGestureProcessor::SetTwoPointInterpolatePastTime( int value )
+{
+  mSceneObject->SetTwoPointInterpolatePastTime( value );
+}
+
+void PanGestureProcessor::SetTwoPointVelocityBias( float value )
+{
+  mSceneObject->SetTwoPointVelocityBias( value );
+}
+
+void PanGestureProcessor::SetTwoPointAccelerationBias( float value )
+{
+  mSceneObject->SetTwoPointAccelerationBias( value );
+}
+
+void PanGestureProcessor::SetMultitapSmoothingRange( int value )
+{
+  mSceneObject->SetMultitapSmoothingRange( value );
+}
+
+const SceneGraph::PanGesture& PanGestureProcessor::GetSceneObject() const
+{
+  return *mSceneObject;
+}
+
 void PanGestureProcessor::UpdateDetection()
 {
   DALI_ASSERT_DEBUG(!mGestureDetectors.empty());
@@ -373,16 +413,19 @@ void PanGestureProcessor::UpdateDetection()
   {
     PanGestureDetector* detector(*iter);
 
-    unsigned int minimum = detector->GetMinimumTouchesRequired();
-    if (minimum < minimumRequired)
+    if( detector )
     {
-      minimumRequired = minimum;
-    }
+      unsigned int minimum = detector->GetMinimumTouchesRequired();
+      if (minimum < minimumRequired)
+      {
+        minimumRequired = minimum;
+      }
 
-    unsigned int maximum = detector->GetMaximumTouchesRequired();
-    if (maximum > maximumRequired)
-    {
-      maximumRequired = maximum;
+      unsigned int maximum = detector->GetMaximumTouchesRequired();
+      if (maximum > maximumRequired)
+      {
+        maximumRequired = maximum;
+      }
     }
   }
 
@@ -403,7 +446,7 @@ void PanGestureProcessor::EmitPanSignal( Actor* actor,
                                          const Integration::PanGestureEvent& panEvent,
                                          Vector2 localCurrent,
                                          Gesture::State state,
-                                         Dali::RenderTask renderTask )
+                                         RenderTaskPtr renderTask )
 {
   if ( actor && !gestureDetectors.empty() )
   {
@@ -414,7 +457,7 @@ void PanGestureProcessor::EmitPanSignal( Actor* actor,
     pan.screenPosition = panEvent.currentPosition;
     pan.position = localCurrent;
 
-    RenderTask& renderTaskImpl( GetImplementation( renderTask ) );
+    RenderTask& renderTaskImpl( *renderTask.Get() );
 
     Vector2 localPrevious;
     actor->ScreenToLocal( renderTaskImpl, localPrevious.x, localPrevious.y, panEvent.previousPosition.x, panEvent.previousPosition.y );
@@ -431,11 +474,11 @@ void PanGestureProcessor::EmitPanSignal( Actor* actor,
     // Avoid dividing by 0
     if ( panEvent.timeDelta > 0 )
     {
-      pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
-      pan.velocity.y = pan.displacement.y / panEvent.timeDelta;
+      pan.velocity.x = pan.displacement.x / static_cast<float>( panEvent.timeDelta );
+      pan.velocity.y = pan.displacement.y / static_cast<float>( panEvent.timeDelta );
 
-      pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
-      pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
+      pan.screenVelocity.x = pan.screenDisplacement.x / static_cast<float>( panEvent.timeDelta );
+      pan.screenVelocity.y = pan.screenDisplacement.y / static_cast<float>( panEvent.timeDelta );
     }
 
     // When the gesture ends, we may incorrectly get a ZERO velocity (as we have lifted our finger without any movement)
@@ -489,14 +532,14 @@ bool PanGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor
     {
       // It does, calculate the angle of the pan in local actor coordinates and ensures it fits
       // the detector's criteria.
-      RenderTask& renderTaskImpl( GetImplementation( mCurrentRenderTask ) );
+      RenderTask& renderTaskImpl = *mCurrentRenderTask.Get();
 
       Vector2 startPosition, currentPosition;
       actor->ScreenToLocal( renderTaskImpl, startPosition.x,   startPosition.y,   mPossiblePanPosition.x,              mPossiblePanPosition.y );
       actor->ScreenToLocal( renderTaskImpl, currentPosition.x, currentPosition.y, mCurrentPanEvent->currentPosition.x, mCurrentPanEvent->currentPosition.y );
       Vector2 displacement( currentPosition - startPosition );
 
-      Radian angle( atan( displacement.y / displacement.x ) );
+      Radian angle( atanf( displacement.y / displacement.x ) );
 
       /////////////////////////////
       //            |            //
@@ -521,12 +564,12 @@ bool PanGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor
         if ( displacement.y >= 0.0f )
         {
           // Quadrant 2
-          angle += Math::PI;
+          angle.radian += Math::PI;
         }
         else
         {
           // Quadrant 3
-          angle -= Math::PI;
+          angle.radian -= Math::PI;
         }
       }
 
@@ -551,7 +594,7 @@ void PanGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetector
   mCurrentPanEmitters.clear();
   ResetActor();
 
-  actor->ScreenToLocal( GetImplementation(mCurrentRenderTask), actorCoordinates.x, actorCoordinates.y, mCurrentPanEvent->currentPosition.x, mCurrentPanEvent->currentPosition.y );
+  actor->ScreenToLocal( *mCurrentRenderTask.Get(), actorCoordinates.x, actorCoordinates.y, mCurrentPanEvent->currentPosition.x, mCurrentPanEvent->currentPosition.y );
 
   EmitPanSignal( actor, gestureDetectors, *mCurrentPanEvent, actorCoordinates, mCurrentPanEvent->state, mCurrentRenderTask );