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