(Gestures) Remove Functor usage from processors 90/24090/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 20 Jun 2014 08:22:17 +0000 (17:22 +0900)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 8 Jul 2014 13:19:39 +0000 (14:19 +0100)
[problem]     Functor usage is confusing and they need to be stack-allocated at the start of every
              gesture.
[cause]       N/A
[solution]    Use deriving methods instead which is a bit clearer and does not require stack allocation
              when the gesture starts.

Change-Id: I099eed5677914301559c5ff7ca55a170b5a99816
Signed-off-by: Adeel Kazmi <adeel.kazmi@samsung.com>
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
dali/internal/event/events/tap-gesture-processor.h

index 95f798f..1457467 100644 (file)
@@ -80,7 +80,7 @@ GestureProcessor::~GestureProcessor()
   ResetActor();
 }
 
-void GestureProcessor::GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors, Functor& functor )
+void GestureProcessor::GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors )
 {
   while ( actor )
   {
@@ -94,8 +94,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 +113,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 +123,7 @@ void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults
     while ( actor )
     {
       GestureDetectorContainer gestureDetectors;
-      GetGesturedActor( actor, gestureDetectors, functor );
+      GetGesturedActor( actor, gestureDetectors );
 
       if ( actor && !gestureDetectors.empty() )
       {
@@ -132,8 +132,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
@@ -151,8 +151,8 @@ void GestureProcessor::ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults
                 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, Vector2( hitPointLocal.x, hitPointLocal.y ) );
                   break; // We have found AND emitted a signal on the gestured actor, break out.
                 }
               }
index 2e0f3ab..2469f33 100644 (file)
@@ -36,7 +36,9 @@ namespace Internal
  */
 class GestureProcessor : public ProxyObject::Observer
 {
-protected: // Construction & Destruction
+protected:
+
+  // Construction & Destruction
 
   /**
    * Protected constructor.  Cannot create an instance of GestureProcessor
@@ -48,53 +50,29 @@ protected: // Construction & Destruction
    */
   virtual ~GestureProcessor();
 
-  // Types for deriving classes
-
-  /**
-   * Functor to use in GetGesturedActor() and ProcessAndEmit() methods.
-   */
-  struct Functor
-  {
-    /**
-     * This operator should be overridden to check if the gesture detector meets the parameters of the current gesture.
-     * @param[in]  detector  The gesture detector to check.
-     * @param[in]  actor     The actor that has been gestured.
-     * @return true, if it meets the parameters, false otherwise.
-     */
-    virtual bool operator() ( GestureDetector* detector, Actor* actor ) = 0;
-
-    /**
-     * This operator should be overridden to emit the gesture signal on the provided container of gesture detectors along with the actor
-     * the gesture has occurred on.
-     * @param[in]  actor             The actor which has been gestured.
-     * @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() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
-  };
-
-  // Methods for deriving classes
+  // Methods to be used by deriving classes
 
   /**
    * 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 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             Used to check if a gesture-detector matches the criteria the gesture detector requires.
    *
+   * @note Uses CheckGestureDetector() to check if a the current gesture matches the criteria the gesture detector requires.
    * @pre gestureDetectors should be empty.
    */
-  void GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors, Functor& functor );
+  void GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors );
 
   /**
    * 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]  functor             Used to check if a gesture-detector matches the criteria the gesture detector requires and for emitting the signal.
    *
+   * @note Uses the CheckGestureDetector() to check if the gesture matches the criteria of the given gesture detector
+   *       and EmitGestureSignal() to emit the signal.
    * @pre Hit Testing should already be done.
    */
-  void ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults, Functor& functor );
+  void ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults );
 
   /**
    * Hit test the screen coordinates, and place the results in hitTestResults.
@@ -123,6 +101,8 @@ protected: // Construction & Destruction
    */
   Actor* GetCurrentGesturedActor();
 
