[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/gesture-event-processor.h>
20
21 #if defined(DEBUG_ENABLED)
22 #include <sstream>
23 #endif
24
25 // INTERNAL INCLUDES
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/render-controller.h>
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/event/events/pan-gesture/pan-gesture-impl.h>
30 #include <dali/internal/event/events/pinch-gesture/pinch-gesture-detector-impl.h>
31 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 GestureEventProcessor::GestureEventProcessor(SceneGraph::UpdateManager& updateManager, Integration::RenderController& renderController)
38 : mLongPressGestureProcessor(),
39   mPanGestureProcessor(updateManager),
40   mPinchGestureProcessor(),
41   mTapGestureProcessor(),
42   mRotationGestureProcessor(),
43   mRenderController(renderController),
44   envOptionMinimumPanDistance(-1),
45   envOptionMinimumPanEvents(-1),
46   mIsProcessingFeedTouch(false)
47 {
48 }
49
50 GestureEventProcessor::~GestureEventProcessor() = default;
51
52 void GestureEventProcessor::ProcessTouchEvent(Scene& scene, const Integration::TouchEvent& event)
53 {
54   if(!mIsProcessingFeedTouch)
55   {
56     mLongPressGestureProcessor.ProcessTouch(scene, event);
57     mPanGestureProcessor.ProcessTouch(scene, event);
58     mPinchGestureProcessor.ProcessTouch(scene, event);
59     mTapGestureProcessor.ProcessTouch(scene, event);
60     mRotationGestureProcessor.ProcessTouch(scene, event);
61   }
62   mIsProcessingFeedTouch = false;
63 }
64
65 void GestureEventProcessor::ProcessTouchEvent(GestureDetector* gestureDetector, Actor& actor, Dali::Internal::RenderTask& renderTask, Scene& scene, const Integration::TouchEvent& event)
66 {
67   mIsProcessingFeedTouch = true;
68   switch(gestureDetector->GetType())
69   {
70     case GestureType::LONG_PRESS:
71     {
72       mLongPressGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
73       break;
74     }
75
76     case GestureType::PAN:
77     {
78       mPanGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
79       break;
80     }
81
82     case GestureType::PINCH:
83     {
84       mPinchGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
85       break;
86     }
87
88     case GestureType::TAP:
89     {
90       mTapGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
91       break;
92     }
93
94     case GestureType::ROTATION:
95     {
96       mRotationGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
97       break;
98     }
99   }
100 }
101
102 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
103 {
104   switch(gestureDetector->GetType())
105   {
106     case GestureType::LONG_PRESS:
107     {
108       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
109       mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
110       break;
111     }
112
113     case GestureType::PAN:
114     {
115       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
116       mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
117       break;
118     }
119
120     case GestureType::PINCH:
121     {
122       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
123       mPinchGestureProcessor.AddGestureDetector(pinch, scene);
124       break;
125     }
126
127     case GestureType::TAP:
128     {
129       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
130       mTapGestureProcessor.AddGestureDetector(tap, scene);
131       break;
132     }
133
134     case GestureType::ROTATION:
135     {
136       RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
137       mRotationGestureProcessor.AddGestureDetector(rotation, scene);
138       break;
139     }
140   }
141 }
142
143 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
144 {
145   switch(gestureDetector->GetType())
146   {
147     case GestureType::LONG_PRESS:
148     {
149       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
150       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
151       break;
152     }
153
154     case GestureType::PAN:
155     {
156       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
157       mPanGestureProcessor.RemoveGestureDetector(pan);
158       break;
159     }
160
161     case GestureType::PINCH:
162     {
163       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
164       mPinchGestureProcessor.RemoveGestureDetector(pinch);
165       break;
166     }
167
168     case GestureType::TAP:
169     {
170       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
171       mTapGestureProcessor.RemoveGestureDetector(tap);
172       break;
173     }
174
175     case GestureType::ROTATION:
176     {
177       RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
178       mRotationGestureProcessor.RemoveGestureDetector(rotation);
179       break;
180     }
181   }
182 }
183
184 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
185 {
186   switch(gestureDetector->GetType())
187   {
188     case GestureType::LONG_PRESS:
189     {
190       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
191       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
192       break;
193     }
194
195     case GestureType::PAN:
196     {
197       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
198       mPanGestureProcessor.GestureDetectorUpdated(pan);
199       break;
200     }
201
202     case GestureType::PINCH:
203     {
204       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
205       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
206       break;
207     }
208
209     case GestureType::TAP:
210     {
211       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
212       mTapGestureProcessor.GestureDetectorUpdated(tap);
213       break;
214     }
215
216     case GestureType::ROTATION:
217     {
218       // Nothing to do
219       break;
220     }
221   }
222 }
223
224 void GestureEventProcessor::SetGestureProperties(const Dali::Gesture& gesture)
225 {
226   DALI_ASSERT_DEBUG(gesture.GetType() == GestureType::PAN && "Only PanGesture has a scene object\n");
227
228   const Dali::PanGesture& pan = static_cast<const Dali::PanGesture&>(gesture);
229   if(mPanGestureProcessor.SetPanGestureProperties(pan))
230   {
231     // We may not be updating so we need to ask the render controller for an update.
232     mRenderController.RequestUpdate();
233   }
234 }
235
236 bool GestureEventProcessor::NeedsUpdate()
237 {
238   bool updateRequired = false;
239
240   updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
241   updateRequired |= mPanGestureProcessor.NeedsUpdate();
242   updateRequired |= mPinchGestureProcessor.NeedsUpdate();
243   updateRequired |= mTapGestureProcessor.NeedsUpdate();
244   updateRequired |= mRotationGestureProcessor.NeedsUpdate();
245
246   return updateRequired;
247 }
248
249 void GestureEventProcessor::EnablePanGestureProfiling()
250 {
251   mPanGestureProcessor.EnableProfiling();
252 }
253
254 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
255 {
256   mPanGestureProcessor.SetPredictionMode(mode);
257 }
258
259 void GestureEventProcessor::SetPanGesturePredictionAmount(uint32_t amount)
260 {
261   mPanGestureProcessor.SetPredictionAmount(amount);
262 }
263
264 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount(uint32_t amount)
265 {
266   mPanGestureProcessor.SetMaximumPredictionAmount(amount);
267 }
268
269 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount(uint32_t amount)
270 {
271   mPanGestureProcessor.SetMinimumPredictionAmount(amount);
272 }
273
274 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment(uint32_t amount)
275 {
276   mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
277 }
278
279 void GestureEventProcessor::SetPanGestureSmoothingMode(int32_t mode)
280 {
281   mPanGestureProcessor.SetSmoothingMode(mode);
282 }
283
284 void GestureEventProcessor::SetPanGestureSmoothingAmount(float amount)
285 {
286   mPanGestureProcessor.SetSmoothingAmount(amount);
287 }
288
289 void GestureEventProcessor::SetPanGestureUseActualTimes(bool value)
290 {
291   mPanGestureProcessor.SetUseActualTimes(value);
292 }
293
294 void GestureEventProcessor::SetPanGestureInterpolationTimeRange(int32_t value)
295 {
296   mPanGestureProcessor.SetInterpolationTimeRange(value);
297 }
298
299 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled(bool value)
300 {
301   mPanGestureProcessor.SetScalarOnlyPredictionEnabled(value);
302 }
303
304 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled(bool value)
305 {
306   mPanGestureProcessor.SetTwoPointPredictionEnabled(value);
307 }
308
309 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime(int value)
310 {
311   mPanGestureProcessor.SetTwoPointInterpolatePastTime(value);
312 }
313
314 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias(float value)
315 {
316   mPanGestureProcessor.SetTwoPointVelocityBias(value);
317 }
318
319 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias(float value)
320 {
321   mPanGestureProcessor.SetTwoPointAccelerationBias(value);
322 }
323
324 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange(int32_t value)
325 {
326   mPanGestureProcessor.SetMultitapSmoothingRange(value);
327 }
328
329 void GestureEventProcessor::SetPanGestureMinimumDistance(int32_t value)
330 {
331   envOptionMinimumPanDistance = value;
332   mPanGestureProcessor.SetMinimumDistance(value);
333 }
334
335 void GestureEventProcessor::SetPanGestureMinimumPanEvents(int32_t value)
336 {
337   envOptionMinimumPanEvents = value;
338   mPanGestureProcessor.SetMinimumPanEvents(value);
339 }
340
341 void GestureEventProcessor::SetPinchGestureMinimumDistance(float value)
342 {
343   mPinchGestureProcessor.SetMinimumPinchDistance(value);
344 }
345
346 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents(uint32_t value)
347 {
348   mPinchGestureProcessor.SetMinimumTouchEvents(value);
349 }
350
351 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart(uint32_t value)
352 {
353   mPinchGestureProcessor.SetMinimumTouchEventsAfterStart(value);
354 }
355
356 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents(uint32_t value)
357 {
358   mRotationGestureProcessor.SetMinimumTouchEvents(value);
359 }
360
361 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart(uint32_t value)
362 {
363   mRotationGestureProcessor.SetMinimumTouchEventsAfterStart(value);
364 }
365
366 void GestureEventProcessor::SetLongPressMinimumHoldingTime(uint32_t value)
367 {
368   mLongPressGestureProcessor.SetMinimumHoldingTime(value);
369 }
370
371 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
372 {
373   return mLongPressGestureProcessor.GetMinimumHoldingTime();
374 }
375
376 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
377 {
378   return mPanGestureProcessor;
379 }
380
381 void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time)
382 {
383   mTapGestureProcessor.SetMaximumAllowedTime(time);
384 }
385
386 void GestureEventProcessor::SetTapRecognizerTime(uint32_t time)
387 {
388   mTapGestureProcessor.SetRecognizerTime(time);
389 }
390
391 void GestureEventProcessor::SetTapMaximumMotionAllowedDistance(float distance)
392 {
393   mTapGestureProcessor.SetMaximumMotionAllowedDistance(distance);
394 }
395
396 const TapGestureProcessor& GestureEventProcessor::GetTapGestureProcessor()
397 {
398   return mTapGestureProcessor;
399 }
400
401 } // namespace Internal
402
403 } // namespace Dali