8b7a3c65e53d34e5896efe4fe498386e1b2c77e1
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture / pan-gesture-processor.cpp
1 /*
2  * Copyright (c) 2020 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/pan-gesture/pan-gesture-processor.h>
20
21 #if defined(DEBUG_ENABLED)
22 #include <sstream>
23 #endif
24
25 // EXTERNAL INCLUDES
26 #include <algorithm>
27
28 // INTERNAL INCLUDES
29 #include <dali/public-api/actors/actor.h>
30 #include <dali/public-api/common/dali-common.h>
31 #include <dali/public-api/events/pan-gesture.h>
32 #include <dali/public-api/math/vector2.h>
33 #include <dali/internal/event/events/pan-gesture/pan-gesture-event.h>
34 #include <dali/integration-api/debug.h>
35 #include <dali/internal/event/common/scene-impl.h>
36 #include <dali/internal/event/render-tasks/render-task-impl.h>
37 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
38 #include <dali/internal/event/events/multi-point-event-util.h>
39 #include <dali/internal/event/events/pan-gesture/pan-gesture-recognizer.h>
40 #include <dali/internal/event/events/pan-gesture/pan-gesture-impl.h>
41 #include <dali/internal/event/events/gesture-requests.h>
42
43 namespace Dali
44 {
45
46 namespace Internal
47 {
48
49 namespace // unnamed namespace
50 {
51
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_PAN_PROCESSOR" );
54
55 const char * GESTURE_STATES[ 6 ] =
56 {
57   "Clear",
58   "Started",
59   "Continuing",
60   "Finished",
61   "Cancelled",
62   "Possible"
63 };
64
65 #endif // defined(DEBUG_ENABLED)
66
67 const unsigned long MAXIMUM_TIME_WITH_VALID_LAST_VELOCITY( 50u );
68
69 /**
70  * Functor which checks whether the specified actor is attached to the gesture detector.
71  * If the actor is attached, it also checks whether the number of touches of the current pan event
72  * are within the range of that expected by the detector.
73  * It returns true if it is no longer attached or the touches are out of range.
74  * This can be used in remove_if functions.
75  */
76 struct IsNotAttachedAndOutsideTouchesRangeFunctor
77 {
78   /**
79    * Constructor
80    * @param[in]  actor                 The actor to check whether it is attached.
81    * @param[in]  touches               The number of touches in the current pan event.
82    * @param[in]  outsideRangeEmitters  Reference to container where emitters outside of the touches range should be added.
83    */
84   IsNotAttachedAndOutsideTouchesRangeFunctor(Actor* actor, unsigned int touches, GestureDetectorContainer& outsideRangeEmitters)
85   : actorToCheck(actor),
86     numberOfTouches(touches),
87     outsideTouchesRangeEmitters(outsideRangeEmitters)
88   {
89   }
90
91   /**
92    * Returns true if not attached, false if it is still attached.
93    * Additionally, checks if the number of touches has changed and stops sending the pan to a particular
94    * detector if it exceeds the range of that detector.
95    * @param[in]  detector  The detector to check.
96    * @return true, if not attached, false otherwise.
97    */
98   bool operator()(GestureDetector* detector) const
99   {
100     bool remove(!detector->IsAttached(*actorToCheck));
101
102     if (!remove)
103     {
104       PanGestureDetector* panDetector( static_cast< PanGestureDetector* >( detector ) );
105
106       // Ensure number of touch points is within the range of our emitter. If it isn't then remove
107       // this emitter and add it to the outsideTouchesRangeEmitters container
108       if ( (numberOfTouches < panDetector->GetMinimumTouchesRequired()) ||
109            (numberOfTouches > panDetector->GetMaximumTouchesRequired()) )
110       {
111         remove = true;
112         outsideTouchesRangeEmitters.push_back(detector);
113       }
114     }
115
116     return remove;
117   }
118
119   Actor* actorToCheck; ///< The actor to check whether it is attached or not.
120   unsigned int numberOfTouches; ///< The number of touches in the pan event.
121   GestureDetectorContainer& outsideTouchesRangeEmitters; ///< Emitters that are outside of the range of current pan.
122 };
123
124 } // unnamed namespace
125
126 PanGestureProcessor::PanGestureProcessor( SceneGraph::UpdateManager& updateManager )
127 : GestureProcessor( Dali::Gesture::Pan ),
128   mPanGestureDetectors(),
129   mCurrentPanEmitters(),
130   mCurrentRenderTask(),
131   mPossiblePanPosition(),
132   mMinTouchesRequired( 1 ),
133   mMaxTouchesRequired( 1 ),
134   mCurrentPanEvent( nullptr ),
135   mSceneObject( SceneGraph::PanGesture::New() ) // Create scene object to store pan information.
136 {
137   // Pass ownership to scene-graph; scene object lives for the lifecycle of UpdateManager
138   updateManager.SetPanGestureProcessor( mSceneObject );
139 }
140
141 PanGestureProcessor::~PanGestureProcessor()
142 {
143   mSceneObject = nullptr; // mSceneObject is owned and destroyed by update manager (there is only one of these for now)
144 }
145
146 void PanGestureProcessor::Process( Scene& scene, const PanGestureEvent& panEvent )
147 {
148 #if defined(DEBUG_ENABLED)
149   DALI_LOG_TRACE_METHOD( gLogFilter );
150
151   DALI_LOG_INFO( gLogFilter, Debug::General, "    Pan Event\n");
152   DALI_LOG_INFO( gLogFilter, Debug::General, "      State: %s  Touches: %d  Time: %d  TimeDelta: %d\n",
153                                              GESTURE_STATES[panEvent.state], panEvent.numberOfTouches, panEvent.time, panEvent.timeDelta);
154   DALI_LOG_INFO( gLogFilter, Debug::General, "      Positions: Current: (%.0f, %.0f), Previous: (%.0f, %.0f)\n",
155                                              panEvent.currentPosition.x, panEvent.currentPosition.y, panEvent.previousPosition.x, panEvent.previousPosition.y);
156 #endif
157
158   switch( panEvent.state )
159   {
160     case Dali::Gesture::Possible:
161     {
162       mCurrentPanEmitters.clear();
163       ResetActor();
164
165       HitTestAlgorithm::Results hitTestResults;
166       if( HitTest( scene, panEvent.currentPosition, hitTestResults ) )
167       {
168         SetActor( &GetImplementation( hitTestResults.actor ) );
169         mPossiblePanPosition = panEvent.currentPosition;
170       }
171       break;
172     }
173
174     case Dali::Gesture::Started:
175     {
176       // Requires a core update
177       mNeedsUpdate = true;
178
179       // The pan gesture should only be sent to the gesture detector which first received it so that
180       // it can be told when the gesture ends as well.
181
182       HitTestAlgorithm::Results hitTestResults;
183       HitTest( scene, panEvent.previousPosition, hitTestResults ); // Hit Test previous position
184
185       if ( hitTestResults.actor )
186       {
187         // If the current hit actor is different from the one we touched down on then set accordingly & update initial pan position
188         if( &GetImplementation( hitTestResults.actor ) != GetCurrentGesturedActor() )
189         {
190           mPossiblePanPosition = panEvent.previousPosition;
191           SetActor( &GetImplementation( hitTestResults.actor ) );
192         }
193
194         // Record the current render-task for Screen->Actor coordinate conversions
195         mCurrentRenderTask = hitTestResults.renderTask;
196
197         // Set mCurrentPanEvent to use inside overridden methods called in ProcessAndEmit()
198         mCurrentPanEvent = &panEvent;
199         ProcessAndEmit( hitTestResults );
200         mCurrentPanEvent = nullptr;
201       }
202       else
203       {
204         ResetActor();
205         mCurrentPanEmitters.clear();
206       }
207       break;
208     }
209
210     case Dali::Gesture::Continuing:
211     {
212       // Requires a core update
213       mNeedsUpdate = true;
214
215       DALI_FALLTHROUGH;
216     }
217
218     case Dali::Gesture::Finished:
219     case Dali::Gesture::Cancelled:
220     {
221       // Only send subsequent pan gesture signals if we processed the pan gesture when it started.
222       // Check if actor is still touchable.
223
224       Actor* currentGesturedActor = GetCurrentGesturedActor();
225       if ( currentGesturedActor )
226       {
227         if ( currentGesturedActor->IsHittable() && !mCurrentPanEmitters.empty() && mCurrentRenderTask )
228         {
229           GestureDetectorContainer outsideTouchesRangeEmitters;
230
231           // Removes emitters that no longer have the actor attached
232           // Also remove emitters whose touches are outside the range of the current pan event and add them to outsideTouchesRangeEmitters
233           GestureDetectorContainer::iterator endIter = std::remove_if( mCurrentPanEmitters.begin(), mCurrentPanEmitters.end(),
234                                                                        IsNotAttachedAndOutsideTouchesRangeFunctor(currentGesturedActor, panEvent.numberOfTouches, outsideTouchesRangeEmitters) );
235           mCurrentPanEmitters.erase( endIter, mCurrentPanEmitters.end() );
236
237           Vector2 actorCoords;
238
239           if ( !outsideTouchesRangeEmitters.empty() || !mCurrentPanEmitters.empty() )
240           {
241             currentGesturedActor->ScreenToLocal( *mCurrentRenderTask.Get(), actorCoords.x, actorCoords.y, panEvent.currentPosition.x, panEvent.currentPosition.y );
242
243             // EmitPanSignal checks whether we have a valid actor and whether the container we are passing in has emitters before it emits the pan.
244             EmitPanSignal( currentGesturedActor, outsideTouchesRangeEmitters, panEvent, actorCoords, Dali::Gesture::Finished, mCurrentRenderTask);
245             EmitPanSignal( currentGesturedActor, mCurrentPanEmitters, panEvent, actorCoords, panEvent.state, mCurrentRenderTask);
246           }
247
248           if ( mCurrentPanEmitters.empty() )
249           {
250             // If we have no emitters attached then clear pan actor as well.
251             ResetActor();
252           }
253
254           // Clear current gesture detectors if pan gesture has ended or been cancelled.
255           if ( ( panEvent.state == Dali::Gesture::Finished ) || ( panEvent.state == Dali::Gesture::Cancelled ) )
256           {
257             mCurrentPanEmitters.clear();
258             ResetActor();
259           }
260         }
261         else
262         {
263           mCurrentPanEmitters.clear();
264           ResetActor();
265         }
266       }
267       break;
268     }
269
270     case Dali::Gesture::Clear:
271     {
272       DALI_ABORT( "Incorrect state received from Integration layer: Clear\n" );
273       break;
274     }
275   }
276 }
277
278 void PanGestureProcessor::AddGestureDetector( PanGestureDetector* gestureDetector, Scene& scene, int32_t minDistance, int32_t minPanEvents )
279 {
280   bool firstRegistration(mPanGestureDetectors.empty());
281
282   mPanGestureDetectors.push_back(gestureDetector);
283
284   if (firstRegistration)
285   {
286     mMinTouchesRequired = gestureDetector->GetMinimumTouchesRequired();
287     mMaxTouchesRequired = gestureDetector->GetMaximumTouchesRequired();
288
289     PanGestureRequest request;
290     request.minTouches = mMinTouchesRequired;
291     request.maxTouches = mMaxTouchesRequired;
292
293     Size size = scene.GetSize();
294     mGestureRecognizer = new PanGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const PanGestureRequest&>(request), minDistance, minPanEvents);
295   }
296   else
297   {
298     UpdateDetection();
299   }
300 }
301
302 void PanGestureProcessor::RemoveGestureDetector( PanGestureDetector* gestureDetector )
303 {
304   if (!mCurrentPanEmitters.empty())
305   {
306     // Check if the removed detector was one that is currently being panned and remove it from emitters.
307     GestureDetectorContainer::iterator endIter = std::remove( mCurrentPanEmitters.begin(), mCurrentPanEmitters.end(), gestureDetector );
308     mCurrentPanEmitters.erase( endIter, mCurrentPanEmitters.end() );
309
310     // If we no longer have any emitters, then we should clear mCurrentGesturedActor as well
311     if ( mCurrentPanEmitters.empty() )
312     {
313       ResetActor();
314     }
315   }
316
317   // Find the detector...
318   PanGestureDetectorContainer::iterator endIter = std::remove( mPanGestureDetectors.begin(), mPanGestureDetectors.end(), gestureDetector );
319   DALI_ASSERT_DEBUG( endIter != mPanGestureDetectors.end() );
320
321   // ...and remove it
322   mPanGestureDetectors.erase(endIter, mPanGestureDetectors.end());
323
324   if (mPanGestureDetectors.empty())
325   {
326     mGestureRecognizer = nullptr;
327   }
328   else
329   {
330     UpdateDetection();
331   }
332 }
333
334 void PanGestureProcessor::GestureDetectorUpdated( PanGestureDetector* gestureDetector )
335 {
336   DALI_ASSERT_DEBUG(find(mPanGestureDetectors.begin(), mPanGestureDetectors.end(), gestureDetector) != mPanGestureDetectors.end());
337
338   UpdateDetection();
339 }
340
341 bool PanGestureProcessor::SetPanGestureProperties( const Dali::PanGesture& pan )
342 {
343   // If we are currently processing a pan gesture then just ignore
344   if ( mCurrentPanEmitters.empty() && mSceneObject )
345   {
346     const PanGesture& panImpl( GetImplementation(pan) );
347
348     // We update the scene object directly rather than sending a message.
349     // Sending a message could cause unnecessary delays, the scene object ensure thread safe behaviour.
350     mSceneObject->AddGesture( panImpl );
351
352     if( Dali::Gesture::Started == panImpl.GetState() || Dali::Gesture::Continuing == panImpl.GetState() )
353     {
354       mNeedsUpdate = true;
355     }
356   }
357
358   return mNeedsUpdate;
359 }
360
361 void PanGestureProcessor::EnableProfiling()
362 {
363   mSceneObject->EnableProfiling();
364 }
365
366 void PanGestureProcessor::SetPredictionMode(int mode)
367 {
368   if( (mode < 0)
369       || (mode >= SceneGraph::PanGesture::NUM_PREDICTION_MODES) )
370   {
371     mode = SceneGraph::PanGesture::DEFAULT_PREDICTION_MODE;
372   }
373   SceneGraph::PanGesture::PredictionMode modeEnum = static_cast<SceneGraph::PanGesture::PredictionMode>(mode);
374   mSceneObject->SetPredictionMode(modeEnum);
375 }
376
377 void PanGestureProcessor::SetPredictionAmount(unsigned int amount)
378 {
379   mSceneObject->SetPredictionAmount(amount);
380 }
381
382 void PanGestureProcessor::SetMaximumPredictionAmount(unsigned int amount)
383 {
384   mSceneObject->SetMaximumPredictionAmount(amount);
385 }
386
387 void PanGestureProcessor::SetMinimumPredictionAmount(unsigned int amount)
388 {
389   mSceneObject->SetMinimumPredictionAmount(amount);
390 }
391
392 void PanGestureProcessor::SetPredictionAmountAdjustment(unsigned int amount)
393 {
394   mSceneObject->SetPredictionAmountAdjustment(amount);
395 }
396
397 void PanGestureProcessor::SetSmoothingMode(int mode)
398 {
399   if( (mode < 0)
400       || (mode >= SceneGraph::PanGesture::NUM_SMOOTHING_MODES) )
401   {
402     mode = SceneGraph::PanGesture::DEFAULT_SMOOTHING_MODE;
403   }
404   SceneGraph::PanGesture::SmoothingMode modeEnum = static_cast<SceneGraph::PanGesture::SmoothingMode>(mode);
405   mSceneObject->SetSmoothingMode(modeEnum);
406 }
407
408 void PanGestureProcessor::SetSmoothingAmount(float amount)
409 {
410   mSceneObject->SetSmoothingAmount(amount);
411 }
412
413 void PanGestureProcessor::SetUseActualTimes( bool value )
414 {
415   mSceneObject->SetUseActualTimes( value );
416 }
417
418 void PanGestureProcessor::SetInterpolationTimeRange( int value )
419 {
420   mSceneObject->SetInterpolationTimeRange( value );
421 }
422
423 void PanGestureProcessor::SetScalarOnlyPredictionEnabled( bool value )
424 {
425   mSceneObject->SetScalarOnlyPredictionEnabled( value );
426 }
427
428 void PanGestureProcessor::SetTwoPointPredictionEnabled( bool value )
429 {
430   mSceneObject->SetTwoPointPredictionEnabled( value );
431 }
432
433 void PanGestureProcessor::SetTwoPointInterpolatePastTime( int value )
434 {
435   mSceneObject->SetTwoPointInterpolatePastTime( value );
436 }
437
438 void PanGestureProcessor::SetTwoPointVelocityBias( float value )
439 {
440   mSceneObject->SetTwoPointVelocityBias( value );
441 }
442
443 void PanGestureProcessor::SetTwoPointAccelerationBias( float value )
444 {
445   mSceneObject->SetTwoPointAccelerationBias( value );
446 }
447
448 void PanGestureProcessor::SetMultitapSmoothingRange( int value )
449 {
450   mSceneObject->SetMultitapSmoothingRange( value );
451 }
452
453 const SceneGraph::PanGesture& PanGestureProcessor::GetSceneObject() const
454 {
455   return *mSceneObject;
456 }
457
458 void PanGestureProcessor::UpdateDetection()
459 {
460   DALI_ASSERT_DEBUG(!mPanGestureDetectors.empty());
461
462   unsigned int minimumRequired = UINT_MAX;
463   unsigned int maximumRequired = 0;
464
465   for ( PanGestureDetectorContainer::iterator iter = mPanGestureDetectors.begin(), endIter = mPanGestureDetectors.end(); iter != endIter; ++iter )
466   {
467     PanGestureDetector* detector(*iter);
468
469     if( detector )
470     {
471       unsigned int minimum = detector->GetMinimumTouchesRequired();
472       if (minimum < minimumRequired)
473       {
474         minimumRequired = minimum;
475       }
476
477       unsigned int maximum = detector->GetMaximumTouchesRequired();
478       if (maximum > maximumRequired)
479       {
480         maximumRequired = maximum;
481       }
482     }
483   }
484
485   if ( (minimumRequired != mMinTouchesRequired)||(maximumRequired != mMaxTouchesRequired) )
486   {
487     mMinTouchesRequired = minimumRequired;
488     mMaxTouchesRequired = maximumRequired;
489
490     PanGestureRequest request;
491     request.minTouches = mMinTouchesRequired;
492     request.maxTouches = mMaxTouchesRequired;
493     mGestureRecognizer->Update(request);
494   }
495 }
496
497 void PanGestureProcessor::EmitPanSignal( Actor* actor,
498                                          const GestureDetectorContainer& gestureDetectors,
499                                          const PanGestureEvent& panEvent,
500                                          Vector2 localCurrent,
501                                          Gesture::State state,
502                                          RenderTaskPtr renderTask )
503 {
504   if ( actor && !gestureDetectors.empty() )
505   {
506     Internal::PanGesturePtr pan( new Internal::PanGesture(state ) );
507
508     pan->SetTime( panEvent.time );
509
510     pan->SetNumberOfTouches( panEvent.numberOfTouches );
511     pan->SetScreenPosition( panEvent.currentPosition );
512     pan->SetPosition( localCurrent );
513
514     RenderTask& renderTaskImpl( *renderTask.Get() );
515
516     Vector2 localPrevious;
517     actor->ScreenToLocal( renderTaskImpl, localPrevious.x, localPrevious.y, panEvent.previousPosition.x, panEvent.previousPosition.y );
518
519     pan->SetDisplacement( localCurrent - localPrevious );
520     Vector2 previousPos( panEvent.previousPosition );
521     if ( state == Dali::Gesture::Started )
522     {
523       previousPos = mPossiblePanPosition;
524     }
525
526     pan->SetScreenDisplacement( panEvent.currentPosition - previousPos );
527
528     // Avoid dividing by 0
529     if ( panEvent.timeDelta > 0 )
530     {
531       Vector2 velocity;
532       velocity.x = pan->GetDisplacement().x / static_cast<float>( panEvent.timeDelta );
533       velocity.y = pan->GetDisplacement().y / static_cast<float>( panEvent.timeDelta );
534       pan->SetVelocity( velocity );
535
536       Vector2 screenVelocity;
537       screenVelocity.x = pan->GetScreenDisplacement().x / static_cast<float>( panEvent.timeDelta );
538       screenVelocity.y = pan->GetScreenDisplacement().y / static_cast<float>( panEvent.timeDelta );
539       pan->SetScreenVelocity( screenVelocity );
540     }
541
542     // When the gesture ends, we may incorrectly get a ZERO velocity (as we have lifted our finger without any movement)
543     // so we should use the last recorded velocity instead in this scenario.
544     if ( ( state == Dali::Gesture::Finished ) && ( pan->GetScreenVelocity() == Vector2::ZERO ) &&
545          ( panEvent.timeDelta < MAXIMUM_TIME_WITH_VALID_LAST_VELOCITY ) )
546     {
547       pan->SetVelocity( mLastVelocity );
548       pan->SetScreenVelocity( mLastScreenVelocity );
549     }
550     else
551     {
552       // Store the current velocity for future iterations.
553       mLastVelocity = pan->GetVelocity();
554       mLastScreenVelocity = pan->GetScreenVelocity();
555     }
556
557     if ( mSceneObject )
558     {
559       // We update the scene object directly rather than sending a message.
560       // Sending a message could cause unnecessary delays, the scene object ensure thread safe behaviour.
561       mSceneObject->AddGesture( *pan.Get() );
562     }
563
564     Dali::Actor actorHandle( actor );
565
566     const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
567     for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
568     {
569       static_cast< PanGestureDetector* >( *iter )->EmitPanGestureSignal( actorHandle, Dali::PanGesture( pan.Get() ) );
570     }
571   }
572 }
573
574 void PanGestureProcessor::OnGesturedActorStageDisconnection()
575 {
576   mCurrentPanEmitters.clear();
577 }
578
579 bool PanGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor )
580 {
581   DALI_ASSERT_DEBUG( mCurrentPanEvent );
582
583   bool retVal( false );
584   PanGestureDetector* panDetector( static_cast< PanGestureDetector* >( detector ) );
585
586   if ( ( mCurrentPanEvent->numberOfTouches >= panDetector->GetMinimumTouchesRequired() ) &&
587        ( mCurrentPanEvent->numberOfTouches <= panDetector->GetMaximumTouchesRequired() ) )
588   {
589     // Check if the detector requires directional panning.
590     if ( panDetector->RequiresDirectionalPan() && mCurrentRenderTask )
591     {
592       // It does, calculate the angle of the pan in local actor coordinates and ensures it fits
593       // the detector's criteria.
594       RenderTask& renderTaskImpl = *mCurrentRenderTask.Get();
595
596       Vector2 startPosition, currentPosition;
597       actor->ScreenToLocal( renderTaskImpl, startPosition.x,   startPosition.y,   mPossiblePanPosition.x,              mPossiblePanPosition.y );
598       actor->ScreenToLocal( renderTaskImpl, currentPosition.x, currentPosition.y, mCurrentPanEvent->currentPosition.x, mCurrentPanEvent->currentPosition.y );
599       Vector2 displacement( currentPosition - startPosition );
600
601       Radian angle( atanf( displacement.y / displacement.x ) );
602
603       /////////////////////////////
604       //            |            //
605       //            |            //
606       //   Q3 (-,-) | Q4 (+,-)   //
607       //            |            //
608       //    ----------------- +x //
609       //            |            //
610       //   Q2 (-,+) | Q1 (+,+)   //
611       //            |            //
612       //            |            //
613       //           +y            //
614       /////////////////////////////
615       // Quadrant 1: As is
616       // Quadrant 2: 180 degrees + angle
617       // Quadrant 3: angle - 180 degrees
618       // Quadrant 4: As is
619       /////////////////////////////
620
621       if ( displacement.x < 0.0f )
622       {
623         if ( displacement.y >= 0.0f )
624         {
625           // Quadrant 2
626           angle.radian += Math::PI;
627         }
628         else
629         {
630           // Quadrant 3
631           angle.radian -= Math::PI;
632         }
633       }
634
635       if ( panDetector->CheckAngleAllowed( angle ) )
636       {
637         retVal = true;
638       }
639     }
640     else
641     {
642       // Directional panning not required so we can use this actor and gesture detector.
643       retVal = true;
644     }
645   }
646   return retVal;
647 }
648
649 void PanGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
650 {
651   DALI_ASSERT_DEBUG ( mCurrentPanEvent );
652
653   mCurrentPanEmitters.clear();
654   ResetActor();
655
656   actor->ScreenToLocal( *mCurrentRenderTask.Get(), actorCoordinates.x, actorCoordinates.y, mCurrentPanEvent->currentPosition.x, mCurrentPanEvent->currentPosition.y );
657
658   EmitPanSignal( actor, gestureDetectors, *mCurrentPanEvent, actorCoordinates, mCurrentPanEvent->state, mCurrentRenderTask );
659
660   if ( actor->OnScene() )
661   {
662     mCurrentPanEmitters = gestureDetectors;
663     SetActor( actor );
664   }
665 }
666
667 } // namespace Internal
668
669 } // namespace Dali