+private:
+
   // For derived classes to override
 
   /**
@@ -130,13 +110,34 @@ protected: // Construction & Destruction
    */
   virtual void OnGesturedActorStageDisconnection() = 0;
 
-private:
+  /**
+   * Called by the ProcessAndEmit() & GetGesturedActor() methods to check if the provided
+   * gesture-detector meets the parameters of the current gesture.
+   *
+   * @param[in]  detector  The gesture detector to check.
+   * @param[in]  actor     The actor that has been gestured.
+   *
+   * @return true, if the detector meets the parameters, false otherwise.
+   */
+  virtual bool CheckGestureDetector( GestureDetector* detector, Actor* actor ) = 0;
+
+  /**
+   * Called by the ProcessAndEmit() method when the gesture meets all applicable criteria and
+   * should be overridden by deriving classes to emit the gesture signal on gesture-detectors
+   * provided for the actor the gesture has occurred on.
+   *
+   * @param[in]  actor             The actor which has been gestured.
+   * @param[in]  gestureDetectors  The detectors that should emit the signal.
+   * @param[in]  actorCoordinates  The local actor coordinates where the gesture took place.
+   */
+  virtual void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
 
   // Undefined
+
   GestureProcessor( const GestureProcessor& );
   GestureProcessor& operator=( const GestureProcessor& );
 
-private:
+  // SceneObject overrides
 
   /**
    * This will never get called as we do not observe objects that have not been added to the scene.
@@ -160,14 +161,6 @@ private:
    */
   virtual void ProxyDestroyed(ProxyObject& proxy);
 
-  // Signal Handlers
-
-  /**
-   * Signal handler called when the actor is removed from the stage.
-   * @param[in]  actor  The actor removed from the stage.
-   */
-  void OnStageDisconnection( Dali::Actor actor );
-
 private: // Data
 
   Gesture::Type mType;                 ///< Type of GestureProcessor
index f031898..6fc846a 100644 (file)
@@ -98,52 +98,6 @@ struct IsNotAttachedFunctor
 
 } // unnamed namespace
 
-struct LongPressGestureProcessor::LongPressEventFunctor : public GestureProcessor::Functor
-{
-  /**
-   * Constructor
-   * @param[in]  event      The current gesture event.
-   * @param[in]  processor  Reference to the processor.
-   */
-  LongPressEventFunctor( const Integration::LongPressGestureEvent& event, LongPressGestureProcessor& processor )
-  : longPressEvent( event ),
-    processor( processor )
-  {
-  }
-
-  /**
-   * Check if the detector meets the current gesture event parameters.
-   */
-  virtual bool operator() ( GestureDetector* detector, Actor* )
-  {
-    LongPressGestureDetector* longPressDetector ( static_cast< LongPressGestureDetector* >( detector ) );
-
-    return ( longPressDetector->GetMinimumTouchesRequired() <= longPressEvent.numberOfTouches ) &&
-           ( longPressDetector->GetMaximumTouchesRequired() >= longPressEvent.numberOfTouches );
-  }
-
-  /**
-   * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
-   */
-  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
-  {
-    // Clear actor as
-    processor.mCurrentEmitters.clear();
-    processor.ResetActor();
-
-    EmitLongPressSignal( actor, gestureDetectors, longPressEvent, actorCoordinates );
-
-    if ( actor->OnStage() )
-    {
-      processor.mCurrentEmitters = gestureDetectors;
-      processor.SetActor( actor );
-    }
-  }
-
-  const Integration::LongPressGestureEvent& longPressEvent;
-  LongPressGestureProcessor& processor;
-};
-
 LongPressGestureProcessor::LongPressGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager)
 : GestureProcessor( Gesture::LongPress ),
   mStage( stage ),
