2 * Copyright (c) 2020 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/render-controller.h>
27 #include <dali/internal/event/common/stage-impl.h>
28 #include <dali/internal/event/events/pinch-gesture/pinch-gesture-detector-impl.h>
29 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
30 #include <dali/internal/event/events/pan-gesture/pan-gesture-impl.h>
31 #include <dali/integration-api/debug.h>
39 GestureEventProcessor::GestureEventProcessor( SceneGraph::UpdateManager& updateManager, Integration::RenderController& renderController )
40 : mLongPressGestureProcessor(),
41 mPanGestureProcessor( updateManager ),
42 mPinchGestureProcessor(),
43 mTapGestureProcessor(),
44 mRotationGestureProcessor(),
45 mRenderController( renderController ),
46 envOptionMinimumPanDistance(-1),
47 envOptionMinimumPanEvents(-1)
51 GestureEventProcessor::~GestureEventProcessor() = default;
53 void GestureEventProcessor::ProcessTouchEvent( Scene& scene, const Integration::TouchEvent& event)
55 mLongPressGestureProcessor.ProcessTouch(scene, event);
56 mPanGestureProcessor.ProcessTouch(scene, event);
57 mPinchGestureProcessor.ProcessTouch(scene, event);
58 mTapGestureProcessor.ProcessTouch(scene, event);
59 mRotationGestureProcessor.ProcessTouch(scene, event);
62 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
64 switch (gestureDetector->GetType())
66 case GestureType::LONG_PRESS:
68 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
69 mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
73 case GestureType::PAN:
75 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
76 mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
80 case GestureType::PINCH:
82 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
83 mPinchGestureProcessor.AddGestureDetector(pinch, scene);
87 case GestureType::TAP:
89 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
90 mTapGestureProcessor.AddGestureDetector(tap, scene);
94 case GestureType::ROTATION:
96 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
97 mRotationGestureProcessor.AddGestureDetector(rotation, scene);
103 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
105 switch (gestureDetector->GetType())
107 case GestureType::LONG_PRESS:
109 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
110 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
114 case GestureType::PAN:
116 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
117 mPanGestureProcessor.RemoveGestureDetector(pan);
121 case GestureType::PINCH:
123 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
124 mPinchGestureProcessor.RemoveGestureDetector(pinch);
128 case GestureType::TAP:
130 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
131 mTapGestureProcessor.RemoveGestureDetector(tap);
135 case GestureType::ROTATION:
137 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
138 mRotationGestureProcessor.RemoveGestureDetector(rotation);
144 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
146 switch (gestureDetector->GetType())
148 case GestureType::LONG_PRESS:
150 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
151 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
155 case GestureType::PAN:
157 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
158 mPanGestureProcessor.GestureDetectorUpdated(pan);
162 case GestureType::PINCH:
164 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
165 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
169 case GestureType::TAP:
171 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
172 mTapGestureProcessor.GestureDetectorUpdated(tap);
176 case GestureType::ROTATION:
184 void GestureEventProcessor::SetGestureProperties( const Dali::Gesture& gesture )
186 DALI_ASSERT_DEBUG( gesture.GetType() == GestureType::PAN && "Only PanGesture has a scene object\n" );
188 const Dali::PanGesture& pan = static_cast< const Dali::PanGesture& >( gesture );
189 if( mPanGestureProcessor.SetPanGestureProperties( pan ) )
191 // We may not be updating so we need to ask the render controller for an update.
192 mRenderController.RequestUpdate( false );
196 bool GestureEventProcessor::NeedsUpdate()
198 bool updateRequired = false;
200 updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
201 updateRequired |= mPanGestureProcessor.NeedsUpdate();
202 updateRequired |= mPinchGestureProcessor.NeedsUpdate();
203 updateRequired |= mTapGestureProcessor.NeedsUpdate();
204 updateRequired |= mRotationGestureProcessor.NeedsUpdate();
206 return updateRequired;
209 void GestureEventProcessor::EnablePanGestureProfiling()
211 mPanGestureProcessor.EnableProfiling();
214 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
216 mPanGestureProcessor.SetPredictionMode(mode);
219 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
221 mPanGestureProcessor.SetPredictionAmount(amount);
224 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
226 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
229 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
231 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
234 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
236 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
239 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
241 mPanGestureProcessor.SetSmoothingMode(mode);
244 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
246 mPanGestureProcessor.SetSmoothingAmount(amount);
249 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
251 mPanGestureProcessor.SetUseActualTimes( value );
254 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
256 mPanGestureProcessor.SetInterpolationTimeRange( value );
259 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
261 mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
264 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
266 mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
269 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
271 mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
274 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
276 mPanGestureProcessor.SetTwoPointVelocityBias( value );
279 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
281 mPanGestureProcessor.SetTwoPointAccelerationBias( value );
284 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
286 mPanGestureProcessor.SetMultitapSmoothingRange( value );
289 void GestureEventProcessor::SetPanGestureMinimumDistance( int32_t value )
291 envOptionMinimumPanDistance = value;
294 void GestureEventProcessor::SetPanGestureMinimumPanEvents( int32_t value )
296 envOptionMinimumPanEvents = value;
299 void GestureEventProcessor::SetPinchGestureMinimumDistance( float value)
301 mPinchGestureProcessor.SetMinimumPinchDistance( value );
304 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents( uint32_t value )
306 mPinchGestureProcessor.SetMinimumTouchEvents( value );
309 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart( uint32_t value )
311 mPinchGestureProcessor.SetMinimumTouchEventsAfterStart( value );
314 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents( uint32_t value )
316 mRotationGestureProcessor.SetMinimumTouchEvents( value );
319 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart( uint32_t value )
321 mRotationGestureProcessor.SetMinimumTouchEventsAfterStart( value );
324 void GestureEventProcessor::SetLongPressMinimumHoldingTime( uint32_t value )
326 mLongPressGestureProcessor.SetMinimumHoldingTime( value );
329 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
331 return mLongPressGestureProcessor.GetMinimumHoldingTime();
334 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
336 return mPanGestureProcessor;
339 } // namespace Internal