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)
49 GestureEventProcessor::~GestureEventProcessor() = default;
51 void GestureEventProcessor::ProcessTouchEvent(Scene& scene, const Integration::TouchEvent& event)
53 mLongPressGestureProcessor.ProcessTouch(scene, event);
54 mPanGestureProcessor.ProcessTouch(scene, event);
55 mPinchGestureProcessor.ProcessTouch(scene, event);
56 mTapGestureProcessor.ProcessTouch(scene, event);
57 mRotationGestureProcessor.ProcessTouch(scene, event);
60 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
62 switch(gestureDetector->GetType())
64 case GestureType::LONG_PRESS:
66 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
67 mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
71 case GestureType::PAN:
73 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
74 mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
78 case GestureType::PINCH:
80 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
81 mPinchGestureProcessor.AddGestureDetector(pinch, scene);
85 case GestureType::TAP:
87 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
88 mTapGestureProcessor.AddGestureDetector(tap, scene);
92 case GestureType::ROTATION:
94 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
95 mRotationGestureProcessor.AddGestureDetector(rotation, scene);
101 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
103 switch(gestureDetector->GetType())
105 case GestureType::LONG_PRESS:
107 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
108 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
112 case GestureType::PAN:
114 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
115 mPanGestureProcessor.RemoveGestureDetector(pan);
119 case GestureType::PINCH:
121 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
122 mPinchGestureProcessor.RemoveGestureDetector(pinch);
126 case GestureType::TAP:
128 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
129 mTapGestureProcessor.RemoveGestureDetector(tap);
133 case GestureType::ROTATION:
135 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
136 mRotationGestureProcessor.RemoveGestureDetector(rotation);
142 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
144 switch(gestureDetector->GetType())
146 case GestureType::LONG_PRESS:
148 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
149 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
153 case GestureType::PAN:
155 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
156 mPanGestureProcessor.GestureDetectorUpdated(pan);
160 case GestureType::PINCH:
162 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
163 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
167 case GestureType::TAP:
169 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
170 mTapGestureProcessor.GestureDetectorUpdated(tap);
174 case GestureType::ROTATION:
182 void GestureEventProcessor::SetGestureProperties(const Dali::Gesture& gesture)
184 DALI_ASSERT_DEBUG(gesture.GetType() == GestureType::PAN && "Only PanGesture has a scene object\n");
186 const Dali::PanGesture& pan = static_cast<const Dali::PanGesture&>(gesture);
187 if(mPanGestureProcessor.SetPanGestureProperties(pan))
189 // We may not be updating so we need to ask the render controller for an update.
190 mRenderController.RequestUpdate();
194 bool GestureEventProcessor::NeedsUpdate()
196 bool updateRequired = false;
198 updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
199 updateRequired |= mPanGestureProcessor.NeedsUpdate();
200 updateRequired |= mPinchGestureProcessor.NeedsUpdate();
201 updateRequired |= mTapGestureProcessor.NeedsUpdate();
202 updateRequired |= mRotationGestureProcessor.NeedsUpdate();
204 return updateRequired;
207 void GestureEventProcessor::EnablePanGestureProfiling()
209 mPanGestureProcessor.EnableProfiling();
212 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
214 mPanGestureProcessor.SetPredictionMode(mode);
217 void GestureEventProcessor::SetPanGesturePredictionAmount(uint32_t amount)
219 mPanGestureProcessor.SetPredictionAmount(amount);
222 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount(uint32_t amount)
224 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
227 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount(uint32_t amount)
229 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
232 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment(uint32_t amount)
234 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
237 void GestureEventProcessor::SetPanGestureSmoothingMode(int32_t mode)
239 mPanGestureProcessor.SetSmoothingMode(mode);
242 void GestureEventProcessor::SetPanGestureSmoothingAmount(float amount)
244 mPanGestureProcessor.SetSmoothingAmount(amount);
247 void GestureEventProcessor::SetPanGestureUseActualTimes(bool value)
249 mPanGestureProcessor.SetUseActualTimes(value);
252 void GestureEventProcessor::SetPanGestureInterpolationTimeRange(int32_t value)
254 mPanGestureProcessor.SetInterpolationTimeRange(value);
257 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled(bool value)
259 mPanGestureProcessor.SetScalarOnlyPredictionEnabled(value);
262 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled(bool value)
264 mPanGestureProcessor.SetTwoPointPredictionEnabled(value);
267 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime(int value)
269 mPanGestureProcessor.SetTwoPointInterpolatePastTime(value);
272 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias(float value)
274 mPanGestureProcessor.SetTwoPointVelocityBias(value);
277 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias(float value)
279 mPanGestureProcessor.SetTwoPointAccelerationBias(value);
282 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange(int32_t value)
284 mPanGestureProcessor.SetMultitapSmoothingRange(value);
287 void GestureEventProcessor::SetPanGestureMinimumDistance(int32_t value)
289 envOptionMinimumPanDistance = value;
292 void GestureEventProcessor::SetPanGestureMinimumPanEvents(int32_t value)
294 envOptionMinimumPanEvents = value;
297 void GestureEventProcessor::SetPinchGestureMinimumDistance(float value)
299 mPinchGestureProcessor.SetMinimumPinchDistance(value);
302 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents(uint32_t value)
304 mPinchGestureProcessor.SetMinimumTouchEvents(value);
307 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart(uint32_t value)
309 mPinchGestureProcessor.SetMinimumTouchEventsAfterStart(value);
312 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents(uint32_t value)
314 mRotationGestureProcessor.SetMinimumTouchEvents(value);
317 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart(uint32_t value)
319 mRotationGestureProcessor.SetMinimumTouchEventsAfterStart(value);
322 void GestureEventProcessor::SetLongPressMinimumHoldingTime(uint32_t value)
324 mLongPressGestureProcessor.SetMinimumHoldingTime(value);
327 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
329 return mLongPressGestureProcessor.GetMinimumHoldingTime();
332 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
334 return mPanGestureProcessor;
337 void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time)
339 mTapGestureProcessor.SetMaximumAllowedTime(time);
342 void GestureEventProcessor::SetTapRecognizerTime(uint32_t time)
344 mTapGestureProcessor.SetRecognizerTime(time);
347 } // namespace Internal