(Gestures) Use the actor-gesture-data containers and use raw Actor pointers. 71/24071/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 6 Jun 2014 16:45:19 +0000 (17:45 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 8 Jul 2014 13:14:50 +0000 (14:14 +0100)
Use the containers provided by actor-gesture-data rather than checking if the actor
is available in attached detectors (should be faster).
Using raw Internal::Actor pointers instead of handles.
Removing unnecessary templates.

Next step is to remove gesture-processor functors and use deriving methods instead.

Change-Id: I130cc8cbd0dae293713b74156fcbf3c1c3eaa758
Signed-off-by: Adeel Kazmi <adeel.kazmi@samsung.com>
dali/internal/event/events/actor-gesture-data.cpp
dali/internal/event/events/actor-gesture-data.h
dali/internal/event/events/gesture-processor.cpp
dali/internal/event/events/gesture-processor.h
dali/internal/event/events/long-press-gesture-processor.cpp
dali/internal/event/events/long-press-gesture-processor.h
dali/internal/event/events/pan-gesture-processor.cpp
dali/internal/event/events/pan-gesture-processor.h
dali/internal/event/events/pinch-gesture-processor.cpp
dali/internal/event/events/pinch-gesture-processor.h
dali/internal/event/events/tap-gesture-processor.cpp

index 1b41d0a..c331c56 100644 (file)
@@ -24,48 +24,6 @@ namespace Dali
 namespace Internal
 {
 
-namespace
-{
-
-/**
- * Template to add a detector to the appropriate container. Dynamically allocates the container only if it is used.
- */
-template< typename DetectorType, typename ContainerType >
-inline void AddDetector( ContainerType*& containerPtr, GestureDetector* detector, Gesture::Type& gesturesRequired )
-{
-  if ( NULL == containerPtr )
-  {
-    containerPtr = new ContainerType;
-  }
-
-  containerPtr->push_back( static_cast< DetectorType* >( detector ) );
-  gesturesRequired = Gesture::Type( gesturesRequired | detector->GetType() );
-}
-
-/**
- * Template to remove a detector from the appropriate container. Deletes the container if it is no longer required.
- */
-template< typename ContainerType >
-inline void RemoveDetector( ContainerType*& containerPtr, GestureDetector* detector, Gesture::Type& gesturesRequired )
-{
-  if ( NULL != containerPtr )
-  {
-    ContainerType& container( *containerPtr );
-    typename ContainerType::iterator match( std::remove( container.begin(), container.end(), detector ) );
-    DALI_ASSERT_DEBUG( match != container.end() && "Actor does not have the detector" );
-    container.erase( match, container.end() );
-
-    if ( container.empty() )
-    {
-      gesturesRequired = Gesture::Type( gesturesRequired & ~detector->GetType() );
-      delete containerPtr;
-      containerPtr = NULL;
-    }
-  }
-}
-
-} // unnamed namespace
-
 ActorGestureData::ActorGestureData()
 : gesturesRequired( Gesture::Type( 0 ) ),
   panDetectors( NULL ),
@@ -86,62 +44,70 @@ ActorGestureData::~ActorGestureData()
 void ActorGestureData::AddGestureDetector( GestureDetector& detector )
 {
   const Gesture::Type type( detector.GetType() );
-  switch ( type )
+
+  GestureDetectorContainer*& containerPtr( GetContainerPtr( type ) );
+  if ( NULL == containerPtr )
   {
-    case Gesture::Pan:
-    {
-      AddDetector< PanGestureDetector, PanGestureDetectorContainer >( panDetectors, &detector, gesturesRequired );
-      break;
-    }
+    containerPtr = new GestureDetectorContainer;
+  }
+  containerPtr->push_back( &detector );
 
-    case Gesture::Pinch:
-    {
-      AddDetector< PinchGestureDetector, PinchGestureDetectorContainer >( pinchDetectors, &detector, gesturesRequired );
-      break;
-    }
+  gesturesRequired = Gesture::Type( gesturesRequired | type );
+}
 
-    case Gesture::LongPress:
-    {
-      AddDetector< LongPressGestureDetector, LongPressGestureDetectorContainer >( longPressDetectors, &detector, gesturesRequired );
-      break;
-    }
+void ActorGestureData::RemoveGestureDetector( GestureDetector& detector )
+{
+  const Gesture::Type type( detector.GetType() );
 
-    case Gesture::Tap:
-    {
-      AddDetector< TapGestureDetector, TapGestureDetectorContainer >( tapDetectors, &detector, gesturesRequired );
-      break;
-    }
+  GestureDetectorContainer*& containerPtr( GetContainerPtr( type ) );
+  DALI_ASSERT_DEBUG( containerPtr && "Container had not been created" );
+
+  GestureDetectorContainer& container( *containerPtr );
+  GestureDetectorContainer::iterator match( std::remove( container.begin(), container.end(), &detector ) );
+  DALI_ASSERT_DEBUG( match != container.end() && "Actor does not have the detector" );
+  container.erase( match, container.end() );
+
+  if ( container.empty() )
+  {
+    gesturesRequired = Gesture::Type( gesturesRequired & ~type );
+    delete containerPtr;
+    containerPtr = NULL;
   }
 }
 
-void ActorGestureData::RemoveGestureDetector( GestureDetector& detector )
+GestureDetectorContainer& ActorGestureData::GetGestureDetectorContainer( Gesture::Type type )
+{
+  return *GetContainerPtr( type );
+}
+
+GestureDetectorContainer*& ActorGestureData::GetContainerPtr( Gesture::Type type )
 {
-  switch ( detector.GetType() )
+  switch ( type )
   {
     case Gesture::Pan:
     {
-      RemoveDetector< PanGestureDetectorContainer >( panDetectors, &detector, gesturesRequired );
-      break;
+      return panDetectors;
     }
 
     case Gesture::Pinch:
     {
-      RemoveDetector< PinchGestureDetectorContainer >( pinchDetectors, &detector, gesturesRequired );
-      break;
+      return pinchDetectors;
     }
 
     case Gesture::LongPress:
     {
-      RemoveDetector< LongPressGestureDetectorContainer >( longPressDetectors, &detector, gesturesRequired );
-      break;
+      return longPressDetectors;
     }
 
     case Gesture::Tap:
     {
-      RemoveDetector< TapGestureDetectorContainer >( tapDetectors, &detector, gesturesRequired );
-      break;
+      return tapDetectors;
     }
   }
+
+  DALI_ASSERT_DEBUG( ! "Invalid Type" );
+  static GestureDetectorContainer* invalidType( NULL );
+  return invalidType;
 }
 
 } // namespace Internal
index 56cc947..2742ef1 100644 (file)
  */
 
 // INTERNAL INCLUDES
-#include <dali/internal/event/events/pan-gesture-detector-impl.h>
-#include <dali/internal/event/events/pinch-gesture-detector-impl.h>
-#include <dali/internal/event/events/long-press-gesture-detector-impl.h>
-#include <dali/internal/event/events/tap-gesture-detector-impl.h>
+#include <dali/internal/event/events/gesture-detector-impl.h>
 
 namespace Dali
 {
@@ -74,14 +71,29 @@ public:
     return type & gesturesRequired;
   }
 
+  /**
+   * Retrieve a reference to the detectors for the given type.
+   * @param[in] type The container type required
+   * @pre Ensure IsGestureRequired() is used to check if the container is actually available.
+   */
+  GestureDetectorContainer& GetGestureDetectorContainer( Gesture::Type type );
+
+private:
+
+  /**
+   * Helper to retrieve the appropriate container type.
+   * @param[in] type The container type required.
+   */
+  inline GestureDetectorContainer*& GetContainerPtr( Gesture::Type type );
+
 private:
 
   Gesture::Type gesturesRequired; ///< Stores which gestures are required
 
-  PanGestureDetectorContainer*       panDetectors;       ///< Pointer to a container of pan-detectors
-  PinchGestureDetectorContainer*     pinchDetectors;     ///< Pointer to a container of pinch-detectors
-  LongPressGestureDetectorContainer* longPressDetectors; ///< Pointer to a container of long-press-detectors
-  TapGestureDetectorContainer*       tapDetectors;       ///< Pointer to a container of tap-detectors
+  GestureDetectorContainer* panDetectors;       ///< Pointer to a container of pan-detectors
+  GestureDetectorContainer* pinchDetectors;     ///< Pointer to a container of pinch-detectors
+  GestureDetectorContainer* longPressDetectors; ///< Pointer to a container of long-press-detectors
+  GestureDetectorContainer* tapDetectors;       ///< Pointer to a container of tap-detectors
 };
 
 } // namespace Internal
