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