Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-processor.cpp
index 95f798f..c294c54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -22,6 +22,7 @@
 #include <dali/integration-api/debug.h>
 #include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/actors/layer-impl.h>
+#include <dali/internal/event/common/scene-impl.h>
 #include <dali/internal/event/events/hit-test-algorithm-impl.h>
 #include <dali/internal/event/events/actor-gesture-data.h>
 #include <dali/internal/event/render-tasks/render-task-impl.h>
@@ -40,11 +41,16 @@ namespace
  */
 struct GestureHitTestCheck : public HitTestAlgorithm::HitTestInterface
 {
-  GestureHitTestCheck( Gesture::Type type )
+  GestureHitTestCheck( DevelGesture::Type type )
   : mType( type )
   {
   }
 
+  GestureHitTestCheck( Gesture::Type type )
+  : GestureHitTestCheck( static_cast< DevelGesture::Type >( type ) )
+  {
+  }
+
   virtual bool IsActorHittable( Actor* actor )
   {
     return actor->IsGestureRequred( mType ) && // Does the Application or derived actor type require the gesture?
@@ -62,25 +68,41 @@ struct GestureHitTestCheck : public HitTestAlgorithm::HitTestInterface
     return layer->IsTouchConsumed();
   }
 
-  Gesture::Type mType;
+  DevelGesture::Type mType;
 };
 
 } // unnamed namespace
 
 
-GestureProcessor::GestureProcessor( Gesture::Type type )
-: mType( type ),
-  mCurrentGesturedActor( NULL ),
+GestureProcessor::GestureProcessor( DevelGesture::Type type )
+: mGestureRecognizer(),
+  mNeedsUpdate( false ),
+  mType( type ),
+  mCurrentGesturedActor( nullptr ),
   mGesturedActorDisconnected( false )
 {
 }
 
+GestureProcessor::GestureProcessor( Gesture::Type type )
+: GestureProcessor( static_cast< DevelGesture::Type >( type ) )
+{
+}
+
+
 GestureProcessor::~GestureProcessor()
 {
   ResetActor();
 }
 
-void GestureProcessor::GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors, Functor& functor )
+void GestureProcessor::ProcessTouch( Scene& scene, const Integration::TouchEvent& event )
+{
+  if( mGestureRecognizer )
+  {
+    mGestureRecognizer->SendEvent(scene, event);
+  }
+}
+
+void GestureProcessor::GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors )
 {
   while ( actor )
   {
@@ -94,8 +116,8 @@ void GestureProcessor::GetGesturedActor( Actor*& actor, GestureDetectorContainer
       {
         GestureDetector* current(*iter);
 
-        // Check whether the gesture detector satisfies the current gesture's parameters.
-        if ( functor( current, actor ) )
+        // Check deriving class for whether the current gesture satisfies the gesture detector's parameters.
+        if ( CheckGestureDetector( current, actor ) )
         {
           gestureDetectors.push_back(current);
         }
@@ -113,7 +135,7 @@ void GestureProcessor::GetGesturedActor( Actor*& actor, GestureDetectorContainer
   }
 }
 
-void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults, Functor& functor )
+void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults )
 {
   if ( hitTestResults.actor )
   {
@@ -123,7 +145,7 @@ void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults
     while ( actor )
     {
       GestureDetectorContainer gestureDetectors;
-      GetGesturedActor( actor, gestureDetectors, functor );
+      GetGesturedActor( actor, gestureDetectors );
 
       if ( actor && !gestureDetectors.empty() )
       {
@@ -132,8 +154,8 @@ void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults
 
         if ( actor == hitTestActor )
         {
-          // Our gesture detector's attached actor WAS the hit actor so we can call the emitting functor.
-          functor( actor, gestureDetectors, hitTestResults.actorCoordinates );
+          // Our gesture detector's attached actor WAS the hit actor so we can can emit the signal.
+          EmitGestureSignal( actor, gestureDetectors, hitTestResults.actorCoordinates );
           break; // We have found AND emitted a signal on the gestured actor, break out.
         }
         else
@@ -147,12 +169,12 @@ void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults
               // Ensure tap is within the actor's area
               if ( actor->RaySphereTest( hitTestResults.rayOrigin, hitTestResults.rayDirection ) ) // Quick check
               {
-                Vector4 hitPointLocal;
+                Vector2 hitPointLocal;
                 float distance( 0.0f );
                 if( actor->RayActorTest( hitTestResults.rayOrigin, hitTestResults.rayDirection, hitPointLocal, distance ) )
                 {
-                  // One of the hit actor's parents was the gestured actor so call the emitting functor.
-                  functor( actor, gestureDetectors, Vector2( hitPointLocal.x, hitPointLocal.y ) );
+                  // One of the parents was the gestured actor so we can emit the signal for that actor.
+                  EmitGestureSignal( actor, gestureDetectors, hitPointLocal );
                   break; // We have found AND emitted a signal on the gestured actor, break out.
                 }
               }
@@ -170,13 +192,10 @@ void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults
   }
 }
 
-bool GestureProcessor::HitTest(
-  Stage&                     stage,
-  Vector2                    screenCoordinates,
-  HitTestAlgorithm::Results& hitTestResults)
+bool GestureProcessor::HitTest( Scene& scene, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults )
 {
   GestureHitTestCheck hitCheck( mType );
-  HitTestAlgorithm::HitTest( stage, screenCoordinates, hitTestResults, hitCheck );
+  HitTestAlgorithm::HitTest( scene.GetSize(), scene.GetRenderTaskList(), scene.GetLayerList(), screenCoordinates, hitTestResults, hitCheck );
   return hitTestResults.renderTask && hitTestResults.actor;
 }
 
@@ -197,37 +216,37 @@ void GestureProcessor::ResetActor()
   if ( mCurrentGesturedActor )
   {
     mCurrentGesturedActor->RemoveObserver( *this );
-    mCurrentGesturedActor = NULL;
+    mCurrentGesturedActor = nullptr;
     mGesturedActorDisconnected = false;
   }
 }
 
 Actor* GestureProcessor::GetCurrentGesturedActor()
 {
-  return mGesturedActorDisconnected ? NULL : mCurrentGesturedActor;
+  return mGesturedActorDisconnected ? nullptr : mCurrentGesturedActor;
 }
 
-void GestureProcessor::SceneObjectRemoved(ProxyObject& proxy)
+void GestureProcessor::SceneObjectRemoved(Object& object)
 {
-  if ( mCurrentGesturedActor == &proxy &&
+  if ( mCurrentGesturedActor == &object &&
       !mGesturedActorDisconnected )
   {
     // Inform deriving classes.
     OnGesturedActorStageDisconnection();
 
-    // do not call proxy.RemoveObserver here, proxy is currently iterating through observers... you wouldnt want to upset proxy now would you?
+    // do not call object.RemoveObserver here, object is currently iterating through observers... you wouldnt want to upset object now would you?
     mGesturedActorDisconnected = true;
   }
 }
 
-void GestureProcessor::ProxyDestroyed(ProxyObject& proxy)
+void GestureProcessor::ObjectDestroyed(Object& object)
 {
-  if ( mCurrentGesturedActor == &proxy )
+  if ( mCurrentGesturedActor == &object )
   {
     // Inform deriving classes.
     OnGesturedActorStageDisconnection();
 
-    mCurrentGesturedActor = NULL;
+    mCurrentGesturedActor = nullptr;
   }
 }