2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/events/gesture-event-processor.h>
21 #if defined(DEBUG_ENABLED)
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>
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)
50 GestureEventProcessor::~GestureEventProcessor() = default;
52 void GestureEventProcessor::ProcessTouchEvent(Scene& scene, const Integration::TouchEvent& event)
54 if(!mIsProcessingFeedTouch)
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);
62 mIsProcessingFeedTouch = false;
65 void GestureEventProcessor::ProcessTouchEvent(GestureDetector* gestureDetector, Actor& actor, Dali::Internal::RenderTask& renderTask, Scene& scene, const Integration::TouchEvent& event)
67 mIsProcessingFeedTouch = true;
68 switch(gestureDetector->GetType())
70 case GestureType::LONG_PRESS:
72 mLongPressGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
76 case GestureType::PAN:
78 mPanGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
82 case GestureType::PINCH:
84 mPinchGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
88 case GestureType::TAP:
90 mTapGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
94 case GestureType::ROTATION:
96 mRotationGestureProcessor.ProcessTouch(gestureDetector, actor, renderTask, scene, event);
102 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
104 switch(gestureDetector->GetType())
106 case GestureType::LONG_PRESS:
108 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
109 mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
113 case GestureType::PAN:
115 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
116 mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
120 case GestureType::PINCH:
122 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
123 mPinchGestureProcessor.AddGestureDetector(pinch, scene);
127 case GestureType::TAP:
129 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
130 mTapGestureProcessor.AddGestureDetector(tap, scene);
134 case GestureType::ROTATION:
136 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
137 mRotationGestureProcessor.AddGestureDetector(rotation, scene);
143 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
145 switch(gestureDetector->GetType())
147 case GestureType::LONG_PRESS:
149 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
150 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
154 case GestureType::PAN:
156 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
157 mPanGestureProcessor.RemoveGestureDetector(pan);
161 case GestureType::PINCH:
163 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
164 mPinchGestureProcessor.RemoveGestureDetector(pinch);
168 case GestureType::TAP:
170 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
171 mTapGestureProcessor.RemoveGestureDetector(tap);
175 case GestureType::ROTATION:
177 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
178 mRotationGestureProcessor.RemoveGestureDetector(rotation);
184 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
186 switch(gestureDetector->GetType())
188 case GestureType::LONG_PRESS:
190 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
191 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
195 case GestureType::PAN:
197 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
198 mPanGestureProcessor.GestureDetectorUpdated(pan);
202 case GestureType::PINCH:
204 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
205 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
209 case GestureType::TAP:
211 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
212 mTapGestureProcessor.GestureDetectorUpdated(tap);
216 case GestureType::ROTATION:
224 void GestureEventProcessor::SetGestureProperties(const Dali::Gesture& gesture)
226 DALI_ASSERT_DEBUG(gesture.GetType() == GestureType::PAN && "Only PanGesture has a scene object\n");
228 const Dali::PanGesture& pan = static_cast<const Dali::PanGesture&>(gesture);
229 if(mPanGestureProcessor.SetPanGestureProperties(pan))
231 // We may not be updating so we need to ask the render controller for an update.
232 mRenderController.RequestUpdate();
236 bool GestureEventProcessor::NeedsUpdate()
238 bool updateRequired = false;
240 updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
241 updateRequired |= mPanGestureProcessor.NeedsUpdate();
242 updateRequired |= mPinchGestureProcessor.NeedsUpdate();
243 updateRequired |= mTapGestureProcessor.NeedsUpdate();
244 updateRequired |= mRotationGestureProcessor.NeedsUpdate();
246 return updateRequired;
249 void GestureEventProcessor::EnablePanGestureProfiling()
251 mPanGestureProcessor.EnableProfiling();
254 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
256 mPanGestureProcessor.SetPredictionMode(mode);
259 void GestureEventProcessor::SetPanGesturePredictionAmount(uint32_t amount)
261 mPanGestureProcessor.SetPredictionAmount(amount);
264 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount(uint32_t amount)
266 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
269 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount(uint32_t amount)
271 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
274 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment(uint32_t amount)
276 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
279 void GestureEventProcessor::SetPanGestureSmoothingMode(int32_t mode)
281 mPanGestureProcessor.SetSmoothingMode(mode);
284 void GestureEventProcessor::SetPanGestureSmoothingAmount(float amount)
286 mPanGestureProcessor.SetSmoothingAmount(amount);
289 void GestureEventProcessor::SetPanGestureUseActualTimes(bool value)
291 mPanGestureProcessor.SetUseActualTimes(value);
294 void GestureEventProcessor::SetPanGestureInterpolationTimeRange(int32_t value)
296 mPanGestureProcessor.SetInterpolationTimeRange(value);
299 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled(bool value)
301 mPanGestureProcessor.SetScalarOnlyPredictionEnabled(value);
304 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled(bool value)
306 mPanGestureProcessor.SetTwoPointPredictionEnabled(value);
309 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime(int value)
311 mPanGestureProcessor.SetTwoPointInterpolatePastTime(value);
314 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias(float value)
316 mPanGestureProcessor.SetTwoPointVelocityBias(value);
319 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias(float value)
321 mPanGestureProcessor.SetTwoPointAccelerationBias(value);
324 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange(int32_t value)
326 mPanGestureProcessor.SetMultitapSmoothingRange(value);
329 void GestureEventProcessor::SetPanGestureMinimumDistance(int32_t value)
331 envOptionMinimumPanDistance = value;
332 mPanGestureProcessor.SetMinimumDistance(value);
335 void GestureEventProcessor::SetPanGestureMinimumPanEvents(int32_t value)
337 envOptionMinimumPanEvents = value;
338 mPanGestureProcessor.SetMinimumPanEvents(value);
341 void GestureEventProcessor::SetPinchGestureMinimumDistance(float value)
343 mPinchGestureProcessor.SetMinimumPinchDistance(value);
346 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents(uint32_t value)
348 mPinchGestureProcessor.SetMinimumTouchEvents(value);
351 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart(uint32_t value)
353 mPinchGestureProcessor.SetMinimumTouchEventsAfterStart(value);
356 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents(uint32_t value)
358 mRotationGestureProcessor.SetMinimumTouchEvents(value);
361 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart(uint32_t value)
363 mRotationGestureProcessor.SetMinimumTouchEventsAfterStart(value);
366 void GestureEventProcessor::SetLongPressMinimumHoldingTime(uint32_t value)
368 mLongPressGestureProcessor.SetMinimumHoldingTime(value);
371 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
373 return mLongPressGestureProcessor.GetMinimumHoldingTime();
376 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
378 return mPanGestureProcessor;
381 void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time)
383 mTapGestureProcessor.SetMaximumAllowedTime(time);
386 void GestureEventProcessor::SetTapRecognizerTime(uint32_t time)
388 mTapGestureProcessor.SetRecognizerTime(time);
391 void GestureEventProcessor::SetTapMaximumMotionAllowedDistance(float distance)
393 mTapGestureProcessor.SetMaximumMotionAllowedDistance(distance);
396 const TapGestureProcessor& GestureEventProcessor::GetTapGestureProcessor()
398 return mTapGestureProcessor;
401 } // namespace Internal