2 * Copyright (c) 2019 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/public-api/events/pan-gesture.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 DevelGesture::LongPress:
70 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
71 mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
75 case DevelGesture::Pan:
77 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
78 mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
82 case DevelGesture::Pinch:
84 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
85 mPinchGestureProcessor.AddGestureDetector(pinch, scene);
89 case DevelGesture::Tap:
91 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
92 mTapGestureProcessor.AddGestureDetector(tap, scene);
96 case DevelGesture::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 DevelGesture::LongPress:
111 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
112 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
116 case DevelGesture::Pan:
118 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
119 mPanGestureProcessor.RemoveGestureDetector(pan);
123 case DevelGesture::Pinch:
125 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
126 mPinchGestureProcessor.RemoveGestureDetector(pinch);
130 case DevelGesture::Tap:
132 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
133 mTapGestureProcessor.RemoveGestureDetector(tap);
137 case DevelGesture::Rotation:
139 RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
140 mRotationGestureProcessor.RemoveGestureDetector(rotation);
146 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
148 switch (gestureDetector->GetType())
150 case DevelGesture::LongPress:
152 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
153 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
157 case DevelGesture::Pan:
159 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
160 mPanGestureProcessor.GestureDetectorUpdated(pan);
164 case DevelGesture::Pinch:
166 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
167 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
171 case DevelGesture::Tap:
173 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
174 mTapGestureProcessor.GestureDetectorUpdated(tap);
178 case DevelGesture::Rotation:
186 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
188 bool requestUpdate = false;
190 switch ( static_cast< DevelGesture::Type >( gesture.type ) )
192 case DevelGesture::Pan:
194 const PanGesture& pan = static_cast< const PanGesture& >( gesture );
195 requestUpdate = mPanGestureProcessor.SetPanGestureProperties( pan );
199 case DevelGesture::LongPress:
200 case DevelGesture::Pinch:
201 case DevelGesture::Tap:
202 case DevelGesture::Rotation:
204 DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
211 // We may not be updating so we need to ask the render controller for an update.
212 mRenderController.RequestUpdate( false );
216 bool GestureEventProcessor::NeedsUpdate()
218 bool updateRequired = false;
220 updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
221 updateRequired |= mPanGestureProcessor.NeedsUpdate();
222 updateRequired |= mPinchGestureProcessor.NeedsUpdate();
223 updateRequired |= mTapGestureProcessor.NeedsUpdate();
224 updateRequired |= mRotationGestureProcessor.NeedsUpdate();
226 return updateRequired;
229 void GestureEventProcessor::EnablePanGestureProfiling()
231 mPanGestureProcessor.EnableProfiling();
234 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
236 mPanGestureProcessor.SetPredictionMode(mode);
239 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
241 mPanGestureProcessor.SetPredictionAmount(amount);
244 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
246 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
249 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
251 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
254 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
256 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
259 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
261 mPanGestureProcessor.SetSmoothingMode(mode);
264 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
266 mPanGestureProcessor.SetSmoothingAmount(amount);
269 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
271 mPanGestureProcessor.SetUseActualTimes( value );
274 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
276 mPanGestureProcessor.SetInterpolationTimeRange( value );
279 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
281 mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
284 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
286 mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
289 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
291 mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
294 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
296 mPanGestureProcessor.SetTwoPointVelocityBias( value );
299 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
301 mPanGestureProcessor.SetTwoPointAccelerationBias( value );
304 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
306 mPanGestureProcessor.SetMultitapSmoothingRange( value );
309 void GestureEventProcessor::SetPanGestureMinimumDistance( int32_t value )
311 envOptionMinimumPanDistance = value;
314 void GestureEventProcessor::SetPanGestureMinimumPanEvents( int32_t value )
316 envOptionMinimumPanEvents = value;
319 void GestureEventProcessor::SetPinchGestureMinimumDistance( float value)
321 mPinchGestureProcessor.SetMinimumPinchDistance( value );
324 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents( uint32_t value )
326 mPinchGestureProcessor.SetMinimumTouchEvents( value );
329 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart( uint32_t value )
331 mPinchGestureProcessor.SetMinimumTouchEventsAfterStart( value );
334 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents( uint32_t value )
336 mRotationGestureProcessor.SetMinimumTouchEvents( value );
339 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart( uint32_t value )
341 mRotationGestureProcessor.SetMinimumTouchEventsAfterStart( value );
344 void GestureEventProcessor::SetLongPressMinimumHoldingTime( uint32_t value )
346 mLongPressGestureProcessor.SetMinimumHoldingTime( value );
349 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
351 return mLongPressGestureProcessor.GetMinimumHoldingTime();
354 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
356 return mPanGestureProcessor;
359 } // namespace Internal