@@ -152,7 +106,8 @@ LongPressGestureProcessor::LongPressGestureProcessor( Stage& stage, Integration:
   mCurrentEmitters(),
   mCurrentRenderTask(),
   mMinTouchesRequired( 1 ),
-  mMaxTouchesRequired( 1 )
+  mMaxTouchesRequired( 1 ),
+  mCurrentLongPressEvent( NULL )
 {
 }
 
@@ -190,8 +145,10 @@ void LongPressGestureProcessor::Process( const Integration::LongPressGestureEven
           // Record the current render-task for Screen->Actor coordinate conversions
           mCurrentRenderTask = hitTestResults.renderTask;
 
-          LongPressEventFunctor functor( longPressEvent, *this );
-          ProcessAndEmit( hitTestResults, functor );
+          // Set mCurrentLongPressEvent to use inside overridden methods called from ProcessAndEmit()
+          mCurrentLongPressEvent = &longPressEvent;
+          ProcessAndEmit( hitTestResults );
+          mCurrentLongPressEvent = NULL;
         }
         else
         {
@@ -343,6 +300,32 @@ void LongPressGestureProcessor::OnGesturedActorStageDisconnection()
   mCurrentEmitters.clear();
 }
 
+bool LongPressGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor )
+{
+  DALI_ASSERT_DEBUG( mCurrentLongPressEvent );
+
+  LongPressGestureDetector* longPressDetector ( static_cast< LongPressGestureDetector* >( detector ) );
+
+  return ( longPressDetector->GetMinimumTouchesRequired() <= mCurrentLongPressEvent->numberOfTouches ) &&
+         ( longPressDetector->GetMaximumTouchesRequired() >= mCurrentLongPressEvent->numberOfTouches );
+}
+
+void LongPressGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+{
+  DALI_ASSERT_DEBUG( mCurrentLongPressEvent );
+
+  mCurrentEmitters.clear();
+  ResetActor();
+
+  EmitLongPressSignal( actor, gestureDetectors, *mCurrentLongPressEvent, actorCoordinates );
+
+  if ( actor->OnStage() )
+  {
+    mCurrentEmitters = gestureDetectors;
+    SetActor( actor );
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali
index 0deb871..5e0627f 100644 (file)
@@ -115,6 +115,16 @@ private:
    */
   void OnGesturedActorStageDisconnection();
 
+  /**
+   * @copydoc GestureProcessor::CheckGestureDetector()
+   */
+  bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
+
+  /**
+   * @copydoc GestureProcessor::EmitGestureSignal()
+   */
+  void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
+
 private:
 
   Stage& mStage;
@@ -127,7 +137,7 @@ private:
   unsigned int mMinTouchesRequired;
   unsigned int mMaxTouchesRequired;
 
-  struct LongPressEventFunctor;
+  const Integration::LongPressGestureEvent* mCurrentLongPressEvent; ///< Pointer to current longPressEvent, used when calling ProcessAndEmit()
 };
 
 } // namespace Internal
index 3f52e19..134212a 100644 (file)
@@ -101,115 +101,6 @@ struct IsNotAttachedAndOutsideTouchesRangeFunctor
 
 } // unnamed namespace
 
