Updated all code to new format
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-processor.h
1 #ifndef DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/events/actor-observer.h>
23 #include <dali/internal/event/events/gesture-processor.h>
24 #include <dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class Scene;
31 class Stage;
32 class Actor;
33
34 struct GestureEvent;
35 struct TapGestureEvent;
36
37 /**
38  * Tap Gesture Event Processing:
39  *
40  * When we receive a tap gesture event, we do the following:
41  * - Find the actor that requires a tap where the tap occurred.
42  * - Emit the gesture if the tap gesture event satisfies the detector conditions.
43  */
44 class TapGestureProcessor : public GestureProcessor, public RecognizerObserver<TapGestureEvent>
45 {
46 public:
47   /**
48    * Create a tap gesture processor.
49    */
50   TapGestureProcessor();
51
52   /**
53    * Non-virtual destructor; TapGestureProcessor is not a base class
54    */
55   ~TapGestureProcessor() override;
56
57 public: // To be called by GestureEventProcessor
58   /**
59    * This method is called whenever a tap gesture event occurs.
60    * @param[in] scene The scene the tap gesture event occurs in.
61    * @param[in] tapEvent The event that has occurred.
62    */
63   void Process(Scene& scene, const TapGestureEvent& event) override;
64
65   /**
66    * Adds a gesture detector to this gesture processor.
67    * If this is the first gesture detector being added, then this method registers the required
68    * gesture with the adaptor.
69    * @param[in]  gestureDetector  The gesture detector being added.
70    */
71   void AddGestureDetector(TapGestureDetector* gestureDetector, Scene& scene);
72
73   /**
74    * Removes the specified gesture detector from this gesture processor.  If, after removing this
75    * gesture detector, there are no more gesture detectors registered, then this method unregisters
76    * the gesture from the adaptor.
77    * @param[in]  gestureDetector  The gesture detector being removed.
78    */
79   void RemoveGestureDetector(TapGestureDetector* gestureDetector);
80
81   /**
82    * This method updates the gesture detection parameters.
83    * @param[in]  gestureDetector  The gesture detector that has been updated.
84    */
85   void GestureDetectorUpdated(TapGestureDetector* gestureDetector);
86
87 private:
88   // Undefined
89   TapGestureProcessor(const TapGestureProcessor&);
90   TapGestureProcessor& operator=(const TapGestureProcessor& rhs);
91
92 private:
93   /**
94    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
95    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
96    */
97   void UpdateDetection();
98
99   // GestureProcessor overrides
100
101   /**
102    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
103    */
104   void OnGesturedActorStageDisconnection() override
105   { /* Nothing to do */
106   }
107
108   /**
109    * @copydoc GestureProcessor::CheckGestureDetector()
110    */
111   bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
112
113   /**
114    * @copydoc GestureProcessor::EmitGestureSignal()
115    */
116   void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
117
118 private:
119   TapGestureDetectorContainer mTapGestureDetectors;
120
121   unsigned int mMinTapsRequired;
122   unsigned int mMaxTapsRequired;
123   unsigned int mMinTouchesRequired;
124   unsigned int mMaxTouchesRequired;
125
126   ActorObserver          mCurrentTapActor;   ///< Observer for the current gesture actor
127   const TapGestureEvent* mCurrentTapEvent;   ///< Pointer to current TapEvent, used when calling ProcessAndEmit()
128   bool                   mPossibleProcessed; ///< Indication of whether we've processed a touch down for this gestuee
129 };
130
131 } // namespace Internal
132
133 } // namespace Dali
134
135 #endif // DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H