Moved Gesture::State and -::Type to gesture-enumerations.h.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/gesture-event-processor.h>
20
21 #if defined(DEBUG_ENABLED)
22 #include <sstream>
23 #endif
24
25 // INTERNAL INCLUDES
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>
32
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
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)
48 {
49 }
50
51 GestureEventProcessor::~GestureEventProcessor()
52 {
53 }
54
55 void GestureEventProcessor::ProcessTouchEvent( Scene& scene, const Integration::TouchEvent& event)
56 {
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);
62 }
63
64 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
65 {
66   switch (gestureDetector->GetType())
67   {
68     case GestureType::LONG_PRESS:
69     {
70       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
71       mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
72       break;
73     }
74
75     case GestureType::PAN:
76     {
77       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
78       mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
79       break;
80     }
81
82     case GestureType::PINCH:
83     {
84       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
85       mPinchGestureProcessor.AddGestureDetector(pinch, scene);
86       break;
87     }
88
89     case GestureType::TAP:
90     {
91       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
92       mTapGestureProcessor.AddGestureDetector(tap, scene);
93       break;
94     }
95
96     case GestureType::ROTATION:
97     {
98       RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
99       mRotationGestureProcessor.AddGestureDetector(rotation, scene);
100       break;
101     }
102   }
103 }
104
105 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
106 {
107   switch (gestureDetector->GetType())
108   {
109     case GestureType::LONG_PRESS:
110     {
111       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
112       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
113       break;
114     }
115
116     case GestureType::PAN:
117     {
118       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
119       mPanGestureProcessor.RemoveGestureDetector(pan);
120       break;
121     }
122
123     case GestureType::PINCH:
124     {
125       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
126       mPinchGestureProcessor.RemoveGestureDetector(pinch);
127       break;
128     }
129
130     case GestureType::TAP:
131     {
132       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
133       mTapGestureProcessor.RemoveGestureDetector(tap);
134       break;
135     }
136
137     case GestureType::ROTATION:
138     {
139       RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
140       mRotationGestureProcessor.RemoveGestureDetector(rotation);
141       break;
142     }
143   }
144 }
145
146 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
147 {
148   switch (gestureDetector->GetType())
149   {
150     case GestureType::LONG_PRESS:
151     {
152       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
153       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
154       break;
155     }
156
157     case GestureType::PAN:
158     {
159       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
160       mPanGestureProcessor.GestureDetectorUpdated(pan);
161       break;
162     }
163
164     case GestureType::PINCH:
165     {
166       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
167       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
168       break;
169     }
170
171     case GestureType::TAP:
172     {
173       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
174       mTapGestureProcessor.GestureDetectorUpdated(tap);
175       break;
176     }
177
178     case GestureType::ROTATION:
179     {
180       // Nothing to do
181       break;
182     }
183   }
184 }
185
186 void GestureEventProcessor::SetGestureProperties( const Dali::Gesture& gesture )
187 {
188   DALI_ASSERT_DEBUG( gesture.GetType() == GestureType::PAN && "Only PanGesture has a scene object\n" );
189
190   const Dali::PanGesture& pan = static_cast< const Dali::PanGesture& >( gesture );
191   if( mPanGestureProcessor.SetPanGestureProperties( pan ) )
192   {
193     // We may not be updating so we need to ask the render controller for an update.
194     mRenderController.RequestUpdate( false );
195   }
196 }
197
198 bool GestureEventProcessor::NeedsUpdate()
199 {
200   bool updateRequired = false;
201
202   updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
203   updateRequired |= mPanGestureProcessor.NeedsUpdate();
204   updateRequired |= mPinchGestureProcessor.NeedsUpdate();
205   updateRequired |= mTapGestureProcessor.NeedsUpdate();
206   updateRequired |= mRotationGestureProcessor.NeedsUpdate();
207
208   return updateRequired;
209 }
210
211 void GestureEventProcessor::EnablePanGestureProfiling()
212 {
213   mPanGestureProcessor.EnableProfiling();
214 }
215
216 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
217 {
218   mPanGestureProcessor.SetPredictionMode(mode);
219 }
220
221 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
222 {
223   mPanGestureProcessor.SetPredictionAmount(amount);
224 }
225
226 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
227 {
228   mPanGestureProcessor.SetMaximumPredictionAmount(amount);
229 }
230
231 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
232 {
233   mPanGestureProcessor.SetMinimumPredictionAmount(amount);
234 }
235
236 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
237 {
238   mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
239 }
240
241 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
242 {
243   mPanGestureProcessor.SetSmoothingMode(mode);
244 }
245
246 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
247 {
248   mPanGestureProcessor.SetSmoothingAmount(amount);
249 }
250
251 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
252 {
253   mPanGestureProcessor.SetUseActualTimes( value );
254 }
255
256 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
257 {
258   mPanGestureProcessor.SetInterpolationTimeRange( value );
259 }
260
261 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
262 {
263   mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
264 }
265
266 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
267 {
268   mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
269 }
270
271 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
272 {
273   mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
274 }
275
276 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
277 {
278   mPanGestureProcessor.SetTwoPointVelocityBias( value );
279 }
280
281 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
282 {
283   mPanGestureProcessor.SetTwoPointAccelerationBias( value );
284 }
285
286 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
287 {
288   mPanGestureProcessor.SetMultitapSmoothingRange( value );
289 }
290
291 void GestureEventProcessor::SetPanGestureMinimumDistance( int32_t value )
292 {
293   envOptionMinimumPanDistance =  value;
294 }
295
296 void GestureEventProcessor::SetPanGestureMinimumPanEvents( int32_t value )
297 {
298   envOptionMinimumPanEvents = value;
299 }
300
301 void GestureEventProcessor::SetPinchGestureMinimumDistance( float value)
302 {
303   mPinchGestureProcessor.SetMinimumPinchDistance( value );
304 }
305
306 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents( uint32_t value )
307 {
308   mPinchGestureProcessor.SetMinimumTouchEvents( value );
309 }
310
311 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart( uint32_t value )
312 {
313   mPinchGestureProcessor.SetMinimumTouchEventsAfterStart( value );
314 }
315
316 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents( uint32_t value )
317 {
318   mRotationGestureProcessor.SetMinimumTouchEvents( value );
319 }
320
321 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart( uint32_t value )
322 {
323   mRotationGestureProcessor.SetMinimumTouchEventsAfterStart( value );
324 }
325
326 void GestureEventProcessor::SetLongPressMinimumHoldingTime( uint32_t value )
327 {
328   mLongPressGestureProcessor.SetMinimumHoldingTime( value );
329 }
330
331 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
332 {
333   return mLongPressGestureProcessor.GetMinimumHoldingTime();
334 }
335
336 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
337 {
338   return mPanGestureProcessor;
339 }
340
341 } // namespace Internal
342
343 } // namespace Dali