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));
80 DALI_ASSERT_ALWAYS( false && "Invalid gesture type sent from Integration\n" );
85 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector)
87 switch (gestureDetector->GetType())
89 case Gesture::LongPress:
91 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
92 mLongPressGestureProcessor.AddGestureDetector(longPress);
98 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
99 mPanGestureProcessor.AddGestureDetector(pan);
105 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
106 mPinchGestureProcessor.AddGestureDetector(pinch);
112 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
113 mTapGestureProcessor.AddGestureDetector(tap);
118 DALI_ASSERT_DEBUG( false && "Invalid gesture detector type created\n" );
123 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
125 switch (gestureDetector->GetType())
127 case Gesture::LongPress:
129 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
130 mLongPressGestureProcessor.RemoveGestureDetector(longPress);
136 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
137 mPanGestureProcessor.RemoveGestureDetector(pan);
143 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
144 mPinchGestureProcessor.RemoveGestureDetector(pinch);
150 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
151 mTapGestureProcessor.RemoveGestureDetector(tap);
156 DALI_ASSERT_DEBUG( false && "Invalid gesture detector type removal request\n" );
161 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
163 switch (gestureDetector->GetType())
165 case Gesture::LongPress:
167 LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
168 mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
174 PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
175 mPanGestureProcessor.GestureDetectorUpdated(pan);
181 PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
182 mPinchGestureProcessor.GestureDetectorUpdated(pinch);
188 TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
189 mTapGestureProcessor.GestureDetectorUpdated(tap);
194 DALI_ASSERT_DEBUG( false && "Invalid gesture type update request\n" );
199 void GestureEventProcessor::SetUpdateRequired()
201 mUpdateRequired = true;
204 void GestureEventProcessor::SetGestureProperties( const Gesture& gesture )
206 if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state )
210 // We may not be updating so we need to ask the render controller for an update.
211 mRenderController.RequestUpdate();
214 switch ( gesture.type )
218 const PanGesture& pan = static_cast< const PanGesture& >( gesture );
219 mPanGestureProcessor.SetPanGestureProperties( pan );
223 case Gesture::LongPress:
227 DALI_ASSERT_DEBUG( false && "Gesture type does not have scene object\n" );
233 bool GestureEventProcessor::NeedsUpdate()
235 bool updateRequired( mUpdateRequired );
237 mUpdateRequired = false;
239 return updateRequired;
242 void GestureEventProcessor::EnablePanGestureProfiling()
244 mPanGestureProcessor.EnableProfiling();
247 } // namespace Internal