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-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 mRenderController( renderController ),
45 envOptionMinimumPanDistance(-1),
46 envOptionMinimumPanEvents(-1)
50 GestureEventProcessor::~GestureEventProcessor()
54 void GestureEventProcessor::ProcessTouchEvent( Scene& scene, const Integration::TouchEvent& event)
56 mLongPressGestureProcessor.ProcessTouch(scene, event);
57 mPanGestureProcessor.ProcessTouch(scene, event);
58 mPinchGestureProcessor.ProcessTouch(scene, event);
59 mTapGestureProcessor.ProcessTouch(scene, event);
62 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
64 switch (gestureDetector->GetType())
66 case Gesture::LongPress:
68 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
69 mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
75 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
76 mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
82 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
83 mPinchGestureProcessor.AddGestureDetector(pinch, scene);
89 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
90 mTapGestureProcessor.AddGestureDetector(tap, scene);
96 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
98 switch (gestureDetector->GetType())
100 case Gesture::LongPress:
102 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
103 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
109 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
110 mPanGestureProcessor.RemoveGestureDetector(pan);
116 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
117 mPinchGestureProcessor.RemoveGestureDetector(pinch);
123 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
124 mTapGestureProcessor.RemoveGestureDetector(tap);
130 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
132 switch (gestureDetector->GetType())
134 case Gesture::LongPress:
136 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
137 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
143 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
144 mPanGestureProcessor.GestureDetectorUpdated(pan);
150 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
151 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
157 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
158 mTapGestureProcessor.GestureDetectorUpdated(tap);
164 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
166 bool requestUpdate = false;
168 switch ( gesture.type )
172 const PanGesture& pan = static_cast< const PanGesture& >( gesture );
173 requestUpdate = mPanGestureProcessor.SetPanGestureProperties( pan );
177 case Gesture::LongPress:
181 DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
188 // We may not be updating so we need to ask the render controller for an update.
189 mRenderController.RequestUpdate( false );
193 bool GestureEventProcessor::NeedsUpdate()
195 bool updateRequired = false;
197 updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
198 updateRequired |= mPanGestureProcessor.NeedsUpdate();
199 updateRequired |= mPinchGestureProcessor.NeedsUpdate();
200 updateRequired |= mTapGestureProcessor.NeedsUpdate();
202 return updateRequired;
205 void GestureEventProcessor::EnablePanGestureProfiling()
207 mPanGestureProcessor.EnableProfiling();
210 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
212 mPanGestureProcessor.SetPredictionMode(mode);
215 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
217 mPanGestureProcessor.SetPredictionAmount(amount);
220 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
222 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
225 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
227 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
230 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
232 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
235 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
237 mPanGestureProcessor.SetSmoothingMode(mode);
240 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
242 mPanGestureProcessor.SetSmoothingAmount(amount);
245 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
247 mPanGestureProcessor.SetUseActualTimes( value );
250 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
252 mPanGestureProcessor.SetInterpolationTimeRange( value );
255 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
257 mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
260 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
262 mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
265 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
267 mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
270 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
272 mPanGestureProcessor.SetTwoPointVelocityBias( value );
275 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
277 mPanGestureProcessor.SetTwoPointAccelerationBias( value );
280 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
282 mPanGestureProcessor.SetMultitapSmoothingRange( value );
285 void GestureEventProcessor::SetPanGestureMinimumDistance( int32_t value )
287 envOptionMinimumPanDistance = value;
290 void GestureEventProcessor::SetPanGestureMinimumPanEvents( int32_t value )
292 envOptionMinimumPanEvents = value;
295 void GestureEventProcessor::SetPinchGestureMinimumDistance( float value)
297 mPinchGestureProcessor.SetMinimumPinchDistance( value );
300 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
302 return mPanGestureProcessor;
305 } // namespace Internal