-struct PanGestureProcessor::PanEventFunctor : public GestureProcessor::Functor
-{
-  /**
-   * Constructor
-   * @param[in]  panEvent   The current gesture event.
-   * @param[in]  processor  Reference to the processor.
-   */
-  PanEventFunctor( const Integration::PanGestureEvent& panEvent, PanGestureProcessor& processor )
-  : panEvent( panEvent ),
-    processor( processor )
-  {
-  }
-
-  /**
-   * Check if the detector meets the current gesture event parameters.
-   */
-  virtual bool operator() ( GestureDetector* detector, Actor* actor )
-  {
-    bool retVal( false );
-
-    PanGestureDetector* panDetector( static_cast< PanGestureDetector* >( detector ) );
-
-    if ( ( panEvent.numberOfTouches >= panDetector->GetMinimumTouchesRequired() ) &&
-         ( panEvent.numberOfTouches <= panDetector->GetMaximumTouchesRequired() ) )
-    {
-      // Check if the detector requires directional panning.
-      if ( panDetector->RequiresDirectionalPan() && processor.mCurrentRenderTask )
-      {
-        // It does, calculate the angle of the pan in local actor coordinates and ensures it fits
-        // the detector's criteria.
-        RenderTask& renderTaskImpl( GetImplementation( processor.mCurrentRenderTask ) );
-
-        Vector2 startPosition, currentPosition;
-        actor->ScreenToLocal( renderTaskImpl, startPosition.x,   startPosition.y,   processor.mPossiblePanPosition.x, processor.mPossiblePanPosition.y );
-        actor->ScreenToLocal( renderTaskImpl, currentPosition.x, currentPosition.y, panEvent.currentPosition.x,       panEvent.currentPosition.y );
-        Vector2 displacement( currentPosition - startPosition );
-
-        Radian angle( atan( displacement.y / displacement.x ) );
-
-        /////////////////////////////
-        //            |            //
-        //            |            //
-        //   Q3 (-,-) | Q4 (+,-)   //
-        //            |            //
-        //    ----------------- +x //
-        //            |            //
-        //   Q2 (-,+) | Q1 (+,+)   //
-        //            |            //
-        //            |            //
-        //           +y            //
-        /////////////////////////////
-        // Quadrant 1: As is
-        // Quadrant 2: 180 degrees + angle
-        // Quadrant 3: angle - 180 degrees
-        // Quadrant 4: As is
-        /////////////////////////////
-
-        if ( displacement.x < 0.0f )
-        {
-          if ( displacement.y >= 0.0f )
-          {
-            // Quadrant 2
-            angle += Math::PI;
-          }
-          else
-          {
-            // Quadrant 3
-            angle -= Math::PI;
-          }
-        }
-
-        if ( panDetector->CheckAngleAllowed( angle ) )
-        {
-          retVal = true;
-        }
-      }
-      else
-      {
-        // Directional panning not required so we can use this actor and gesture detector.
-        retVal = true;
-      }
-    }
-
-    return retVal;
-  }
-
-  /**
-   * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
-   */
-  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
-  {
-    processor.mCurrentPanEmitters.clear();
-    processor.ResetActor();
-
-    actor->ScreenToLocal( GetImplementation(processor.mCurrentRenderTask), actorCoordinates.x, actorCoordinates.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
-
-    processor.EmitPanSignal( actor, gestureDetectors, panEvent, actorCoordinates, panEvent.state, processor.mCurrentRenderTask );
-
-    if ( actor->OnStage() )
-    {
-      processor.mCurrentPanEmitters = gestureDetectors;
-      processor.SetActor( actor );
-    }
-  }
-
-  const Integration::PanGestureEvent& panEvent;
-  PanGestureProcessor& processor;
-};
-
 PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager )
 : GestureProcessor( Gesture::Pan ),
   mStage( stage ),