index 548d204..297a4bd 100644 (file)
@@ -21,8 +21,9 @@
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 #include <dali/internal/event/actors/actor-impl.h>
-#include <dali/internal/event/render-tasks/render-task-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>
 
 namespace Dali
 {
@@ -73,88 +74,92 @@ GestureProcessor::~GestureProcessor()
   ResetActor();
 }
 
-void GestureProcessor::GetGesturedActor( Dali::Actor& actor, const GestureDetectorContainer& connectedDetectors, std::vector<GestureDetector*>& gestureDetectors, Functor& functor )
+void GestureProcessor::GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors, Functor& functor )
 {
   while ( actor )
   {
-    Actor* actorImpl( &GetImplementation(actor) );
-
-    // Check if our hit actor or any of its parents are attached to any registered detector.
-    // Find all detectors that have the actor attached.
-    for ( GestureDetectorContainer::const_iterator iter = connectedDetectors.begin(), endIter = connectedDetectors.end(); iter != endIter; ++iter )
+    // We may be checking a parent so ensure the parent requires this gesture (and do not unintentionally create the gesture data for the parent)
+    if ( actor->IsGestureRequred( mType ) )
     {
-      GestureDetector* current(*iter);
-
-      // Check whether the actor is attached to the gesture detector and then call the functor to
-      // check whether the gesture detector satisfies the current gesture's parameters.
-      if ( current->IsAttached( *actorImpl ) && functor( current, actorImpl ) )
+      // Retrieve the actor's detectors and check if they satisfy current gesture
+      const GestureDetectorContainer& connectedDetectors( actor->GetGestureData().GetGestureDetectorContainer( mType ) );
+      const GestureDetectorContainer::const_iterator endIter( connectedDetectors.end() );
+      for ( GestureDetectorContainer::const_iterator iter = connectedDetectors.begin(); iter != endIter; ++iter )
       {
-        gestureDetectors.push_back(current);
+        GestureDetector* current(*iter);
+
+        // Check whether the gesture detector satisfies the current gesture's parameters.
+        if ( functor( current, actor ) )
+        {
+          gestureDetectors.push_back(current);
+        }
       }
-    }
 
-    // The hit actor or one of the parents is a gestured actor, break out.
-    if ( !gestureDetectors.empty() )
-    {
-      break;
+      // The hit actor or one of the parents is a gestured actor, break out.
+      if ( !gestureDetectors.empty() )
+      {
+        break;
+      }
     }
 
     // No match, we should now check the hit actor's parent.
-    actor = actor.GetParent();
+    actor = actor->GetParent();
   }
 }
 
