Add event handling support for multiple windows.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.cpp
1 /*
2  * Copyright (c) 2018 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 // INTERNAL INCLUDES
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>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
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 )
48 {
49 }
50
51 GestureEventProcessor::~GestureEventProcessor()
52 {
53 }
54
55 void GestureEventProcessor::ProcessGestureEvent( Scene& scene, const Integration::GestureEvent& event)
56 {
57   if( Gesture::Started == event.state || Gesture::Continuing == event.state )
58   {
59     SetUpdateRequired();
60   }
61
62   switch(event.gestureType)
63   {
64     case Gesture::LongPress:
65       mLongPressGestureProcessor.Process( scene, static_cast<const Integration::LongPressGestureEvent&>(event) );
66       break;
67
68     case Gesture::Pan:
69       mPanGestureProcessor.Process( scene, static_cast<const Integration::PanGestureEvent&>(event));
70       break;
71
72     case Gesture::Pinch:
73       mPinchGestureProcessor.Process( scene, static_cast<const Integration::PinchGestureEvent&>(event));
74       break;
75
76     case Gesture::Tap:
77       mTapGestureProcessor.Process( scene, static_cast<const Integration::TapGestureEvent&>(event));
78       break;
79   }
80 }
81
82 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
83 {
84   switch (gestureDetector->GetType())
85   {
86     case Gesture::LongPress:
87     {
88       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
89       mLongPressGestureProcessor.AddGestureDetector(longPress);
90       break;
91     }
92
93     case Gesture::Pan:
94     {
95       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
96       mPanGestureProcessor.AddGestureDetector(pan);
97       break;
98     }
99
100     case Gesture::Pinch:
101     {
102       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
103       mPinchGestureProcessor.AddGestureDetector(pinch);
104       break;
105     }
106
107     case Gesture::Tap:
108     {
109       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
110       mTapGestureProcessor.AddGestureDetector(tap);
111       break;
112     }
113   }
114 }
115
116 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
117 {
118   switch (gestureDetector->GetType())
119   {
120     case Gesture::LongPress:
121     {
122       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
123       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
124       break;
125     }
126
127     case Gesture::Pan:
128     {
129       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
130       mPanGestureProcessor.RemoveGestureDetector(pan);
131       break;
132     }
133
134     case Gesture::Pinch:
135     {
136       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
137       mPinchGestureProcessor.RemoveGestureDetector(pinch);
138       break;
139     }
140
141     case Gesture::Tap:
142     {
143       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
144       mTapGestureProcessor.RemoveGestureDetector(tap);
145       break;
146     }
147   }
148 }
149
150 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
151 {
152   switch (gestureDetector->GetType())
153   {
154     case Gesture::LongPress:
155     {
156       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
157       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
158       break;
159     }
160
161     case Gesture::Pan:
162     {
163       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
164       mPanGestureProcessor.GestureDetectorUpdated(pan);
165       break;
166     }
167
168     case Gesture::Pinch:
169     {
170       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
171       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
172       break;
173     }
174
175     case Gesture::Tap:
176     {
177       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
178       mTapGestureProcessor.GestureDetectorUpdated(tap);
179       break;
180     }
181   }
182 }
183
184 void GestureEventProcessor::SetUpdateRequired()
185 {
186   mUpdateRequired = true;
187 }
188
189 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
190 {
191   if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
192   {
193     SetUpdateRequired();
194
195     // We may not be updating so we need to ask the render controller for an update.
196     mRenderController.RequestUpdate( false );
197   }
198
199   switch ( gesture.type )
200   {
201     case Gesture::Pan:
202     {
203       const PanGesture& pan = static_cast< const PanGesture& >( gesture );
204       mPanGestureProcessor.SetPanGestureProperties( pan );
205       break;
206     }
207
208     case Gesture::LongPress:
209     case Gesture::Pinch:
210     case Gesture::Tap:
211     {
212       DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
213       break;
214     }
215   }
216 }
217
218 bool GestureEventProcessor::NeedsUpdate()
219 {
220   bool updateRequired( mUpdateRequired );
221
222   mUpdateRequired = false;
223
224   return updateRequired;
225 }
226
227 void GestureEventProcessor::EnablePanGestureProfiling()
228 {
229   mPanGestureProcessor.EnableProfiling();
230 }
231
232 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
233 {
234   mPanGestureProcessor.SetPredictionMode(mode);
235 }
236
237 void GestureEventProcessor::SetPanGesturePredictionAmount( uint32_t amount )
238 {
239   mPanGestureProcessor.SetPredictionAmount(amount);
240 }
241
242 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( uint32_t amount )
243 {
244   mPanGestureProcessor.SetMaximumPredictionAmount(amount);
245 }
246
247 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( uint32_t amount )
248 {
249   mPanGestureProcessor.SetMinimumPredictionAmount(amount);
250 }
251
252 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( uint32_t amount )
253 {
254   mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
255 }
256
257 void GestureEventProcessor::SetPanGestureSmoothingMode( int32_t mode )
258 {
259   mPanGestureProcessor.SetSmoothingMode(mode);
260 }
261
262 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
263 {
264   mPanGestureProcessor.SetSmoothingAmount(amount);
265 }
266
267 void GestureEventProcessor::SetPanGestureUseActualTimes( bool value )
268 {
269   mPanGestureProcessor.SetUseActualTimes( value );
270 }
271
272 void GestureEventProcessor::SetPanGestureInterpolationTimeRange( int32_t value )
273 {
274   mPanGestureProcessor.SetInterpolationTimeRange( value );
275 }
276
277 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled( bool value )
278 {
279   mPanGestureProcessor.SetScalarOnlyPredictionEnabled( value );
280 }
281
282 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled( bool value )
283 {
284   mPanGestureProcessor.SetTwoPointPredictionEnabled( value );
285 }
286
287 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime( int value )
288 {
289   mPanGestureProcessor.SetTwoPointInterpolatePastTime( value );
290 }
291
292 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias( float value )
293 {
294   mPanGestureProcessor.SetTwoPointVelocityBias( value );
295 }
296
297 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias( float value )
298 {
299   mPanGestureProcessor.SetTwoPointAccelerationBias( value );
300 }
301
302 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange( int32_t value )
303 {
304   mPanGestureProcessor.SetMultitapSmoothingRange( value );
305 }
306
307 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
308 {
309   return mPanGestureProcessor;
310 }
311
312 } // namespace Internal
313
314 } // namespace Dali