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