use modern construct 'override' in the derive class.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-processor.h
index ff6c525..fc05876 100644 (file)
@@ -1,26 +1,28 @@
-#ifndef __DALI_INTERNAL_GESTURE_PROCESSOR_H__
-#define __DALI_INTERNAL_GESTURE_PROCESSOR_H__
-
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+#ifndef DALI_INTERNAL_GESTURE_PROCESSOR_H
+#define DALI_INTERNAL_GESTURE_PROCESSOR_H
+
+/*
+ * Copyright (c) 2020 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // INTERNAL INCLUDES
 #include <dali/internal/event/events/gesture-detector-impl.h>
 #include <dali/internal/event/events/hit-test-algorithm-impl.h>
-#include <dali/internal/event/common/proxy-object.h>
+#include <dali/internal/event/events/gesture-recognizer.h>
+#include <dali/internal/event/common/object-impl.h>
 
 namespace Dali
 {
@@ -33,113 +35,80 @@ namespace Internal
 /**
  * Base class for the different Gesture Processors.
  */
-class GestureProcessor : public ProxyObject::Observer
+class GestureProcessor : public Object::Observer
 {
-protected: // Construction & Destruction
+public:
 
   /**
-   * Protected constructor.  Cannot create an instance of GestureProcessor
+   * Process the touch event in the attached recognizer
+   * @param[in] scene Scene.
+   * @param[in] event Touch event to process
    */
-  GestureProcessor( Gesture::Type type );
+  void ProcessTouch( Scene& scene, const Integration::TouchEvent& event );
 
   /**
-   * Virtual protected destructor.
+   * Returns whether any GestureDetector requires a Core::Update
+   * @return true if update required
    */
-  virtual ~GestureProcessor();
+  inline bool NeedsUpdate()
+  {
+    bool updateRequired = mNeedsUpdate;
+    mNeedsUpdate = false;
+    return updateRequired;
+  }
+
+protected:
 
-  // Templates and types for deriving classes
+  // Construction & Destruction
 
   /**
-   * 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.
+   * Protected constructor.  Cannot create an instance of GestureProcessor
    */
-  template< typename Detector >
-  static void UpCastContainer( const typename DerivedGestureDetectorContainer<Detector>::type& derivedContainer, GestureDetectorContainer& baseContainer )
-  {
-    baseContainer.assign( derivedContainer.begin(), derivedContainer.end() );
-  }
+  GestureProcessor( GestureType::Value type );
 
   /**
-   * 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.
+   * Virtual protected destructor.
    */
-  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 ) );
-    }
-  }
+  ~GestureProcessor() override;
+
+  // Methods to be used by 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() ( Dali::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.
+   *
+   * @note Uses CheckGestureDetector() to check if a the current gesture 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 );
 
   /**
-   * 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.
    *
+   * @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( const HitTestAlgorithm::Results& hitTestResults, const GestureDetectorContainer& connectedDetectors, Functor& functor );
+  void ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults );
 
   /**
    * Hit test the screen coordinates, and place the results in hitTestResults.
-   * @param[in] stage Stage.
+   * @param[in] scene Scene.
    * @param[in] screenCoordinates The screen coordinates to test.
    * @param[out] hitTestResults Structure to write results into.
    * @return false if the system overlay was hit or no actor was hit.
    */
-  virtual bool HitTest(Stage& stage, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
+  virtual bool HitTest( Scene& scene, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
 
   /**
    * 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.
@@ -153,6 +122,8 @@ protected: // Construction & Destruction
    */
   Actor* GetCurrentGesturedActor();
 
+private:
+
   // For derived classes to override
 
   /**
@@ -160,47 +131,66 @@ 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.
-   * @param[in] proxy The proxy object.
-   * @see ProxyObject::Observer::SceneObjectAdded()
+   * @param[in] object The object object.
+   * @see Object::Observer::SceneObjectAdded()
    */
-  virtual void SceneObjectAdded(ProxyObject& proxy) { }
+  void SceneObjectAdded(Object& object) override { }
 
   /**
    * This will be called when the actor is removed from the stage, we should clear and stop
    * observing it.
-   * @param[in] proxy The proxy object.
-   * @see ProxyObject::Observer::SceneObjectRemoved()
+   * @param[in] object The object object.
+   * @see Object::Observer::SceneObjectRemoved()
    */
-  virtual void SceneObjectRemoved(ProxyObject& proxy);
+  void SceneObjectRemoved(Object& object) override;
 
   /**
    * This will be called when the actor is destroyed. We should clear the actor.
    * No need to stop observing as the object is being destroyed anyway.
-   * @see ProxyObject::Observer::ProxyDestroyed()
+   * @see Object::Observer::ObjectDestroyed()
    */
-  virtual void ProxyDestroyed(ProxyObject& proxy);
+  void ObjectDestroyed(Object& object) override;
 
-  // 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 );
+protected:  //Data
+
+  GestureRecognizerPtr mGestureRecognizer;  ///< The gesture recognizer
+  bool   mNeedsUpdate;                 ///< Indicates if any GestureDetector requires a Core::Update
 
 private: // Data
 
-  Gesture::Type mType;                 ///< Type of GestureProcessor
+  GestureType::Value mType;            ///< Type of GestureProcessor
   Actor* mCurrentGesturedActor;        ///< The current actor that has been gestured.
   bool   mGesturedActorDisconnected:1; ///< Indicates whether the gestured actor has been disconnected from the scene
 };
@@ -209,4 +199,4 @@ private: // Data
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_GESTURE_PROCESSOR_H__
+#endif // DALI_INTERNAL_GESTURE_PROCESSOR_H