-void GestureProcessor::ProcessAndEmit( const HitTestAlgorithm::Results& hitTestResults, const GestureDetectorContainer& connectedDetectors, Functor& functor )
+void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults, Functor& functor )
 {
-  Dali::Actor actor( hitTestResults.actor );
-
-  while ( actor )
+  if ( hitTestResults.actor )
   {
-    std::vector<GestureDetector*> gestureDetectors;
+    Actor* hitTestActor( &GetImplementation( hitTestResults.actor ) );
+    Actor* actor( hitTestActor );
 
-    GetGesturedActor( actor, connectedDetectors, gestureDetectors, functor );
-
-    if ( actor && !gestureDetectors.empty() )
+    while ( actor )
     {
-      // We have a match but check if the hit point is within the gestured actor's bounds.
-      // If it is not then continue up the actor hierarchy.
+      GestureDetectorContainer gestureDetectors;
+      GetGesturedActor( actor, gestureDetectors, functor );
 
-      if ( actor == hitTestResults.actor )
-      {
-        // Our gesture detector's attached actor WAS the hit actor so we can call the emitting functor.
-        functor( actor, gestureDetectors, hitTestResults.actorCoordinates );
-        break; // We have found AND emitted a signal on the gestured actor, break out.
-      }
-      else
+      if ( actor && !gestureDetectors.empty() )
       {
-        if ( GetImplementation(actor).IsHittable() )
-        {
-          const Vector3 size( actor.GetCurrentSize() );
+        // We have a match but check if the hit point is within the gestured actor's bounds.
+        // If it is not then continue up the actor hierarchy.
 
-          if ( ( size.x > 0.0f ) && ( size.y > 0.0f ) )
+        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 );
+          break; // We have found AND emitted a signal on the gestured actor, break out.
+        }
+        else
+        {
+          if ( actor->IsHittable() )
           {
-            // Ensure tap is within the actor's area
-            Actor& actorImpl = GetImplementation(actor);
-            if ( actorImpl.RaySphereTest( hitTestResults.rayOrigin, hitTestResults.rayDirection ) ) // Quick check
+            const Vector3 size( actor->GetCurrentSize() );
+
+            if ( ( size.x > 0.0f ) && ( size.y > 0.0f ) )
             {
-              Vector4 hitPointLocal;
-              float distance( 0.0f );
-              if( actorImpl.RayActorTest( hitTestResults.rayOrigin, hitTestResults.rayDirection, hitPointLocal, distance ) )
+              // Ensure tap is within the actor's area
+              if ( actor->RaySphereTest( hitTestResults.rayOrigin, hitTestResults.rayDirection ) ) // Quick check
               {
-                // One of the hit actor's parents was the gestured actor so call the emitting functor.
-                functor( actor, gestureDetectors, Vector2( hitPointLocal.x, hitPointLocal.y ) );
-                break; // We have found AND emitted a signal on the gestured actor, break out.
+                Vector4 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 ) );
+                  break; // We have found AND emitted a signal on the gestured actor, break out.
+                }
               }
             }
           }
         }
       }
-    }
 
-    // Continue up hierarchy to see if any of the parents require this gesture.
-    if ( actor )
-    {
-      actor = actor.GetParent();
+      // Continue up hierarchy to see if any of the parents require this gesture.
+      if ( actor )
+      {
+        actor = actor->GetParent();
+      }
     }
   }
 }
@@ -169,13 +174,13 @@ bool GestureProcessor::HitTest(
   return hitTestResults.renderTask && hitTestResults.actor;
 }
 