@@ -220,6 +111,7 @@ PanGestureProcessor::PanGestureProcessor( Stage& stage, Integration::GestureMana
   mPossiblePanPosition(),
   mMinTouchesRequired( 1 ),
   mMaxTouchesRequired( 1 ),
+  mCurrentPanEvent( NULL ),
   mSceneObject( SceneGraph::PanGesture::New() ) // Create scene object to store pan information.
 {
   // Pass ownership to scene-graph
@@ -269,8 +161,10 @@ void PanGestureProcessor::Process( const Integration::PanGestureEvent& panEvent
           // Record the current render-task for Screen->Actor coordinate conversions
           mCurrentRenderTask = hitTestResults.renderTask;
 
-          PanEventFunctor functor( panEvent, *this );
-          ProcessAndEmit( hitTestResults, functor );
+          // Set mCurrentPanEvent to use inside overridden methods called in ProcessAndEmit()
+          mCurrentPanEvent = &panEvent;
+          ProcessAndEmit( hitTestResults );
+          mCurrentPanEvent = NULL;
         }
         else
         {
@@ -545,6 +439,94 @@ void PanGestureProcessor::OnGesturedActorStageDisconnection()
   mCurrentPanEmitters.clear();
 }
 
+bool PanGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor )
+{
+  DALI_ASSERT_DEBUG( mCurrentPanEvent );
+
+  bool retVal( false );
+  PanGestureDetector* panDetector( static_cast< PanGestureDetector* >( detector ) );
+
+  if ( ( mCurrentPanEvent->numberOfTouches >= panDetector->GetMinimumTouchesRequired() ) &&
+       ( mCurrentPanEvent->numberOfTouches <= panDetector->GetMaximumTouchesRequired() ) )
+  {
+    // Check if the detector requires directional panning.
+    if ( panDetector->RequiresDirectionalPan() && mCurrentRenderTask )
+    {
+      // It does, calculate the angle of the pan in local actor coordinates and ensures it fits
+      // the detector's criteria.
+      RenderTask& renderTaskImpl( GetImplementation( mCurrentRenderTask ) );
+
+      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 ) );
+
+      /////////////////////////////
+      //            |            //
+      //            |            //
+      //   Q3 (-,-) | Q4 (+,-)   //
+      //            |            //
+      //    ----------------- +x //
+      //            |            //
+      //   Q2 (-,+) | Q1 (+,+)   //
+      //            |            //
+      //            |            //
+      //           +y            //
+      /////////////////////////////
+      // Quadrant 1: As is
+      // Quadrant 2: 180 degrees + angle
+      // Quadrant 3: angle - 180 degrees
+      // Quadrant 4: As is
+      /////////////////////////////
+
+      if ( displacement.x < 0.0f )
+      {
+        if ( displacement.y >= 0.0f )
+        {
+          // Quadrant 2
+          angle += Math::PI;
+        }
+        else
+        {
+          // Quadrant 3
+          angle -= Math::PI;
+        }
+      }
+
+      if ( panDetector->CheckAngleAllowed( angle ) )
+      {
+        retVal = true;
+      }
+    }
+    else
+    {
+      // Directional panning not required so we can use this actor and gesture detector.
+      retVal = true;
+    }
+  }
+  return retVal;
+}
+
+void PanGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+{
+  DALI_ASSERT_DEBUG ( mCurrentPanEvent );
+
+  mCurrentPanEmitters.clear();
+  ResetActor();
+
+  actor->ScreenToLocal( GetImplementation(mCurrentRenderTask), actorCoordinates.x, actorCoordinates.y, mCurrentPanEvent->currentPosition.x, mCurrentPanEvent->currentPosition.y );
+
+  EmitPanSignal( actor, gestureDetectors, *mCurrentPanEvent, actorCoordinates, mCurrentPanEvent->state, mCurrentRenderTask );
+
+  if ( actor->OnStage() )
+  {
+    mCurrentPanEmitters = gestureDetectors;
+    SetActor( actor );
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali
index f93ff03..290e9a2 100644 (file)
@@ -168,6 +168,16 @@ private:
    */
   void OnGesturedActorStageDisconnection();
 
+  /**
+   * @copydoc GestureProcessor::CheckGestureDetector()
+   */
+  bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
+
+  /**
+   * @copydoc GestureProcessor::EmitGestureSignal()
+   */
+  void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
+
 private:
 
   Stage& mStage;
@@ -183,8 +193,7 @@ private:
   Vector2 mLastVelocity;       ///< The last recorded velocity in local actor coordinates.
   Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
 
-  struct PanEventFunctor;
-
+  const Integration::PanGestureEvent* mCurrentPanEvent; ///< Pointer to current PanEvent, used when calling ProcessAndEmit()
   SceneGraph::PanGesture* mSceneObject; ///< Not owned, but we write to it directly
 };
 
index 79e2d6c..bec5c1e 100644 (file)
@@ -100,51 +100,13 @@ struct IsNotAttachedFunctor
 
 } // unnamed namespace
 
