2 * Copyright (c) 2018 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>
22 #include <dali/integration-api/events/gesture-event.h>
23 #include <dali/integration-api/events/long-press-gesture-event.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/events/pinch-gesture-event.h>
26 #include <dali/integration-api/events/tap-gesture-event.h>
27 #include <dali/integration-api/gesture-manager.h>
28 #include <dali/integration-api/render-controller.h>
29 #include <dali/internal/event/common/stage-impl.h>
30 #include <dali/internal/event/events/pinch-gesture-detector-impl.h>
31 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
32 #include <dali/public-api/events/pan-gesture.h>
40 GestureEventProcessor::GestureEventProcessor( SceneGraph::UpdateManager& updateManager, Integration::GestureManager& gestureManager, Integration::RenderController& renderController )
41 : mGestureManager( gestureManager ),
42 mLongPressGestureProcessor( gestureManager ),
43 mPanGestureProcessor( gestureManager, updateManager ),
44 mPinchGestureProcessor( gestureManager ),
45 mTapGestureProcessor( gestureManager ),
46 mRenderController( renderController ),
47 mUpdateRequired( false )
51 GestureEventProcessor::~GestureEventProcessor()
55 void GestureEventProcessor::ProcessGestureEvent( Scene& scene, const Integration::GestureEvent& event)
57 if( Gesture::Started == event.state || Gesture::Continuing == event.state )
62 switch(event.gestureType)
64 case Gesture::LongPress:
65 mLongPressGestureProcessor.Process( scene, static_cast<const Integration::LongPressGestureEvent&>(event) );
69 mPanGestureProcessor.Process( scene, static_cast<const Integration::PanGestureEvent&>(event));
73 mPinchGestureProcessor.Process( scene, static_cast<const Integration::PinchGestureEvent&>(event));
77 mTapGestureProcessor.Process( scene, static_cast<const Integration::TapGestureEvent&>(event));
82 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
84 switch (gestureDetector->GetType())
86 case Gesture::LongPress:
88 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
89 mLongPressGestureProcessor.AddGestureDetector(longPress);
95 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
96 mPanGestureProcessor.AddGestureDetector(pan);
102 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
103 mPinchGestureProcessor.AddGestureDetector(pinch);
109 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
110 mTapGestureProcessor.AddGestureDetector(tap);
116 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
118 switch (gestureDetector->GetType())
120 case Gesture::LongPress:
122 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
123 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
129 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
130 mPanGestureProcessor.RemoveGestureDetector(pan);
136 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
137 mPinchGestureProcessor.RemoveGestureDetector(pinch);
143 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
144 mTapGestureProcessor.RemoveGestureDetector(tap);
150 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
152 switch (gestureDetector->GetType())
154 case Gesture::LongPress:
156 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
157 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
163 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
164 mPanGestureProcessor.GestureDetectorUpdated(pan);
170 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
171 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
177 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
178 mTapGestureProcessor.GestureDetectorUpdated(tap);
184 void GestureEventProcessor::SetUpdateRequired()
186 mUpdateRequired = true;
189 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
191 if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
195 // We may not be updating so we need to ask the render controller for an update.
196 mRenderController.RequestUpdate( false );
199 switch ( gesture.type )
203 const PanGesture& pan = static_cast< const PanGesture& >( gesture );
204 mPanGestureProcessor.SetPanGestureProperties( pan );
208 case Gesture::LongPress:
212 DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
218 bool GestureEventProcessor::NeedsUpdate()
220 bool updateRequired( mUpdateRequired );
222 mUpdateRequired = false;
224 return updateRequired;
227 void GestureEventProcessor::EnablePanGestureProfiling()
229 mPanGestureProcessor.EnableProfiling();
232 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
234 mPanGestureProcessor.SetPredictionMode(mode);
237 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
239 mPanGestureProcessor.SetPredictionAmount(amount);
242 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
244 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
247 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
249 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
252 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
254 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
257 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
259 mPanGestureProcessor.SetSmoothingMode(mode);
262 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
264 mPanGestureProcessor.SetSmoothingAmount(amount);
267 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
269 mPanGestureProcessor.SetUseActualTimes( value );
272 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
274 mPanGestureProcessor.SetInterpolationTimeRange( value );
277 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
279 mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
282 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
284 mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
287 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
289 mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
292 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
294 mPanGestureProcessor.SetTwoPointVelocityBias( value );
297 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
299 mPanGestureProcessor.SetTwoPointAccelerationBias( value );
302 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
304 mPanGestureProcessor.SetMultitapSmoothingRange( value );
307 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
309 return mPanGestureProcessor;
312 } // namespace Internal