-void GestureProcessor::SetActor( Dali::Actor actor )
+void GestureProcessor::SetActor( Actor* actor )
 {
   if ( actor && actor != mCurrentGesturedActor )
   {
     ResetActor();
 
-    mCurrentGesturedActor = &GetImplementation( actor );
+    mCurrentGesturedActor = actor;
     mCurrentGesturedActor->AddObserver( *this );
   }
   mGesturedActorDisconnected = false;
index 0a4e1e3..2e0f3ab 100644 (file)
@@ -48,34 +48,7 @@ protected: // Construction & Destruction
    */
   virtual ~GestureProcessor();
 
-  // Templates and types for deriving classes
-
-  /**
-   * Given a container of derived pointer types, this populates an equivalent container of base pointer types.
-   * @param[in]   derivedContainer  A const reference to the container with pointers to the derived class.
-   * @param[out]  baseContainer     A reference to the container to populate with equivalent pointers to the base class.
-   * @pre Ensure the baseContainer is empty.
-   */
-  template< typename Detector >
-  static void UpCastContainer( const typename DerivedGestureDetectorContainer<Detector>::type& derivedContainer, GestureDetectorContainer& baseContainer )
-  {
-    baseContainer.assign( derivedContainer.begin(), derivedContainer.end() );
-  }
-
-  /**
-   * Given a container of base pointer types, this populates an equivalent container of derived pointer types.
-   * @param[in]   baseContainer     A const reference to the container with pointers to the base class.
-   * @param[out]  derivedContainer  A reference to the container to populate with equivalent pointers to the derived class.
-   * @pre Ensure the derivedContainer is empty.
-   */
-  template< typename Detector >
-  static void DownCastContainer( const GestureDetectorContainer& baseContainer, typename DerivedGestureDetectorContainer<Detector>::type& derivedContainer )
-  {
-    for ( GestureDetectorContainer::const_iterator iter = baseContainer.begin(), endIter = baseContainer.end(); iter != endIter; ++iter )
-    {
-      derivedContainer.push_back( static_cast< Detector* >( *iter ) );
-    }
-  }
+  // Types for deriving classes
 
   /**
    * Functor to use in GetGesturedActor() and ProcessAndEmit() methods.
@@ -97,35 +70,31 @@ protected: // Construction & Destruction
      * @param[in]  gestureDetectors  The detectors that should emit the signal.
      * @param[in]  actorCoordinates  The local actor coordinates where the gesture took place.
      */
-    virtual void operator() ( Dali::Actor actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
+    virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
   };
 
   // Methods for deriving classes
 
   /**
-   * Given the hit actor and attached detectors, this walks up the actor tree to determine the actor that is connected to one (or several) gesture
-   * detectors. The functor is used to check whether the gesture falls within the gesture detector's parameters.
-   * Derived classes need to provide this functor.
+   * Given the hit actor, this walks up the actor tree to determine the actor that is connected to one (or several) gesture detectors.
    *
-   * @param[in,out]  actor               The hit actor. When this function returns, this is the actor that has been hit by the gesture.
-   * @param[in]      connectedDetectors  Reference to the detectors connected to the derived processor
+   * @param[in,out]  actor               The gestured actor. When this function returns, this is the actor that has been hit by the gesture.
    * @param[out]     gestureDetectors    A container containing all the gesture detectors that have the hit actor attached and satisfy the functor parameters.
-   * @param[in]      functor             A reference to Functor.  The operator() (GestureDetector*) should be used to check if the connected gesture detector
-   *                                     meets the current gesture's parameters.
+   * @param[in]      functor             Used to check if a gesture-detector matches the criteria the gesture detector requires.
+   *
+   * @pre gestureDetectors should be empty.
    */
-  void GetGesturedActor( Dali::Actor& actor, const GestureDetectorContainer& connectedDetectors, GestureDetectorContainer& gestureDetectors, Functor& functor );
+  void GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors, Functor& functor );
 
   /**
-   * This does what GetGesturedActor() does but also starts emission of the gesture (using the functor).
+   * Calls the emission method in the deriving class for matching gesture-detectors with the hit-actor (or one of its parents).
    *
    * @param[in]  hitTestResults      The Hit Test Results.
-   * @param[in]  connectedDetectors  The detectors attached to the gesture processor.
-   * @param[in]  functor             A reference to the functor which should provide an operator() to check if detector satisfies current gesture and another
-   *                                 operator() which will be called when all conditions are met and the gesture should be emitted for the actor and detectors.
+   * @param[in]  functor             Used to check if a gesture-detector matches the criteria the gesture detector requires and for emitting the signal.
    *
    * @pre Hit Testing should already be done.
    */
-  void ProcessAndEmit( const HitTestAlgorithm::Results& hitTestResults, const GestureDetectorContainer& connectedDetectors, Functor& functor );
+  void ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults, Functor& functor );
 
   /**
    * Hit test the screen coordinates, and place the results in hitTestResults.
@@ -140,7 +109,7 @@ protected: // Construction & Destruction
    * Sets the mCurrentGesturedActor and connects to the required signals.
    * @actor  actor  The actor so set.
    */
