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()
55 void GestureEventProcessor::ProcessTouchEvent( Scene& scene, const Integration::TouchEvent& event)
57 mLongPressGestureProcessor.ProcessTouch(scene, event);
58 mPanGestureProcessor.ProcessTouch(scene, event);
59 mPinchGestureProcessor.ProcessTouch(scene, event);
60 mTapGestureProcessor.ProcessTouch(scene, event);
61 mRotationGestureProcessor.ProcessTouch(scene, event);
64 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
66 switch (gestureDetector->GetType())
68 case GestureType::LONG_PRESS:
70 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
71 mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
75 case GestureType::PAN:
77 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
78 mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
82 case GestureType::PINCH:
84 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
85 mPinchGestureProcessor.AddGestureDetector(pinch, scene);
89 case GestureType::TAP:
91 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
92 mTapGestureProcessor.AddGestureDetector(tap, scene);
96 case GestureType::ROTATION:
98 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
99 mRotationGestureProcessor.AddGestureDetector(rotation, scene);
105 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
107 switch (gestureDetector->GetType())
109 case GestureType::LONG_PRESS:
111 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
112 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
116 case GestureType::PAN:
118 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
119 mPanGestureProcessor.RemoveGestureDetector(pan);
123 case GestureType::PINCH:
125 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
126 mPinchGestureProcessor.RemoveGestureDetector(pinch);
130 case GestureType::TAP:
132 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
133 mTapGestureProcessor.RemoveGestureDetector(tap);
137 case GestureType::ROTATION:
139 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
140 mRotationGestureProcessor.RemoveGestureDetector(rotation);
146 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
148 switch (gestureDetector->GetType())
150 case GestureType::LONG_PRESS:
152 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
153 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
157 case GestureType::PAN:
159 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
160 mPanGestureProcessor.GestureDetectorUpdated(pan);
164 case GestureType::PINCH:
166 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
167 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
171 case GestureType::TAP:
173 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
174 mTapGestureProcessor.GestureDetectorUpdated(tap);
178 case GestureType::ROTATION:
186 void GestureEventProcessor::SetGestureProperties( const Dali::Gesture& gesture )
188 DALI_ASSERT_DEBUG( gesture.GetType() == GestureType::PAN && "Only PanGesture has a scene object\n" );
190 const Dali::PanGesture& pan = static_cast< const Dali::PanGesture& >( gesture );
191 if( mPanGestureProcessor.SetPanGestureProperties( pan ) )
193 // We may not be updating so we need to ask the render controller for an update.
194 mRenderController.RequestUpdate( false );
198 bool GestureEventProcessor::NeedsUpdate()
200 bool updateRequired = false;
202 updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
203 updateRequired |= mPanGestureProcessor.NeedsUpdate();
204 updateRequired |= mPinchGestureProcessor.NeedsUpdate();
205 updateRequired |= mTapGestureProcessor.NeedsUpdate();
206 updateRequired |= mRotationGestureProcessor.NeedsUpdate();
208 return updateRequired;
211 void GestureEventProcessor::EnablePanGestureProfiling()
213 mPanGestureProcessor.EnableProfiling();
216 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
218 mPanGestureProcessor.SetPredictionMode(mode);
221 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
223 mPanGestureProcessor.SetPredictionAmount(amount);
226 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
228 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
231 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
233 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
236 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
238 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
241 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
243 mPanGestureProcessor.SetSmoothingMode(mode);
246 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
248 mPanGestureProcessor.SetSmoothingAmount(amount);
251 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
253 mPanGestureProcessor.SetUseActualTimes( value );
256 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
258 mPanGestureProcessor.SetInterpolationTimeRange( value );
261 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
263 mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
266 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
268 mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
271 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
273 mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
276 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
278 mPanGestureProcessor.SetTwoPointVelocityBias( value );
281 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
283 mPanGestureProcessor.SetTwoPointAccelerationBias( value );
286 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
288 mPanGestureProcessor.SetMultitapSmoothingRange( value );
291 void GestureEventProcessor::SetPanGestureMinimumDistance( int32_t value )
293 envOptionMinimumPanDistance = value;
296 void GestureEventProcessor::SetPanGestureMinimumPanEvents( int32_t value )
298 envOptionMinimumPanEvents = value;
301 void GestureEventProcessor::SetPinchGestureMinimumDistance( float value)
303 mPinchGestureProcessor.SetMinimumPinchDistance( value );
306 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents( uint32_t value )
308 mPinchGestureProcessor.SetMinimumTouchEvents( value );
311 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart( uint32_t value )
313 mPinchGestureProcessor.SetMinimumTouchEventsAfterStart( value );
316 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents( uint32_t value )
318 mRotationGestureProcessor.SetMinimumTouchEvents( value );
321 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart( uint32_t value )
323 mRotationGestureProcessor.SetMinimumTouchEventsAfterStart( value );
326 void GestureEventProcessor::SetLongPressMinimumHoldingTime( uint32_t value )
328 mLongPressGestureProcessor.SetMinimumHoldingTime( value );
331 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
333 return mLongPressGestureProcessor.GetMinimumHoldingTime();
336 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
338 return mPanGestureProcessor;
341 } // namespace Internal