-struct PinchGestureProcessor::PinchEventFunctor : public GestureProcessor::Functor
-{
-  /**
-   * Constructor
-   * @param[in]  pinchEvent  The current gesture event.
-   * @param[in]  processor   Reference to the processor.
-   */
-  PinchEventFunctor( const Integration::PinchGestureEvent& pinchEvent, PinchGestureProcessor& processor )
-  : pinchEvent( pinchEvent ),
-    processor( processor )
-  {
-  }
-
-  /**
-   * Check if the detector meets the current gesture event parameters.
-   */
-  virtual bool operator() ( GestureDetector*, Actor* )
-  {
-    return true;
-  }
-
-  /**
-   * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
-   */
-  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
-  {
-    EmitPinchSignal( actor, gestureDetectors, pinchEvent, actorCoordinates );
-
-    if ( actor->OnStage() )
-    {
-      processor.mCurrentPinchEmitters = gestureDetectors;
-      processor.SetActor( actor );
-    }
-  }
-
-  const Integration::PinchGestureEvent& pinchEvent;
-  PinchGestureProcessor& processor;
-};
-
 PinchGestureProcessor::PinchGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager )
 : GestureProcessor( Gesture::Pinch ),
   mStage(stage),
   mGestureManager(gestureManager),
   mGestureDetectors(),
-  mCurrentPinchEmitters()
+  mCurrentPinchEmitters(),
+  mCurrentPinchEvent(NULL)
 {
 }
 
@@ -170,8 +132,10 @@ void PinchGestureProcessor::Process( const Integration::PinchGestureEvent& pinch
         // Record the current render-task for Screen->Actor coordinate conversions
         mCurrentRenderTask = hitTestResults.renderTask;
 
-        PinchEventFunctor functor( pinchEvent, *this ); // Sets mCurrentGesturedActor
-        ProcessAndEmit( hitTestResults, functor );
+        // Set mCurrentPanEvent to use inside overridden methods called from ProcessAndEmit()
+        mCurrentPinchEvent = &pinchEvent;
+        ProcessAndEmit( hitTestResults );
+        mCurrentPinchEvent = NULL;
       }
       break;
     }
@@ -284,6 +248,25 @@ void PinchGestureProcessor::OnGesturedActorStageDisconnection()
   mCurrentPinchEmitters.clear();
 }
 
+bool PinchGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor )
+{
+  // No special case required for pinch.
+  return true;
+}
+
+void PinchGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+{
+  DALI_ASSERT_DEBUG( mCurrentPinchEvent );
+
+  EmitPinchSignal( actor, gestureDetectors, *mCurrentPinchEvent, actorCoordinates );
+
+  if ( actor->OnStage() )
+  {
+    mCurrentPinchEmitters = gestureDetectors;
+    SetActor( actor );
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali
index 01a387c..68a98a4 100644 (file)
@@ -110,6 +110,16 @@ private:
    */
   void OnGesturedActorStageDisconnection();
 
+  /**
+   * @copydoc GestureProcessor::CheckGestureDetector()
+   */
+  bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
+
+  /**
+   * @copydoc GestureProcessor::EmitGestureSignal()
+   */
+  void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
+
 private:
 
   Stage& mStage;
@@ -118,7 +128,7 @@ private:
   GestureDetectorContainer mCurrentPinchEmitters;
   Dali::RenderTask mCurrentRenderTask;
 
-  struct PinchEventFunctor;
+  const Integration::PinchGestureEvent* mCurrentPinchEvent; ///< Pointer to current PinchEvent, used when calling ProcessAndEmit()
 };
 
 } // namespace Internal
index 1c3aa58..0845511 100644 (file)
@@ -72,39 +72,6 @@ void EmitTapSignal(
 
 } // unnamed namespace
 
