2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/events/gesture-event-processor.h>
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>
40 GestureEventProcessor::GestureEventProcessor( Stage& stage, SceneGraph::UpdateManager& updateManager, Integration::GestureManager& gestureManager, Integration::RenderController& renderController )
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 )
52 GestureEventProcessor::~GestureEventProcessor()
56 void GestureEventProcessor::ProcessGestureEvent(const Integration::GestureEvent& event)
58 if( Gesture::Started == event.state || Gesture::Continuing == event.state )
63 switch(event.gestureType)
65 case Gesture::LongPress:
66 mLongPressGestureProcessor.Process(static_cast<const Integration::LongPressGestureEvent&>(event));
70 mPanGestureProcessor.Process(static_cast<const Integration::PanGestureEvent&>(event));
74 mPinchGestureProcessor.Process(static_cast<const Integration::PinchGestureEvent&>(event));
78 mTapGestureProcessor.Process(static_cast<const Integration::TapGestureEvent&>(event));
83 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
85 switch (gestureDetector->GetType())
87 case Gesture::LongPress:
89 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
90 mLongPressGestureProcessor.AddGestureDetector(longPress);
96 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
97 mPanGestureProcessor.AddGestureDetector(pan);
103 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
104 mPinchGestureProcessor.AddGestureDetector(pinch);
110 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
111 mTapGestureProcessor.AddGestureDetector(tap);
117 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
119 switch (gestureDetector->GetType())
121 case Gesture::LongPress:
123 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
124 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
130 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
131 mPanGestureProcessor.RemoveGestureDetector(pan);
137 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
138 mPinchGestureProcessor.RemoveGestureDetector(pinch);
144 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
145 mTapGestureProcessor.RemoveGestureDetector(tap);
151 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
153 switch (gestureDetector->GetType())
155 case Gesture::LongPress:
157 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
158 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
164 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
165 mPanGestureProcessor.GestureDetectorUpdated(pan);
171 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
172 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
178 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
179 mTapGestureProcessor.GestureDetectorUpdated(tap);
185 void GestureEventProcessor::SetUpdateRequired()
187 mUpdateRequired = true;
190 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
192 if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
196 // We may not be updating so we need to ask the render controller for an update.
197 mRenderController.RequestUpdate( false );
200 switch ( gesture.type )
204 const PanGesture& pan = static_cast< const PanGesture& >( gesture );
205 mPanGestureProcessor.SetPanGestureProperties( pan );
209 case Gesture::LongPress:
213 DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
219 bool GestureEventProcessor::NeedsUpdate()
221 bool updateRequired( mUpdateRequired );
223 mUpdateRequired = false;
225 return updateRequired;
228 void GestureEventProcessor::EnablePanGestureProfiling()
230 mPanGestureProcessor.EnableProfiling();
233 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
235 mPanGestureProcessor.SetPredictionMode(mode);
238 void GestureEventProcessor::SetPanGesturePredictionAmount( unsigned int amount )
240 mPanGestureProcessor.SetPredictionAmount(amount);
243 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount( unsigned int amount )
245 mPanGestureProcessor.SetMaximumPredictionAmount(amount);
248 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount( unsigned int amount )
250 mPanGestureProcessor.SetMinimumPredictionAmount(amount);
253 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment( unsigned int amount )
255 mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
258 void GestureEventProcessor::SetPanGestureSmoothingMode(int mode)
260 mPanGestureProcessor.SetSmoothingMode(mode);
263 void GestureEventProcessor::SetPanGestureSmoothingAmount( float amount )
265 mPanGestureProcessor.SetSmoothingAmount(amount);
268 } // namespace Internal