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/public-api/events/pan-gesture.h>
38 GestureEventProcessor::GestureEventProcessor(Stage& stage, Integration::GestureManager& gestureManager, Integration::RenderController& renderController)
40 mGestureManager(gestureManager),
41 mLongPressGestureProcessor(stage, gestureManager),
42 mPanGestureProcessor(stage, gestureManager),
43 mPinchGestureProcessor(stage, gestureManager),
44 mTapGestureProcessor(stage, gestureManager),
45 mRenderController(renderController),
46 mUpdateRequired( false )
50 GestureEventProcessor::~GestureEventProcessor()
54 void GestureEventProcessor::ProcessGestureEvent(const Integration::GestureEvent& event)
56 if( Gesture::Started == event.state || Gesture::Continuing == event.state )
61 switch(event.gestureType)
63 case Gesture::LongPress:
64 mLongPressGestureProcessor.Process(static_cast<const Integration::LongPressGestureEvent&>(event));
68 mPanGestureProcessor.Process(static_cast<const Integration::PanGestureEvent&>(event));
72 mPinchGestureProcessor.Process(static_cast<const Integration::PinchGestureEvent&>(event));
76 mTapGestureProcessor.Process(static_cast<const Integration::TapGestureEvent&>(event));
81 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
83 switch (gestureDetector->GetType())
85 case Gesture::LongPress:
87 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
88 mLongPressGestureProcessor.AddGestureDetector(longPress);
94 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
95 mPanGestureProcessor.AddGestureDetector(pan);
101 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
102 mPinchGestureProcessor.AddGestureDetector(pinch);
108 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
109 mTapGestureProcessor.AddGestureDetector(tap);
115 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
117 switch (gestureDetector->GetType())
119 case Gesture::LongPress:
121 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
122 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
128 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
129 mPanGestureProcessor.RemoveGestureDetector(pan);
135 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
136 mPinchGestureProcessor.RemoveGestureDetector(pinch);
142 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
143 mTapGestureProcessor.RemoveGestureDetector(tap);
149 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
151 switch (gestureDetector->GetType())
153 case Gesture::LongPress:
155 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
156 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
162 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
163 mPanGestureProcessor.GestureDetectorUpdated(pan);
169 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
170 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
176 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
177 mTapGestureProcessor.GestureDetectorUpdated(tap);
183 void GestureEventProcessor::SetUpdateRequired()
185 mUpdateRequired = true;
188 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
190 if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
194 // We may not be updating so we need to ask the render controller for an update.
195 mRenderController.RequestUpdate();
198 switch ( gesture.type )
202 const PanGesture& pan = static_cast< const PanGesture& >( gesture );
203 mPanGestureProcessor.SetPanGestureProperties( pan );
207 case Gesture::LongPress:
211 DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
217 bool GestureEventProcessor::NeedsUpdate()
219 bool updateRequired( mUpdateRequired );
221 mUpdateRequired = false;
223 return updateRequired;
226 void GestureEventProcessor::EnablePanGestureProfiling()
228 mPanGestureProcessor.EnableProfiling();
231 } // namespace Internal