-struct TapGestureProcessor::TapEventFunctor : public GestureProcessor::Functor
-{
-  /**
-   * Constructor
-   * @param[in]  tapEvent   The current gesture event.
-   */
-  TapEventFunctor( const Integration::TapGestureEvent& tapEvent )
-  : tapEvent(tapEvent)
-  {
-  }
-
-  /**
-   * Check if the detector meets the current gesture event parameters.
-   */
-   virtual bool operator() ( GestureDetector* detector, Actor* )
-  {
-    TapGestureDetector* tapDetector ( static_cast< TapGestureDetector* >( detector ) );
-
-    return tapDetector->GetTapsRequired() == tapEvent.numberOfTaps &&
-           tapDetector->GetTouchesRequired() == tapEvent.numberOfTouches;
-  }
-
-  /**
-   * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
-   */
-  virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
-  {
-    EmitTapSignal( actor, gestureDetectors, tapEvent, actorCoordinates );
-  }
-
-  const Integration::TapGestureEvent& tapEvent;
-};
-
 TapGestureProcessor::TapGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager)
 : GestureProcessor( Gesture::Tap ),
   mStage( stage ),
@@ -113,7 +80,8 @@ TapGestureProcessor::TapGestureProcessor( Stage& stage, Integration::GestureMana
   mMinTapsRequired( 1 ),
   mMaxTapsRequired( 1 ),
   mMinTouchesRequired( 1 ),
-  mMaxTouchesRequired( 1 )
+  mMaxTouchesRequired( 1 ),
+  mCurrentTapEvent( NULL )
 {
 }
 
@@ -147,8 +115,10 @@ void TapGestureProcessor::Process( const Integration::TapGestureEvent& tapEvent
 
         if ( hitTestResults.actor && ( GetCurrentGesturedActor() == &GetImplementation( hitTestResults.actor ) ) )
         {
-          TapEventFunctor functor( tapEvent );
-          ProcessAndEmit( hitTestResults, functor );
+          // Set mCurrentTapEvent to use inside overridden methods called from ProcessAndEmit()
+          mCurrentTapEvent = &tapEvent;
+          ProcessAndEmit( hitTestResults );
+          mCurrentTapEvent = NULL;
         }
 
         ResetActor();
@@ -285,6 +255,23 @@ void TapGestureProcessor::UpdateDetection()
   }
 }
 
+bool TapGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor )
+{
+  DALI_ASSERT_DEBUG( mCurrentTapEvent );
+
+  TapGestureDetector* tapDetector ( static_cast< TapGestureDetector* >( detector ) );
+
+  return ( tapDetector->GetTapsRequired() == mCurrentTapEvent->numberOfTaps ) &&
+         ( tapDetector->GetTouchesRequired() == mCurrentTapEvent->numberOfTouches );
+}
+
+void TapGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+{
+  DALI_ASSERT_DEBUG( mCurrentTapEvent );
+
+  EmitTapSignal( actor, gestureDetectors, *mCurrentTapEvent, actorCoordinates );
+}
+
 } // namespace Internal
 
 } // namespace Dali
index 69400ad..a83b6ea 100644 (file)
@@ -115,6 +115,16 @@ private:
    */
   void OnGesturedActorStageDisconnection() { /* Nothing to do */ }
 
+  /**
+   * @copydoc GestureProcessor::CheckGestureDetector()
+   */
+  bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
+
+  /**
+   * @copydoc GestureProcessor::EmitGestureSignal()
+   */
+  void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
+
 private:
 
   Stage& mStage;
@@ -126,7 +136,7 @@ private:
   unsigned int mMinTouchesRequired;
   unsigned int mMaxTouchesRequired;
 
-  struct TapEventFunctor;
+  const Integration::TapGestureEvent* mCurrentTapEvent; ///< Pointer to current TapEvent, used when calling ProcessAndEmit()
 };
 
 } // namespace Internal