2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/events/gesture-event-processor.h>
21 #include <dali/integration-api/events/gesture-event.h>
22 #include <dali/integration-api/events/long-press-gesture-event.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali/integration-api/events/pinch-gesture-event.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali/integration-api/gesture-manager.h>
27 #include <dali/integration-api/render-controller.h>
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/event/events/pinch-gesture-detector-impl.h>
30 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
31 #include <dali/public-api/events/pan-gesture.h>
39 GestureEventProcessor::GestureEventProcessor(Stage& stage, Integration::GestureManager& gestureManager, Integration::RenderController& renderController)
41 mGestureManager(gestureManager),
42 mLongPressGestureProcessor(stage, gestureManager),
43 mPanGestureProcessor(stage, gestureManager),
44 mPinchGestureProcessor(stage, gestureManager),
45 mTapGestureProcessor(stage, gestureManager),
46 mRenderController(renderController),
47 mUpdateRequired( false )
51 GestureEventProcessor::~GestureEventProcessor()
55 void GestureEventProcessor::ProcessGestureEvent(const Integration::GestureEvent& event)
57 if( Gesture::Started == event.state || Gesture::Continuing == event.state )
62 switch(event.gestureType)
64 case Gesture::LongPress:
65 mLongPressGestureProcessor.Process(static_cast<const Integration::LongPressGestureEvent&>(event));
69 mPanGestureProcessor.Process(static_cast<const Integration::PanGestureEvent&>(event));
73 mPinchGestureProcessor.Process(static_cast<const Integration::PinchGestureEvent&>(event));
77 mTapGestureProcessor.Process(static_cast<const Integration::TapGestureEvent&>(event));
82 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
84 switch (gestureDetector->GetType())
86 case Gesture::LongPress:
88 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
89 mLongPressGestureProcessor.AddGestureDetector(longPress);
95 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
96 mPanGestureProcessor.AddGestureDetector(pan);
102 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
103 mPinchGestureProcessor.AddGestureDetector(pinch);
109 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
110 mTapGestureProcessor.AddGestureDetector(tap);
116 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
118 switch (gestureDetector->GetType())
120 case Gesture::LongPress:
122 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
123 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
129 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
130 mPanGestureProcessor.RemoveGestureDetector(pan);
136 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
137 mPinchGestureProcessor.RemoveGestureDetector(pinch);
143 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
144 mTapGestureProcessor.RemoveGestureDetector(tap);
150 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
152 switch (gestureDetector->GetType())
154 case Gesture::LongPress:
156 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
157 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
163 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
164 mPanGestureProcessor.GestureDetectorUpdated(pan);
170 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
171 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
177 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
178 mTapGestureProcessor.GestureDetectorUpdated(tap);
184 void GestureEventProcessor::SetUpdateRequired()
186 mUpdateRequired = true;
189 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
191 if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
195 // We may not be updating so we need to ask the render controller for an update.
196 mRenderController.RequestUpdate();
199 switch ( gesture.type )
203 const PanGesture& pan = static_cast< const PanGesture& >( gesture );
204 mPanGestureProcessor.SetPanGestureProperties( pan );
208 case Gesture::LongPress:
212 DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
218 bool GestureEventProcessor::NeedsUpdate()
220 bool updateRequired( mUpdateRequired );
222 mUpdateRequired = false;
224 return updateRequired;
227 void GestureEventProcessor::EnablePanGestureProfiling()
229 mPanGestureProcessor.EnableProfiling();
232 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
234 mPanGestureProcessor.SetPredictionMode(mode);
237 void GestureEventProcessor::SetPanGesturePredictionAmount( float amount )
239 mPanGestureProcessor.SetPredictionAmount(amount);
242 } // namespace Internal