-  void SetActor( Dali::Actor actor );
+  void SetActor( Actor* actor );
 
   /**
    * Resets the set actor and disconnects any connected signals.
index 5542410..f031898 100644 (file)
@@ -49,8 +49,8 @@ namespace
  * @param[in]  localPoint        Relative to the actor attached to the detector.
  */
 void EmitLongPressSignal(
-    Dali::Actor actor,
-    LongPressGestureDetectorContainer& gestureDetectors,
+    Actor* actor,
+    const GestureDetectorContainer& gestureDetectors,
     const Integration::LongPressGestureEvent& longPressEvent,
     Vector2 localPoint)
 {
@@ -60,9 +60,11 @@ void EmitLongPressSignal(
   longPress.screenPoint = longPressEvent.point;
   longPress.localPoint = localPoint;
 
-  for ( LongPressGestureDetectorContainer::iterator iter = gestureDetectors.begin(), endIter = gestureDetectors.end(); iter != endIter; ++iter )
+  Dali::Actor actorHandle( actor );
+  const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
+  for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
   {
-    (*iter)->EmitLongPressGestureSignal(actor, longPress);
+    static_cast< LongPressGestureDetector* >( *iter )->EmitLongPressGestureSignal( actorHandle, longPress );
   }
 }
 
@@ -86,7 +88,7 @@ struct IsNotAttachedFunctor
    * @param[in]  detector  The detector to check.
    * @return true, if not attached, false otherwise.
    */
-  bool operator()( const LongPressGestureDetector* detector ) const
+  bool operator()( const GestureDetector* detector ) const
   {
     return !detector->IsAttached( *actorToCheck );
   }
@@ -123,20 +125,17 @@ struct LongPressGestureProcessor::LongPressEventFunctor : public GestureProcesso
   /**
    * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
    */
-  virtual void operator() ( Dali::Actor actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
   {
-    LongPressGestureDetectorContainer derivedContainer;
-    DownCastContainer<LongPressGestureDetector>( gestureDetectors, derivedContainer );
-
     // Clear actor as
     processor.mCurrentEmitters.clear();
     processor.ResetActor();
 
-    EmitLongPressSignal( actor, derivedContainer, longPressEvent, actorCoordinates );
+    EmitLongPressSignal( actor, gestureDetectors, longPressEvent, actorCoordinates );
 
-    if ( actor.OnStage() )
+    if ( actor->OnStage() )
     {
-      processor.mCurrentEmitters = derivedContainer;
+      processor.mCurrentEmitters = gestureDetectors;
       processor.SetActor( actor );
     }
   }
@@ -173,7 +172,7 @@ void LongPressGestureProcessor::Process( const Integration::LongPressGestureEven
       HitTestAlgorithm::Results hitTestResults;
       if( HitTest( mStage, longPressEvent.point, hitTestResults ) )
       {
-        SetActor( hitTestResults.actor );
+        SetActor( &GetImplementation( hitTestResults.actor ) );
       }
       break;
     }
@@ -192,9 +191,7 @@ void LongPressGestureProcessor::Process( const Integration::LongPressGestureEven
           mCurrentRenderTask = hitTestResults.renderTask;
 
           LongPressEventFunctor functor( longPressEvent, *this );
-          GestureDetectorContainer gestureDetectors;
-          UpCastContainer<LongPressGestureDetector>( mGestureDetectors, gestureDetectors );
-          ProcessAndEmit( hitTestResults, gestureDetectors, functor );
+          ProcessAndEmit( hitTestResults, functor );
         }
         else
         {
@@ -219,7 +216,7 @@ void LongPressGestureProcessor::Process( const Integration::LongPressGestureEven
         if ( currentGesturedActor->IsHittable() && !mCurrentEmitters.empty() && mCurrentRenderTask )
         {
           // Ensure actor is still attached to the emitters, if it is not then remove the emitter.
-          LongPressGestureDetectorContainer::iterator endIter = std::remove_if( mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) );
+          GestureDetectorContainer::iterator endIter = std::remove_if( mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) );
           mCurrentEmitters.erase( endIter, mCurrentEmitters.end() );
 
           if ( !mCurrentEmitters.empty() )
@@ -228,7 +225,7 @@ void LongPressGestureProcessor::Process( const Integration::LongPressGestureEven
             RenderTask& renderTaskImpl( GetImplementation( mCurrentRenderTask ) );
             currentGesturedActor->ScreenToLocal( renderTaskImpl, actorCoords.x, actorCoords.y, longPressEvent.point.x, longPressEvent.point.y );
 
-            EmitLongPressSignal( Dali::Actor( currentGesturedActor ), mCurrentEmitters, longPressEvent, actorCoords );
+            EmitLongPressSignal( currentGesturedActor, mCurrentEmitters, longPressEvent, actorCoords );
           }
         }
 
index e023b7b..0deb871 100644 (file)
@@ -121,7 +121,7 @@ private:
   Integration::GestureManager& mGestureManager;
   LongPressGestureDetectorContainer mGestureDetectors;
 
-  LongPressGestureDetectorContainer mCurrentEmitters;
+  GestureDetectorContainer mCurrentEmitters;
   Dali::RenderTask mCurrentRenderTask;
 
   unsigned int mMinTouchesRequired;
index 1a3ea2b..3f52e19 100644 (file)
@@ -59,7 +59,7 @@ struct IsNotAttachedAndOutsideTouchesRangeFunctor
    * @param[in]  touches               The number of touches in the current pan event.
    * @param[in]  outsideRangeEmitters  Reference to container where emitters outside of the touches range should be added.
    */
-  IsNotAttachedAndOutsideTouchesRangeFunctor(Actor* actor, unsigned int touches, PanGestureDetectorContainer& outsideRangeEmitters)
+  IsNotAttachedAndOutsideTouchesRangeFunctor(Actor* actor, unsigned int touches, GestureDetectorContainer& outsideRangeEmitters)
   : actorToCheck(actor),
     numberOfTouches(touches),
     outsideTouchesRangeEmitters(outsideRangeEmitters)
@@ -73,16 +73,18 @@ struct IsNotAttachedAndOutsideTouchesRangeFunctor
    * @param[in]  detector  The detector to check.
    * @return true, if not attached, false otherwise.
    */
-  bool operator()(PanGestureDetector* detector) const
+  bool operator()(GestureDetector* detector) const
   {
     bool remove(!detector->IsAttached(*actorToCheck));
 
     if (!remove)
     {
+      PanGestureDetector* panDetector( static_cast< PanGestureDetector* >( detector ) );
+
       // Ensure number of touch points is within the range of our emitter. If it isn't then remove
       // this emitter and add it to the outsideTouchesRangeEmitters container
-      if ( (numberOfTouches < detector->GetMinimumTouchesRequired()) ||
-           (numberOfTouches > detector->GetMaximumTouchesRequired()) )
+      if ( (numberOfTouches < panDetector->GetMinimumTouchesRequired()) ||
+           (numberOfTouches > panDetector->GetMaximumTouchesRequired()) )
       {
         remove = true;
         outsideTouchesRangeEmitters.push_back(detector);
@@ -94,7 +96,7 @@ struct IsNotAttachedAndOutsideTouchesRangeFunctor
 
   Actor* actorToCheck; ///< The actor to check whether it is attached or not.
   unsigned int numberOfTouches; ///< The number of touches in the pan event.
-  PanGestureDetectorContainer& outsideTouchesRangeEmitters; ///< Emitters that are outside of the range of current pan.
+  GestureDetectorContainer& outsideTouchesRangeEmitters; ///< Emitters that are outside of the range of current pan.
 };
 
 } // unnamed namespace
@@ -188,22 +190,18 @@ struct PanGestureProcessor::PanEventFunctor : public GestureProcessor::Functor
   /**
    * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
    */
-  virtual void operator() ( Dali::Actor actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
   {
-    PanGestureDetectorContainer derivedContainer;
-    DownCastContainer<PanGestureDetector>( gestureDetectors, derivedContainer );
-
     processor.mCurrentPanEmitters.clear();
     processor.ResetActor();
 
-    Actor* actorImpl( &GetImplementation( actor ) );
-    actorImpl->ScreenToLocal( GetImplementation(processor.mCurrentRenderTask), actorCoordinates.x, actorCoordinates.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
+    actor->ScreenToLocal( GetImplementation(processor.mCurrentRenderTask), actorCoordinates.x, actorCoordinates.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
 
-    processor.EmitPanSignal( actor, derivedContainer, panEvent, actorCoordinates, panEvent.state, processor.mCurrentRenderTask );
+    processor.EmitPanSignal( actor, gestureDetectors, panEvent, actorCoordinates, panEvent.state, processor.mCurrentRenderTask );
 
-    if ( actorImpl->OnStage() )
+    if ( actor->OnStage() )
     {
-      processor.mCurrentPanEmitters = derivedContainer;
+      processor.mCurrentPanEmitters = gestureDetectors;
       processor.SetActor( actor );
     }
   }
@@ -249,7 +247,7 @@ void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent
       HitTestAlgorithm::Results hitTestResults;
       if( HitTest( mStage, panEvent.currentPosition, hitTestResults ) )
       {
-        SetActor( hitTestResults.actor );
+        SetActor( &GetImplementation( hitTestResults.actor ) );
         mPossiblePanPosition = panEvent.currentPosition;
       }
 
@@ -272,9 +270,7 @@ void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent
           mCurrentRenderTask = hitTestResults.renderTask;
 
           PanEventFunctor functor( panEvent, *this );
-          GestureDetectorContainer gestureDetectors;
-          UpCastContainer<PanGestureDetector>( mGestureDetectors, gestureDetectors );
-          ProcessAndEmit( hitTestResults, gestureDetectors, functor );
+          ProcessAndEmit( hitTestResults, functor );
         }
         else
         {
@@ -297,12 +293,12 @@ void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent
       {
         if ( currentGesturedActor->IsHittable() && !mCurrentPanEmitters.empty() && mCurrentRenderTask )
         {
-          PanGestureDetectorContainer outsideTouchesRangeEmitters;
+          GestureDetectorContainer outsideTouchesRangeEmitters;
 
           // Removes emitters that no longer have the actor attached
           // Also remove emitters whose touches are outside the range of the current pan event and add them to outsideTouchesRangeEmitters
-          PanGestureDetectorContainer::iterator endIter = std::remove_if( mCurrentPanEmitters.begin(), mCurrentPanEmitters.end(),
-                                                                          IsNotAttachedAndOutsideTouchesRangeFunctor(currentGesturedActor, panEvent.numberOfTouches, outsideTouchesRangeEmitters) );
+          GestureDetectorContainer::iterator endIter = std::remove_if( mCurrentPanEmitters.begin(), mCurrentPanEmitters.end(),
+                                                                       IsNotAttachedAndOutsideTouchesRangeFunctor(currentGesturedActor, panEvent.numberOfTouches, outsideTouchesRangeEmitters) );
           mCurrentPanEmitters.erase( endIter, mCurrentPanEmitters.end() );
 
           Vector2 actorCoords;
@@ -312,8 +308,8 @@ void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent
             currentGesturedActor->ScreenToLocal( GetImplementation( mCurrentRenderTask ), 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(Dali::Actor(currentGesturedActor), outsideTouchesRangeEmitters, panEvent, actorCoords, Gesture::Finished, mCurrentRenderTask);
-            EmitPanSignal(Dali::Actor(currentGesturedActor), mCurrentPanEmitters, panEvent, actorCoords, panEvent.state, mCurrentRenderTask);
+            EmitPanSignal( currentGesturedActor, outsideTouchesRangeEmitters, panEvent, actorCoords, Gesture::Finished, mCurrentRenderTask);
+            EmitPanSignal( currentGesturedActor, mCurrentPanEmitters, panEvent, actorCoords, panEvent.state, mCurrentRenderTask);
           }
 
           if ( mCurrentPanEmitters.empty() )
@@ -374,7 +370,7 @@ void PanGestureProcessor::RemoveGestureDetector( PanGestureDetector* gestureDete
   if (!mCurrentPanEmitters.empty())
   {
     // Check if the removed detector was one that is currently being panned and remove it from emitters.
-    PanGestureDetectorContainer::iterator endIter = std::remove( mCurrentPanEmitters.begin(), mCurrentPanEmitters.end(), gestureDetector );
+    GestureDetectorContainer::iterator endIter = std::remove( mCurrentPanEmitters.begin(), mCurrentPanEmitters.end(), gestureDetector );
     mCurrentPanEmitters.erase( endIter, mCurrentPanEmitters.end() );
 
     // If we no longer have any emitters, then we should clear mCurrentGesturedActor as well
@@ -477,17 +473,15 @@ void PanGestureProcessor::UpdateDetection()
   }
 }
 
-void PanGestureProcessor::EmitPanSignal( Dali::Actor actorHandle,
-                                         PanGestureDetectorContainer& gestureDetectors,
+void PanGestureProcessor::EmitPanSignal( Actor* actor,
+                                         const GestureDetectorContainer& gestureDetectors,
                                          const Integration::PanGestureEvent& panEvent,
                                          Vector2 localCurrent,
                                          Gesture::State state,
                                          Dali::RenderTask renderTask )
 {
-  if ( actorHandle && !gestureDetectors.empty() )
+  if ( actor && !gestureDetectors.empty() )
   {
-    Actor& actor = GetImplementation(actorHandle);
-
     PanGesture pan(state);
     pan.time = panEvent.time;
 
@@ -498,7 +492,7 @@ void PanGestureProcessor::EmitPanSignal( Dali::Actor actorHandle,
     RenderTask& renderTaskImpl( GetImplementation( renderTask ) );
 
     Vector2 localPrevious;
-    actor.ScreenToLocal( renderTaskImpl, localPrevious.x, localPrevious.y, panEvent.previousPosition.x, panEvent.previousPosition.y );
+    actor->ScreenToLocal( renderTaskImpl, localPrevious.x, localPrevious.y, panEvent.previousPosition.x, panEvent.previousPosition.y );
 
     pan.displacement = localCurrent - localPrevious;
     Vector2 previousPos( panEvent.previousPosition );
@@ -537,9 +531,11 @@ void PanGestureProcessor::EmitPanSignal( Dali::Actor actorHandle,
       mSceneObject->AddGesture( pan );
     }
 
-    for ( PanGestureDetectorContainer::iterator iter = gestureDetectors.begin(), endIter = gestureDetectors.end(); iter != endIter; ++iter )
+    Dali::Actor actorHandle( actor );
+    const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
+    for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
     {
-      (*iter)->EmitPanGestureSignal(actorHandle, pan);
+      static_cast< PanGestureDetector* >( *iter )->EmitPanGestureSignal( actorHandle, pan );
     }
   }
 }
index ec92f0d..f93ff03 100644 (file)
@@ -154,8 +154,8 @@ private:
    * @param[in]  state             The state of the gesture.
    * @param[in]  renderTask        The renderTask to use.
    */
-  void EmitPanSignal( Dali::Actor actor,
-                      PanGestureDetectorContainer& gestureDetectors,
+  void EmitPanSignal( Actor* actor,
+                      const GestureDetectorContainer& gestureDetectors,
                       const Integration::PanGestureEvent& panEvent,
                       Vector2 localCurrent,
                       Gesture::State state,
@@ -173,7 +173,7 @@ private:
   Stage& mStage;
   Integration::GestureManager& mGestureManager;
   PanGestureDetectorContainer mGestureDetectors;
-  PanGestureDetectorContainer mCurrentPanEmitters;
+  GestureDetectorContainer mCurrentPanEmitters;
   Dali::RenderTask mCurrentRenderTask;
   Vector2 mPossiblePanPosition;
 
index 52bcdb0..79e2d6c 100644 (file)
@@ -48,8 +48,8 @@ namespace
  * @param[in]  localCenter       Relative to the actor attached to the detector.
  */
 void EmitPinchSignal(
-    Dali::Actor actor,
-    PinchGestureDetectorContainer& gestureDetectors,
+    Actor* actor,
+    const GestureDetectorContainer& gestureDetectors,
     const Integration::PinchGestureEvent& pinchEvent,
     Vector2 localCenter)
 {
@@ -62,9 +62,11 @@ void EmitPinchSignal(
 
   pinch.localCenterPoint = localCenter;
 
-  for ( PinchGestureDetectorContainer::iterator iter = gestureDetectors.begin(), endIter = gestureDetectors.end(); iter != endIter; ++iter )
+  Dali::Actor actorHandle( actor );
+  const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
+  for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
   {
-    (*iter)->EmitPinchGestureSignal(actor, pinch);
+    static_cast< PinchGestureDetector* >( *iter )->EmitPinchGestureSignal( actorHandle, pinch );
   }
 }
 
@@ -88,7 +90,7 @@ struct IsNotAttachedFunctor
    * @param[in]  detector  The detector to check.
    * @return true, if not attached, false otherwise.
    */
-  bool operator()(const PinchGestureDetector* detector) const
+  bool operator()(const GestureDetector* detector) const
   {
     return !detector->IsAttached(*actorToCheck);
   }
@@ -122,16 +124,13 @@ struct PinchGestureProcessor::PinchEventFunctor : public GestureProcessor::Funct
   /**
    * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
    */
-  virtual void operator() ( Dali::Actor actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
   {
-    PinchGestureDetectorContainer derivedContainer;
-    DownCastContainer<PinchGestureDetector>( gestureDetectors, derivedContainer );
+    EmitPinchSignal( actor, gestureDetectors, pinchEvent, actorCoordinates );
 
-    EmitPinchSignal( actor, derivedContainer, pinchEvent, actorCoordinates );
-
-    if ( actor.OnStage() )
+    if ( actor->OnStage() )
     {
-      processor.mCurrentPinchEmitters = derivedContainer;
+      processor.mCurrentPinchEmitters = gestureDetectors;
       processor.SetActor( actor );
     }
   }
@@ -172,9 +171,7 @@ void PinchGestureProcessor::Process( const Integration::PinchGestureEvent& pinch
         mCurrentRenderTask = hitTestResults.renderTask;
 
         PinchEventFunctor functor( pinchEvent, *this ); // Sets mCurrentGesturedActor
-        GestureDetectorContainer gestureDetectors;
-        UpCastContainer<PinchGestureDetector>( mGestureDetectors, gestureDetectors );
-        ProcessAndEmit( hitTestResults, gestureDetectors, functor );
+        ProcessAndEmit( hitTestResults, functor );
       }
       break;
     }
@@ -192,7 +189,7 @@ void PinchGestureProcessor::Process( const Integration::PinchGestureEvent& pinch
         if ( currentGesturedActor->IsHittable() && !mCurrentPinchEmitters.empty() && mCurrentRenderTask )
         {
           // Ensure actor is still attached to the emitters, if it is not then remove the emitter.
-          PinchGestureDetectorContainer::iterator endIter = std::remove_if( mCurrentPinchEmitters.begin(), mCurrentPinchEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) );
+          GestureDetectorContainer::iterator endIter = std::remove_if( mCurrentPinchEmitters.begin(), mCurrentPinchEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) );
           mCurrentPinchEmitters.erase( endIter, mCurrentPinchEmitters.end() );
 
           if ( !mCurrentPinchEmitters.empty() )
@@ -201,7 +198,7 @@ void PinchGestureProcessor::Process( const Integration::PinchGestureEvent& pinch
             RenderTask& renderTaskImpl( GetImplementation(mCurrentRenderTask) );
             currentGesturedActor->ScreenToLocal( renderTaskImpl, actorCoords.x, actorCoords.y, pinchEvent.centerPoint.x, pinchEvent.centerPoint.y );
 
-            EmitPinchSignal( Dali::Actor(currentGesturedActor), mCurrentPinchEmitters, pinchEvent, actorCoords );
+            EmitPinchSignal( currentGesturedActor, mCurrentPinchEmitters, pinchEvent, actorCoords );
           }
           else
           {
@@ -253,7 +250,7 @@ void PinchGestureProcessor::RemoveGestureDetector( PinchGestureDetector* gesture
   if ( !mCurrentPinchEmitters.empty() )
   {
     // Check if the removed detector was one that is currently being pinched and remove it from emitters.
-    PinchGestureDetectorContainer::iterator endIter = std::remove( mCurrentPinchEmitters.begin(), mCurrentPinchEmitters.end(), gestureDetector );
+    GestureDetectorContainer::iterator endIter = std::remove( mCurrentPinchEmitters.begin(), mCurrentPinchEmitters.end(), gestureDetector );
     mCurrentPinchEmitters.erase( endIter, mCurrentPinchEmitters.end() );
 
     // If we no longer have any emitters, then we should clear mCurrentGesturedActor as well
index 7f0e267..01a387c 100644 (file)
@@ -115,7 +115,7 @@ private:
   Stage& mStage;
   Integration::GestureManager& mGestureManager;
   PinchGestureDetectorContainer mGestureDetectors;
-  PinchGestureDetectorContainer mCurrentPinchEmitters;
+  GestureDetectorContainer mCurrentPinchEmitters;
   Dali::RenderTask mCurrentRenderTask;
 
   struct PinchEventFunctor;
index bdfbd07..1c3aa58 100644 (file)
@@ -50,8 +50,8 @@ namespace
  * @param[in]  localPoint        Relative to the actor attached to the detector.
  */
 void EmitTapSignal(
-    Dali::Actor actor,
-    TapGestureDetectorContainer& gestureDetectors,
+    Actor* actor,
+    const GestureDetectorContainer& gestureDetectors,
     const Integration::TapGestureEvent& tapEvent,
     Vector2 localPoint)
 {
@@ -62,9 +62,11 @@ void EmitTapSignal(
   tap.screenPoint = tapEvent.point;
   tap.localPoint = localPoint;
 
-  for ( TapGestureDetectorContainer::iterator iter = gestureDetectors.begin(), endIter = gestureDetectors.end(); iter != endIter; ++iter )
+  Dali::Actor actorHandle( actor );
+  const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
+  for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
   {
-    (*iter)->EmitTapGestureSignal( actor, tap );
+    static_cast< TapGestureDetector* >( *iter )->EmitTapGestureSignal( actorHandle, tap );
   }
 }
 
@@ -95,11 +97,9 @@ struct TapGestureProcessor::TapEventFunctor : public GestureProcessor::Functor
   /**
    * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
    */
-  virtual void operator() ( Dali::Actor actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
   {
-    TapGestureDetectorContainer derivedContainer;
-    DownCastContainer<TapGestureDetector>( gestureDetectors, derivedContainer );
-    EmitTapSignal( actor, derivedContainer, tapEvent, actorCoordinates );
+    EmitTapSignal( actor, gestureDetectors, tapEvent, actorCoordinates );
   }
 
   const Integration::TapGestureEvent& tapEvent;
@@ -133,7 +133,7 @@ void TapGestureProcessor::Process( const Integration::TapGestureEvent& tapEvent
       if( HitTest( mStage, tapEvent.point, hitTestResults ) )
       {
         // Only sets the actor if we have a hit.
-        SetActor( hitTestResults.actor );
+        SetActor( &GetImplementation( hitTestResults.actor ) );
       }
       break;
     }
@@ -148,9 +148,7 @@ void TapGestureProcessor::Process( const Integration::TapGestureEvent& tapEvent
         if ( hitTestResults.actor && ( GetCurrentGesturedActor() == &GetImplementation( hitTestResults.actor ) ) )
         {
           TapEventFunctor functor( tapEvent );
-          GestureDetectorContainer gestureDetectors;
-          UpCastContainer<TapGestureDetector>( mGestureDetectors, gestureDetectors );
-          ProcessAndEmit( hitTestResults, gestureDetectors, functor );
+          ProcessAndEmit( hitTestResults, functor );
         }
 
         ResetActor();