Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture-processor.cpp
index dd908c7..1762821 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 )
@@ -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;
+    }
   }
 }
 
@@ -331,6 +329,21 @@ void PanGestureProcessor::SetPredictionAmount(unsigned int amount)
   mSceneObject->SetPredictionAmount(amount);
 }
 
+void PanGestureProcessor::SetMaximumPredictionAmount(unsigned int amount)
+{
+  mSceneObject->SetMaximumPredictionAmount(amount);
+}
+
+void PanGestureProcessor::SetMinimumPredictionAmount(unsigned int amount)
+{
+  mSceneObject->SetMinimumPredictionAmount(amount);
+}
+
+void PanGestureProcessor::SetPredictionAmountAdjustment(unsigned int amount)
+{
+  mSceneObject->SetPredictionAmountAdjustment(amount);
+}
+
 void PanGestureProcessor::SetSmoothingMode(int mode)
 {
   if( (mode < 0)
@@ -347,6 +360,46 @@ 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 );
+}
+
 void PanGestureProcessor::UpdateDetection()
 {
   DALI_ASSERT_DEBUG(!mGestureDetectors.empty());
@@ -358,16 +411,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;
+      }
     }
   }
 
@@ -416,11 +472,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)
@@ -481,7 +537,7 @@ bool PanGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor
       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 ) );
 
       /////////////////////////////
       //            |            //
@@ -506,12 +562,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;
         }
       }