Change to process events when the application is paused
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.cpp
1 /*
2  * Copyright (c) 2017 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( Stage& stage, SceneGraph::UpdateManager& updateManager, Integration::GestureManager& gestureManager, Integration::RenderController& renderController )
41 : mStage( stage ),
42   mGestureManager( gestureManager ),
43   mLongPressGestureProcessor( stage, gestureManager ),
44   mPanGestureProcessor( stage, gestureManager, updateManager ),
45   mPinchGestureProcessor( stage, gestureManager ),
46   mTapGestureProcessor( stage, gestureManager ),
47   mRenderController( renderController ),
48   mUpdateRequired( false )
49 {
50 }
51
52 GestureEventProcessor::~GestureEventProcessor()
53 {
54 }
55
56 void GestureEventProcessor::ProcessGestureEvent(const Integration::GestureEvent& event)
57 {
58   if( Gesture::Started == event.state || Gesture::Continuing == event.state )
59   {
60     SetUpdateRequired();
61   }
62
63   switch(event.gestureType)
64   {
65     case Gesture::LongPress:
66       mLongPressGestureProcessor.Process(static_cast<const Integration::LongPressGestureEvent&>(event));
67       break;
68
69     case Gesture::Pan:
70       mPanGestureProcessor.Process(static_cast<const Integration::PanGestureEvent&>(event));
71       break;
72
73     case Gesture::Pinch:
74       mPinchGestureProcessor.Process(static_cast<const Integration::PinchGestureEvent&>(event));
75       break;
76
77     case Gesture::Tap:
78       mTapGestureProcessor.Process(static_cast<const Integration::TapGestureEvent&>(event));
79       break;
80   }
81 }
82
83 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
84 {
85   switch (gestureDetector->GetType())
86   {
87     case Gesture::LongPress:
88     {
89       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
90       mLongPressGestureProcessor.AddGestureDetector(longPress);
91       break;
92     }
93
94     case Gesture::Pan:
95     {
96       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
97       mPanGestureProcessor.AddGestureDetector(pan);
98       break;
99     }
100
101     case Gesture::Pinch:
102     {
103       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
104       mPinchGestureProcessor.AddGestureDetector(pinch);
105       break;
106     }
107
108     case Gesture::Tap:
109     {
110       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
111       mTapGestureProcessor.AddGestureDetector(tap);
112       break;
113     }
114   }
115 }
116
117 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
118 {
119   switch (gestureDetector->GetType())
120   {
121     case Gesture::LongPress:
122     {
123       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
124       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
125       break;
126     }
127
128     case Gesture::Pan:
129     {
130       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
131       mPanGestureProcessor.RemoveGestureDetector(pan);
132       break;
133     }
134
135     case Gesture::Pinch:
136     {
137       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
138       mPinchGestureProcessor.RemoveGestureDetector(pinch);
139       break;
140     }
141
142     case Gesture::Tap:
143     {
144       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
145       mTapGestureProcessor.RemoveGestureDetector(tap);
146       break;
147     }
148   }
149 }
150
151 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
152 {
153   switch (gestureDetector->GetType())
154   {
155     case Gesture::LongPress:
156     {
157       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
158       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
159       break;
160     }
161
162     case Gesture::Pan:
163     {
164       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
165       mPanGestureProcessor.GestureDetectorUpdated(pan);
166       break;
167     }
168
169     case Gesture::Pinch:
170     {
171       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
172       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
173       break;
174     }
175
176     case Gesture::Tap:
177     {
178       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
179       mTapGestureProcessor.GestureDetectorUpdated(tap);
180       break;
181     }
182   }
183 }
184
185 void GestureEventProcessor::SetUpdateRequired()
186 {
187   mUpdateRequired = true;
188 }
189
190 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
191 {
192   if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
193   {
194     SetUpdateRequired();
195
196     // We may not be updating so we need to ask the render controller for an update.
197     mRenderController.RequestUpdate( false );
198   }
199
200   switch ( gesture.type )
201   {
202     case Gesture::Pan:
203     {
204       const PanGesture& pan = static_cast< const PanGesture& >( gesture );
205       mPanGestureProcessor.SetPanGestureProperties( pan );
206       break;
207     }
208
209     case Gesture::LongPress:
210     case Gesture::Pinch:
211     case Gesture::Tap:
212     {
213       DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
214       break;
215     }
216   }
217 }
218
219 bool GestureEventProcessor::NeedsUpdate()
220 {
221   bool updateRequired( mUpdateRequired );
222
223   mUpdateRequired = false;
224
225   return updateRequired;
226 }
227
228 void GestureEventProcessor::EnablePanGestureProfiling()
229 {
230   mPanGestureProcessor.EnableProfiling();
231 }
232
233 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
234 {
235   mPanGestureProcessor.SetPredictionMode(mode);
236 }
237
238 void GestureEventProcessor::SetPanGesturePredictionAmount( unsigned int amount )
239 {
240   mPanGestureProcessor.SetPredictionAmount(amount);
241 }
242
243 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( unsigned int amount )
244 {
245   mPanGestureProcessor.SetMaximumPredictionAmount(amount);
246 }
247
248 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( unsigned int amount )
249 {
250   mPanGestureProcessor.SetMinimumPredictionAmount(amount);
251 }
252
253 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( unsigned int amount )
254 {
255   mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
256 }
257
258 void GestureEventProcessor::SetPanGestureSmoothingMode(int mode)
259 {
260   mPanGestureProcessor.SetSmoothingMode(mode);
261 }
262
263 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
264 {
265   mPanGestureProcessor.SetSmoothingAmount(amount);
266 }
267
268 } // namespace Internal
269
270 } // namespace Dali