[dali_2.3.30] Merge branch 'devel/master'
[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) 2023 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   /**
88    * @brief This method sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond)
89    *
90    * @param[in] time The time value in milliseconds
91    */
92   void SetMaximumAllowedTime(uint32_t time);
93
94   /**
95    * @brief This method gets the maximum allowed time (millisecond)
96    *
97    * @return The time value in milliseconds
98    */
99   uint32_t GetMaximumAllowedTime() const;
100
101   /**
102    * @brief This method sets the recognizer time required to be recognized as a tap gesture (millisecond)
103    *
104    * This time is from touch down to touch up to recognize the tap gesture.
105    *
106    * @param[in] time The time value in milliseconds
107    */
108   void SetRecognizerTime(uint32_t time);
109
110   /**
111    * @brief This method gets the recognizer time required to be recognized as a tap gesture (millisecond)
112    *
113    * @return The time value in milliseconds
114    */
115   uint32_t GetRecognizerTime() const;
116
117   /**
118    * @brief This method sets the recognizer distance required to be recognized as a tap gesture
119    *
120    * This distance is from touch down to touch up to recognize the tap gesture.
121    *
122    * @param[in] distance The distance
123    */
124   void SetMaximumMotionAllowedDistance(float distance);
125
126   /**
127    * @brief This method gets the recognizer distance required to be recognized as a tap gesture
128    *
129    * @return The distance value
130    */
131   float GetMaximumMotionAllowedDistance() const;
132
133 private:
134   // Undefined
135   TapGestureProcessor(const TapGestureProcessor&);
136   TapGestureProcessor& operator=(const TapGestureProcessor& rhs);
137
138 private:
139   /**
140    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
141    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
142    */
143   void UpdateDetection();
144
145   // GestureProcessor overrides
146
147   /**
148    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
149    */
150   void OnGesturedActorStageDisconnection() override
151   { /* Nothing to do */
152   }
153
154   /**
155    * @copydoc GestureProcessor::CheckGestureDetector()
156    */
157   bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
158
159   /**
160    * @copydoc GestureProcessor::EmitGestureSignal()
161    */
162   void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
163
164 private:
165   TapGestureDetectorContainer mTapGestureDetectors;
166
167   uint32_t mMinTouchesRequired;
168   uint32_t mMaxTouchesRequired;
169
170   ActorObserver          mCurrentTapActor;   ///< Observer for the current gesture actor
171   const TapGestureEvent* mCurrentTapEvent;   ///< Pointer to current TapEvent, used when calling ProcessAndEmit()
172   bool                   mPossibleProcessed; ///< Indication of whether we've processed a touch down for this gestuee
173
174   uint32_t mMaximumAllowedTime;              ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond)
175   uint32_t mRecognizerTime;                  ///< The recognizer time required to be recognized as a tap gesture (millisecond)
176   float    mMaximumMotionAllowedDistance;    ///< The recognizer distance required to be recognized as a tap gesture
177 };
178
179 } // namespace Internal
180
181 } // namespace Dali
182
183 #endif // DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H