Merge "Add methods to set variables for Pinch and Rotation gesture processing" into...
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.cpp
1 /*
2  * Copyright (c) 2019 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/public-api/events/pan-gesture.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 DevelGesture::LongPress:
69     {
70       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
71       mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
72       break;
73     }
74
75     case DevelGesture::Pan:
76     {
77       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
78       mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
79       break;
80     }
81
82     case DevelGesture::Pinch:
83     {
84       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
85       mPinchGestureProcessor.AddGestureDetector(pinch, scene);
86       break;
87     }
88
89     case DevelGesture::Tap:
90     {
91       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
92       mTapGestureProcessor.AddGestureDetector(tap, scene);
93       break;
94     }
95
96     case DevelGesture::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 DevelGesture::LongPress:
110     {
111       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
112       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
113       break;
114     }
115
116     case DevelGesture::Pan:
117     {
118       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
119       mPanGestureProcessor.RemoveGestureDetector(pan);
120       break;
121     }
122
123     case DevelGesture::Pinch:
124     {
125       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
126       mPinchGestureProcessor.RemoveGestureDetector(pinch);
127       break;
128     }
129
130     case DevelGesture::Tap:
131     {
132       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
133       mTapGestureProcessor.RemoveGestureDetector(tap);
134       break;
135     }
136
137     case DevelGesture::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 DevelGesture::LongPress:
151     {
152       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
153       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
154       break;
155     }
156
157     case DevelGesture::Pan:
158     {
159       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
160       mPanGestureProcessor.GestureDetectorUpdated(pan);
161       break;
162     }
163
164     case DevelGesture::Pinch:
165     {
166       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
167       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
168       break;
169     }
170
171     case DevelGesture::Tap:
172     {
173       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
174       mTapGestureProcessor.GestureDetectorUpdated(tap);
175       break;
176     }
177
178     case DevelGesture::Rotation:
179     {
180       // Nothing to do
181       break;
182     }
183   }
184 }
185
186 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
187 {
188   bool requestUpdate = false;
189
190   switch ( static_cast< DevelGesture::Type >( gesture.type ) )
191   {
192     case DevelGesture::Pan:
193     {
194       const PanGesture& pan = static_cast< const PanGesture& >( gesture );
195       requestUpdate = mPanGestureProcessor.SetPanGestureProperties( pan );
196       break;
197     }
198
199     case DevelGesture::LongPress:
200     case DevelGesture::Pinch:
201     case DevelGesture::Tap:
202     case DevelGesture::Rotation:
203     {
204       DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
205       break;
206     }
207   }
208
209   if( requestUpdate )
210   {
211     // We may not be updating so we need to ask the render controller for an update.
212     mRenderController.RequestUpdate( false );
213   }
214 }
215
216 bool GestureEventProcessor::NeedsUpdate()
217 {
218   bool updateRequired = false;
219
220   updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
221   updateRequired |= mPanGestureProcessor.NeedsUpdate();
222   updateRequired |= mPinchGestureProcessor.NeedsUpdate();
223   updateRequired |= mTapGestureProcessor.NeedsUpdate();
224   updateRequired |= mRotationGestureProcessor.NeedsUpdate();
225
226   return updateRequired;
227 }
228
229 void GestureEventProcessor::EnablePanGestureProfiling()
230 {
231   mPanGestureProcessor.EnableProfiling();
232 }
233
234 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
235 {
236   mPanGestureProcessor.SetPredictionMode(mode);
237 }
238
239 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
240 {
241   mPanGestureProcessor.SetPredictionAmount(amount);
242 }
243
244 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
245 {
246   mPanGestureProcessor.SetMaximumPredictionAmount(amount);
247 }
248
249 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
250 {
251   mPanGestureProcessor.SetMinimumPredictionAmount(amount);
252 }
253
254 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
255 {
256   mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
257 }
258
259 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
260 {
261   mPanGestureProcessor.SetSmoothingMode(mode);
262 }
263
264 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
265 {
266   mPanGestureProcessor.SetSmoothingAmount(amount);
267 }
268
269 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
270 {
271   mPanGestureProcessor.SetUseActualTimes( value );
272 }
273
274 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
275 {
276   mPanGestureProcessor.SetInterpolationTimeRange( value );
277 }
278
279 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
280 {
281   mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
282 }
283
284 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
285 {
286   mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
287 }
288
289 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
290 {
291   mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
292 }
293
294 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
295 {
296   mPanGestureProcessor.SetTwoPointVelocityBias( value );
297 }
298
299 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
300 {
301   mPanGestureProcessor.SetTwoPointAccelerationBias( value );
302 }
303
304 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
305 {
306   mPanGestureProcessor.SetMultitapSmoothingRange( value );
307 }
308
309 void GestureEventProcessor::SetPanGestureMinimumDistance( int32_t value )
310 {
311   envOptionMinimumPanDistance =  value;
312 }
313
314 void GestureEventProcessor::SetPanGestureMinimumPanEvents( int32_t value )
315 {
316   envOptionMinimumPanEvents = value;
317 }
318
319 void GestureEventProcessor::SetPinchGestureMinimumDistance( float value)
320 {
321   mPinchGestureProcessor.SetMinimumPinchDistance( value );
322 }
323
324 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents( uint32_t value )
325 {
326   mPinchGestureProcessor.SetMinimumTouchEvents( value );
327 }
328
329 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart( uint32_t value )
330 {
331   mPinchGestureProcessor.SetMinimumTouchEventsAfterStart( value );
332 }
333
334 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents( uint32_t value )
335 {
336   mRotationGestureProcessor.SetMinimumTouchEvents( value );
337 }
338
339 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart( uint32_t value )
340 {
341   mRotationGestureProcessor.SetMinimumTouchEventsAfterStart( value );
342 }
343
344 void GestureEventProcessor::SetLongPressMinimumHoldingTime( uint32_t value )
345 {
346   mLongPressGestureProcessor.SetMinimumHoldingTime( value );
347 }
348
349 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
350 {
351   return mLongPressGestureProcessor.GetMinimumHoldingTime();
352 }
353
354 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
355 {
356   return mPanGestureProcessor;
357 }
358
359 } // namespace Internal
360
361 } // namespace Dali