(Gestures) Each actor is now aware of what gestures it requires which is used when...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PanGestureDetector.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
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 #include <iostream>
18
19 #include <stdlib.h>
20 #include <dali/dali.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/pan-gesture-event.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali/integration-api/profiling.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-touch-utils.h>
27
28 using namespace Dali;
29
30 void utc_dali_pan_gesture_detector_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_pan_gesture_detector_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////
41 namespace
42 {
43 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
44
45
46 // Stores data that is populated in the callback and will be read by the test cases
47 struct SignalData
48 {
49   SignalData()
50   : functorCalled(false),
51     voidFunctorCalled(false),
52     receivedGesture(Gesture::Clear)
53   {}
54
55   void Reset()
56   {
57     functorCalled = false;
58     voidFunctorCalled = false;
59
60     receivedGesture.state = Gesture::Clear;
61     receivedGesture.velocity = Vector2(0.0f, 0.0f);
62     receivedGesture.displacement = Vector2(0.0f, 0.0f);
63     receivedGesture.position = Vector2(0.0f, 0.0f);
64     receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
65     receivedGesture.numberOfTouches = 0;
66
67     pannedActor = NULL;
68   }
69
70   bool functorCalled;
71   bool voidFunctorCalled;
72   PanGesture receivedGesture;
73   Actor pannedActor;
74 };
75
76 // Functor that sets the data when called
77 struct GestureReceivedFunctor
78 {
79   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
80
81   void operator()(Actor actor, PanGesture pan)
82   {
83     signalData.functorCalled = true;
84     signalData.receivedGesture = pan;
85     signalData.pannedActor = actor;
86   }
87
88   void operator()()
89   {
90     signalData.voidFunctorCalled = true;
91   }
92
93   SignalData& signalData;
94 };
95
96 // Functor that removes the gestured actor from stage
97 struct UnstageActorFunctor : public GestureReceivedFunctor
98 {
99   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
100   : GestureReceivedFunctor( data ),
101     stateToUnstage( stateToUnstage )
102   {
103   }
104
105   void operator()( Actor actor, PanGesture pan )
106   {
107     GestureReceivedFunctor::operator()( actor, pan );
108
109     if ( pan.state == stateToUnstage )
110     {
111       Stage::GetCurrent().Remove( actor );
112     }
113   }
114
115   Gesture::State& stateToUnstage;
116 };
117
118 // Functor for receiving a touch event
119 struct TouchEventFunctor
120 {
121   bool operator()(Actor actor, const TouchEvent& touch)
122   {
123     return false;
124   }
125 };
126
127 // Data for constraints
128 struct ConstraintData
129 {
130   ConstraintData()
131   : called(false)
132   {
133   }
134
135   Vector2 screenPosition;
136   Vector2 screenDisplacement;
137   Vector2 localPosition;
138   Vector2 localDisplacement;
139   bool called;
140
141   void Reset()
142   {
143     screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO;
144     called = false;
145   }
146 };
147
148 // Constraint used with panning properties
149 struct PanConstraint
150 {
151   PanConstraint( ConstraintData& data ) : constraintData(data) { }
152
153   Vector3 operator()(const Vector3&       current,
154                      const PropertyInput& screenPositionProperty,
155                      const PropertyInput& screenDisplacementProperty,
156                      const PropertyInput& localPositionProperty,
157                      const PropertyInput& localDisplacementProperty)
158   {
159     constraintData.screenPosition = screenPositionProperty.GetVector2();
160     constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
161     constraintData.localPosition = localPositionProperty.GetVector2();
162     constraintData.localDisplacement = localDisplacementProperty.GetVector2();
163     constraintData.called = true;
164     return Vector3::ZERO;
165   }
166
167   ConstraintData& constraintData;
168 };
169
170 // Generate a PanGestureEvent to send to Core
171 Integration::PanGestureEvent GeneratePan(
172     Gesture::State state,
173     Vector2 previousPosition,
174     Vector2 currentPosition,
175     unsigned long timeDelta,
176     unsigned int numberOfTouches = 1,
177     unsigned int time = 1u)
178 {
179   Integration::PanGestureEvent pan(state);
180
181   pan.previousPosition = previousPosition;
182   pan.currentPosition = currentPosition;
183   pan.timeDelta = timeDelta;
184   pan.numberOfTouches = numberOfTouches;
185   pan.time = time;
186
187   return pan;
188 }
189
190 // Generate a PanGesture
191 PanGesture GeneratePan( unsigned int time,
192                         Gesture::State state,
193                         Vector2 screenPosition,
194                         Vector2 localPosition,
195                         Vector2 screenDisplacement = Vector2::ONE,
196                         Vector2 localDisplacement = Vector2::ONE,
197                         Vector2 velocity = Vector2::ONE,
198                         unsigned int numberOfTouches = 1 )
199 {
200   PanGesture pan( state );
201
202   pan.time = time;
203
204   pan.screenPosition = screenPosition;
205   pan.position = localPosition;
206
207   pan.screenDisplacement = screenDisplacement;
208   pan.displacement = localDisplacement;
209
210   pan.screenVelocity = pan.velocity = velocity;
211   pan.numberOfTouches = numberOfTouches;
212
213   return pan;
214 }
215
216 } // anon namespace
217
218 ///////////////////////////////////////////////////////////////////////////////
219
220 // Positive test case for a method
221 int UtcDaliPanGestureDetectorConstructor(void)
222 {
223   TestApplication application;
224
225   PanGestureDetector detector;
226   DALI_TEST_CHECK(!detector);
227   END_TEST;
228 }
229
230
231 // Negative test case for a method
232 int UtcDaliPanGestureDetectorNew(void)
233 {
234   TestApplication application;
235
236   PanGestureDetector detector = PanGestureDetector::New();
237
238   DALI_TEST_CHECK(detector);
239
240   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
241   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
242
243   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
244   Actor actor = Actor::New();
245   actor.SetSize(100.0f, 100.0f);
246   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
247   detector.Attach(actor);
248
249   Stage::GetCurrent().Add(actor);
250
251   // Render and notify
252   application.SendNotification();
253   application.Render();
254
255   Integration::TouchEvent touchEvent(1);
256   TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
257   touchEvent.AddPoint(point);
258   application.ProcessEvent(touchEvent);
259   END_TEST;
260 }
261
262 int UtcDaliPanGestureDetectorDownCast(void)
263 {
264   TestApplication application;
265   tet_infoline("Testing Dali::GestureDetector::DownCast()");
266
267   PanGestureDetector detector = PanGestureDetector::New();
268
269   BaseHandle object(detector);
270
271   PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
272   DALI_TEST_CHECK(detector2);
273
274   PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
275   DALI_TEST_CHECK(detector3);
276
277   BaseHandle unInitializedObject;
278   PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
279   DALI_TEST_CHECK(!detector4);
280
281   PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
282   DALI_TEST_CHECK(!detector5);
283
284   GestureDetector detector6 = PanGestureDetector::New();
285   PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
286   DALI_TEST_CHECK(detector7);
287   END_TEST;
288 }
289
290 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
291 {
292   TestApplication application;
293
294   PanGestureDetector detector = PanGestureDetector::New();
295
296   unsigned int min = 2;
297
298   DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
299
300   detector.SetMinimumTouchesRequired(min);
301
302   DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
303
304   // Attach an actor and change the minimum touches
305
306   Actor actor = Actor::New();
307   actor.SetSize(100.0f, 100.0f);
308   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
309   Stage::GetCurrent().Add(actor);
310
311   // Render and notify
312   application.SendNotification();
313   application.Render();
314
315   SignalData data;
316   GestureReceivedFunctor functor(data);
317
318   detector.Attach(actor);
319   detector.DetectedSignal().Connect(&application, functor);
320
321   TestGestureManager& gestureManager = application.GetGestureManager();
322   gestureManager.Initialize();
323
324   detector.SetMinimumTouchesRequired(3);
325
326   // Gesture detection should have been updated only
327   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
328   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
329   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
330
331   // Reset values
332   gestureManager.Initialize();
333
334   // Create a second gesture detector that requires even less minimum touches
335   PanGestureDetector secondDetector = PanGestureDetector::New();
336   secondDetector.Attach(actor);
337
338   // Gesture detection should have been updated only
339   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
340   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
341   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
342   END_TEST;
343 }
344
345 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
346 {
347   TestApplication application;
348
349   PanGestureDetector detector = PanGestureDetector::New();
350
351   unsigned int max = 3;
352
353   DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
354
355   detector.SetMaximumTouchesRequired(max);
356
357   DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
358
359   // Attach an actor and change the maximum touches
360
361   Actor actor = Actor::New();
362   actor.SetSize(100.0f, 100.0f);
363   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
364   Stage::GetCurrent().Add(actor);
365
366   // Render and notify
367   application.SendNotification();
368   application.Render();
369
370   SignalData data;
371   GestureReceivedFunctor functor(data);
372
373   detector.Attach(actor);
374   detector.DetectedSignal().Connect(&application, functor);
375
376   TestGestureManager& gestureManager = application.GetGestureManager();
377   gestureManager.Initialize();
378
379   detector.SetMaximumTouchesRequired(4);
380
381   // Gesture detection should have been updated only
382   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
383   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
384   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
385
386   // Reset values
387   gestureManager.Initialize();
388
389   // Create a second gesture detector that requires even less maximum touches
390   PanGestureDetector secondDetector = PanGestureDetector::New();
391   secondDetector.Attach(actor);
392
393   // Gesture detection should NOT have been updated
394   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
395   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
396   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
397   END_TEST;
398 }
399
400 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
401 {
402   TestApplication application;
403
404   PanGestureDetector detector = PanGestureDetector::New();
405   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
406   END_TEST;
407 }
408
409 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
410 {
411   TestApplication application;
412
413   PanGestureDetector detector = PanGestureDetector::New();
414   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
415   END_TEST;
416 }
417
418 int UtcDaliPanGestureSignalReceptionNegative(void)
419 {
420   TestApplication application;
421
422   Actor actor = Actor::New();
423   actor.SetSize(100.0f, 100.0f);
424   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
425   Stage::GetCurrent().Add(actor);
426
427   // Render and notify
428   application.SendNotification();
429   application.Render();
430
431   SignalData data;
432   GestureReceivedFunctor functor(data);
433
434   PanGestureDetector detector = PanGestureDetector::New();
435   detector.Attach(actor);
436   detector.DetectedSignal().Connect(&application, functor);
437
438   // Do a pan outside actor's area
439   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
440   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
441   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
442
443   // Continue pan into actor's area - we should still not receive the signal
444   data.Reset();
445   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
446   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
447
448   // Stop panning - we should still not receive the signal
449   data.Reset();
450   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
451   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
452   END_TEST;
453 }
454
455 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
456 {
457   TestApplication application;
458
459   Actor actor = Actor::New();
460   actor.SetSize(100.0f, 100.0f);
461   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
462   Stage::GetCurrent().Add(actor);
463
464   // Render and notify
465   application.SendNotification();
466   application.Render();
467
468   SignalData data;
469   GestureReceivedFunctor functor(data);
470
471   PanGestureDetector detector = PanGestureDetector::New();
472   detector.Attach(actor);
473   detector.DetectedSignal().Connect(&application, functor);
474
475   // Start pan within the actor's area
476   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
477   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
478   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
479   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
480   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
481   DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
482   DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
483   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
484   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
485
486   // Continue the pan within the actor's area - we should still receive the signal
487   data.Reset();
488   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
489   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
490   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
491   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
492   DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
493   DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
494   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
495   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
496
497   // Pan Gesture leaves actor's area - we should still receive the signal
498   data.Reset();
499   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
500   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
501   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
502   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
503   DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
504   DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
505   DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
506   DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
507
508   // Gesture ends - we would receive a finished state
509   data.Reset();
510   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
511   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
512   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
513   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
514   DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
515   DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
516   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
517   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
518   END_TEST;
519 }
520
521 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
522 {
523   TestApplication application;
524
525   Actor actor = Actor::New();
526   actor.SetSize(100.0f, 100.0f);
527   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
528   Stage::GetCurrent().Add(actor);
529
530   // Render and notify
531   application.SendNotification();
532   application.Render();
533
534   SignalData data;
535   GestureReceivedFunctor functor(data);
536
537   PanGestureDetector detector = PanGestureDetector::New();
538   detector.Attach(actor);
539   detector.DetectedSignal().Connect(&application, functor);
540
541   // Start pan within the actor's area
542   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
543   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
544   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
545   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
546   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
547   DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
548   DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
549   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
550   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
551
552   // Continue the pan within the actor's area - we should still receive the signal
553   data.Reset();
554   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
555   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
556   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
557   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
558   DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
559   DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
560   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
561   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
562
563   // Gesture ends within actor's area - we would receive a finished state
564   data.Reset();
565   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
566   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
568   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
569   DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
570   DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
571   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
572   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
573   END_TEST;
574 }
575
576 int UtcDaliPanGestureSignalReceptionCancelled(void)
577 {
578   TestApplication application;
579
580   Actor actor = Actor::New();
581   actor.SetSize(100.0f, 100.0f);
582   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
583   Stage::GetCurrent().Add(actor);
584
585   // Render and notify
586   application.SendNotification();
587   application.Render();
588
589   SignalData data;
590   GestureReceivedFunctor functor(data);
591
592   PanGestureDetector detector = PanGestureDetector::New();
593   detector.Attach(actor);
594   detector.DetectedSignal().Connect(&application, functor);
595
596   // Start pan within the actor's area
597   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
598   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
599   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
600   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
601
602   // Continue the pan within the actor's area - we should still receive the signal
603   data.Reset();
604   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
605   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
607
608   // The gesture is cancelled
609   data.Reset();
610   application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
611   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612   DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
613   END_TEST;
614 }
615
616 int UtcDaliPanGestureSignalReceptionDetach(void)
617 {
618   TestApplication application;
619
620   Actor actor = Actor::New();
621   actor.SetSize(100.0f, 100.0f);
622   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
623   Stage::GetCurrent().Add(actor);
624
625   // Render and notify
626   application.SendNotification();
627   application.Render();
628
629   SignalData data;
630   GestureReceivedFunctor functor(data);
631
632   PanGestureDetector detector = PanGestureDetector::New();
633   detector.Attach(actor);
634   detector.DetectedSignal().Connect(&application, functor);
635
636   // Start pan within the actor's area
637   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
638   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
639   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
640
641   // Continue the pan within the actor's area - we should still receive the signal
642   data.Reset();
643   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
644   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
645
646   // Gesture ends within actor's area
647   data.Reset();
648   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
649   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
650
651   // Detach actor
652   detector.DetachAll();
653
654   // Ensure we are no longer signalled
655   data.Reset();
656   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
657   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
658   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
659   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
660   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
661   END_TEST;
662 }
663
664 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
665 {
666   TestApplication application;
667
668   Actor actor = Actor::New();
669   actor.SetSize(100.0f, 100.0f);
670   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
671   Stage::GetCurrent().Add(actor);
672
673   // Render and notify
674   application.SendNotification();
675   application.Render();
676
677   SignalData data;
678   GestureReceivedFunctor functor(data);
679
680   PanGestureDetector detector = PanGestureDetector::New();
681   detector.Attach(actor);
682   detector.DetectedSignal().Connect(&application, functor);
683
684   // Start pan within the actor's area
685   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
686   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
687   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
688
689   // Continue the pan within the actor's area - we should still receive the signal
690   data.Reset();
691   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
692   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
693
694   // Detach actor during the pan, we should not receive the next event
695   detector.DetachAll();
696
697   // Gesture ends within actor's area
698   data.Reset();
699   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
700   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
701   END_TEST;
702 }
703
704 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
705 {
706   TestApplication application;
707
708   SignalData data;
709   GestureReceivedFunctor functor(data);
710
711   PanGestureDetector detector = PanGestureDetector::New();
712   detector.DetectedSignal().Connect(&application, functor);
713
714   // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
715   // is destroyed.
716   Actor tempActor = Actor::New();
717   tempActor.SetSize(100.0f, 100.0f);
718   tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
719   Stage::GetCurrent().Add(tempActor);
720   detector.Attach(tempActor);
721
722   // Actor lifetime is scoped
723   {
724     Actor actor = Actor::New();
725     actor.SetSize(100.0f, 100.0f);
726     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
727     Stage::GetCurrent().Add(actor);
728
729     // Render and notify
730     application.SendNotification();
731     application.Render();
732
733     detector.Attach(actor);
734
735     // Start pan within the actor's area
736     application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
737     application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
738     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
739
740     // Continue the pan within the actor's area - we should still receive the signal
741     data.Reset();
742     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
743     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
744
745     // Remove the actor from stage and reset the data
746     Stage::GetCurrent().Remove(actor);
747
748     // Render and notify
749     application.SendNotification();
750     application.Render();
751   }
752
753   // Actor should now have been destroyed
754
755   // Gesture ends within the area where the actor used to be
756   data.Reset();
757   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
758   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
759   END_TEST;
760 }
761
762 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
763 {
764   TestApplication application;
765
766   Actor actor = Actor::New();
767   actor.SetSize(100.0f, 100.0f);
768   actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
769   Stage::GetCurrent().Add(actor);
770
771   // Render and notify
772   application.SendNotification();
773   application.Render();
774
775   SignalData data;
776   GestureReceivedFunctor functor(data);
777
778   PanGestureDetector detector = PanGestureDetector::New();
779   detector.Attach(actor);
780   detector.DetectedSignal().Connect(&application, functor);
781
782   // Do an entire pan, only check finished value
783   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
784   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
785   data.Reset();
786   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
787   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
788   DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
789
790   // Rotate actor again and render a couple of times
791   actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
792   application.SendNotification();
793   application.Render();
794
795   // Do an entire pan, only check finished value
796   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
797   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
798   data.Reset();
799   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
800   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
801   DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
802
803   // Rotate actor again and render a couple of times
804   actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
805   application.SendNotification();
806   application.Render();
807
808   // Do an entire pan, only check finished value
809   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
810   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
811   data.Reset();
812   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
813   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
814   DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
815   END_TEST;
816 }
817
818 int UtcDaliPanGestureSignalReceptionChildHit(void)
819 {
820   TestApplication application;
821
822   Actor parent = Actor::New();
823   parent.SetSize(100.0f, 100.0f);
824   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
825   Stage::GetCurrent().Add(parent);
826
827   // Set child to completely cover parent.
828   // Change rotation of child to be different from parent so that we can check if our local coordinate
829   // conversion of the parent actor is correct.
830   Actor child = Actor::New();
831   child.SetSize(100.0f, 100.0f);
832   child.SetAnchorPoint(AnchorPoint::CENTER);
833   child.SetParentOrigin(ParentOrigin::CENTER);
834   child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
835   parent.Add(child);
836
837   TouchEventFunctor touchFunctor;
838   child.TouchedSignal().Connect(&application, touchFunctor);
839
840   // Render and notify
841   application.SendNotification();
842   application.Render();
843
844   SignalData data;
845   GestureReceivedFunctor functor(data);
846
847   PanGestureDetector detector = PanGestureDetector::New();
848   detector.Attach(parent);
849   detector.DetectedSignal().Connect(&application, functor);
850
851   // Do an entire pan, only check finished value - hits child area but parent should still receive it
852   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
853   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
854   data.Reset();
855   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
856   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
857   DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
858   DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
859
860   // Attach child and generate same touch points to yield a different displacement
861   // (Also proves that you can detach and then re-attach another actor)
862   detector.Attach(child);
863   detector.Detach(parent);
864
865   // Do an entire pan, only check finished value
866   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
867   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
868   data.Reset();
869   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
870   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
871   DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
872   DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
873   END_TEST;
874 }
875
876 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
877 {
878   TestApplication application;
879
880   Actor first = Actor::New();
881   first.SetSize(100.0f, 100.0f);
882   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
883   Stage::GetCurrent().Add(first);
884
885   Actor second = Actor::New();
886   second.SetSize(100.0f, 100.0f);
887   second.SetX(100.0f);
888   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
889   Stage::GetCurrent().Add(second);
890
891   // Render and notify
892   application.SendNotification();
893   application.Render();
894
895   SignalData data;
896   GestureReceivedFunctor functor(data);
897
898   PanGestureDetector detector = PanGestureDetector::New();
899   detector.Attach(first);
900   detector.Attach(second);
901   detector.DetectedSignal().Connect(&application, functor);
902
903   // Start pan within second actor's area
904   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
905   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
906   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
907   DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
908
909   // Pan moves into first actor's area - second actor should receive the pan
910   data.Reset();
911   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
912   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
913   DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
914
915   // Detach the second actor during the pan, we should not receive the next event
916   detector.Detach(second);
917
918   // Gesture ends within actor's area
919   data.Reset();
920   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
921   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
922   END_TEST;
923 }
924
925 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
926 {
927   TestApplication application;
928
929   Actor actor = Actor::New();
930   actor.SetSize(100.0f, 100.0f);
931   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
932   Stage::GetCurrent().Add(actor);
933
934   // Render and notify
935   application.SendNotification();
936   application.Render();
937
938   SignalData data;
939   GestureReceivedFunctor functor(data);
940
941   PanGestureDetector detector = PanGestureDetector::New();
942   detector.Attach(actor);
943   detector.DetectedSignal().Connect(&application, functor);
944
945   // Start pan in actor's area
946   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
947   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
948   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
949
950   // Pan continues within actor's area
951   data.Reset();
952   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
953   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
954
955   // Actor become invisible - actor should not receive the next pan
956   actor.SetVisible(false);
957
958   // Render and notify
959   application.SendNotification();
960   application.Render();
961
962   // Gesture ends within actor's area
963   data.Reset();
964   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
965   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
966   END_TEST;
967 }
968
969 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
970 {
971   TestApplication application;
972   Dali::TestGestureManager& gestureManager = application.GetGestureManager();
973
974   Actor first = Actor::New();
975   first.SetSize(100.0f, 100.0f);
976   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
977   Stage::GetCurrent().Add(first);
978
979   Actor second = Actor::New();
980   second.SetSize(100.0f, 100.0f);
981   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
982   first.Add(second);
983
984   // Render and notify
985   application.SendNotification();
986   application.Render();
987
988   SignalData data;
989   GestureReceivedFunctor functor(data);
990
991   PanGestureDetector firstDetector = PanGestureDetector::New();
992   firstDetector.Attach(first);
993   firstDetector.DetectedSignal().Connect(&application, functor);
994
995   // secondDetector is scoped
996   {
997     // Reset gestureManager statistics
998     gestureManager.Initialize();
999
1000     PanGestureDetector secondDetector = PanGestureDetector::New();
1001     secondDetector.SetMinimumTouchesRequired(2);
1002     secondDetector.SetMaximumTouchesRequired(2);
1003     secondDetector.Attach(second);
1004     secondDetector.DetectedSignal().Connect(&application, functor);
1005
1006     DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1007     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1008     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1009
1010     // Start pan within second actor's area
1011     application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1012     application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1013     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1014     DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1015
1016     // Two touch pan changes to single touch - we should receive a finished state
1017     data.Reset();
1018     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1019     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1020     DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1021     DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1022
1023     // Pan continues as single touch gesture - we should not receive any gesture
1024     data.Reset();
1025     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1026     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1027
1028     // Pan ends - still no signal
1029     data.Reset();
1030     application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1031     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1032
1033     // Single touch pan starts - first actor should be panned
1034     data.Reset();
1035     application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1036     application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1037     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1038     DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1039
1040     // Pan changes to double-touch - we should receive a finished state
1041     data.Reset();
1042     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1043     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1044     DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1045     DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1046
1047     // Pan continues as double touch gesture - we should not receive any gesture
1048     data.Reset();
1049     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1050     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1051
1052     // Pan ends - still no signal
1053     data.Reset();
1054     application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1055     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1056
1057     // Reset gesture manager statistics
1058     gestureManager.Initialize();
1059   }
1060
1061   // secondDetector has now been deleted.  Gesture detection should have been updated only
1062   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1063   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1064   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1065   END_TEST;
1066 }
1067
1068 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1069 {
1070   TestApplication application;
1071
1072   Actor actor = Actor::New();
1073   actor.SetSize(100.0f, 100.0f);
1074   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1075   Stage::GetCurrent().Add(actor);
1076
1077   Actor actor2 = Actor::New();
1078   actor2.SetSize(100.0f, 100.0f);
1079   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1080   Stage::GetCurrent().Add(actor2);
1081
1082   // Render and notify
1083   application.SendNotification();
1084   application.Render();
1085
1086   // Attach actor to one detector
1087   SignalData firstData;
1088   GestureReceivedFunctor firstFunctor(firstData);
1089   PanGestureDetector firstDetector = PanGestureDetector::New();
1090   firstDetector.Attach(actor);
1091   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1092
1093   // Attach actor to another detector
1094   SignalData secondData;
1095   GestureReceivedFunctor secondFunctor(secondData);
1096   PanGestureDetector secondDetector = PanGestureDetector::New();
1097   secondDetector.Attach(actor);
1098   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1099
1100   // Add second actor to second detector, when we remove the actor, this will make sure that this
1101   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
1102   // functor should still not be called (which is what we're also testing).
1103   secondDetector.Attach(actor2);
1104
1105   // Pan in actor's area - both detector's functors should be called
1106   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1107   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1108   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1109   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1110
1111   // Pan continues in actor's area - both detector's functors should be called
1112   firstData.Reset();
1113   secondData.Reset();
1114   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1115   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1116   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1117
1118   // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1119   firstDetector.Detach(actor);
1120   firstData.Reset();
1121   secondData.Reset();
1122   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1123   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1124   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1125
1126   // New pan on actor, only secondDetector has actor attached
1127   firstData.Reset();
1128   secondData.Reset();
1129   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1130   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1131   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1132   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1133
1134   // Detach actor from secondDetector
1135   secondDetector.Detach(actor);
1136   firstData.Reset();
1137   secondData.Reset();
1138   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1139   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1140   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1141   END_TEST;
1142 }
1143
1144 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1145 {
1146   // Should handle two started events gracefully.
1147
1148   TestApplication application;
1149
1150   Actor actor = Actor::New();
1151   actor.SetSize(100.0f, 100.0f);
1152   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1153   Stage::GetCurrent().Add(actor);
1154
1155   SignalData data;
1156   GestureReceivedFunctor functor(data);
1157
1158   PanGestureDetector detector = PanGestureDetector::New();
1159   detector.Attach(actor);
1160   detector.DetectedSignal().Connect(&application, functor);
1161
1162   // Render and notify
1163   application.SendNotification();
1164   application.Render();
1165
1166   // Start pan in actor's area
1167   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1168   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1169   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1170
1171   // Send another start in actor's area
1172   data.Reset();
1173   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1174   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1175
1176   // Add a child actor to overlap actor and send another start in actor's area
1177   Actor child = Actor::New();
1178   child.SetSize(100.0f, 100.0f);
1179   child.SetAnchorPoint(AnchorPoint::CENTER);
1180   child.SetParentOrigin(ParentOrigin::CENTER);
1181   actor.Add(child);
1182
1183   TouchEventFunctor touchFunctor;
1184   child.TouchedSignal().Connect(&application, touchFunctor);
1185
1186   // Render and notify
1187   application.SendNotification();
1188   application.Render();
1189
1190   // Send another possible and start in actor's area
1191   data.Reset();
1192   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1193   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1194   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1195
1196   // Send another start in actor's area
1197   data.Reset();
1198   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1199   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1200   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1201   END_TEST;
1202 }
1203
1204 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1205 {
1206   TestApplication application;
1207
1208   Actor actor1 = Actor::New();
1209   actor1.SetSize(100.0f, 100.0f);
1210   actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1211   Stage::GetCurrent().Add(actor1);
1212   SignalData data1;
1213   GestureReceivedFunctor functor1(data1);
1214   PanGestureDetector detector1 = PanGestureDetector::New();
1215   detector1.Attach(actor1);
1216   detector1.DetectedSignal().Connect(&application, functor1);
1217
1218   Actor actor2 = Actor::New();
1219   actor2.SetSize(100.0f, 100.0f);
1220   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1221   actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1222   Stage::GetCurrent().Add(actor2);
1223   SignalData data2;
1224   GestureReceivedFunctor functor2(data2);
1225   PanGestureDetector detector2 = PanGestureDetector::New();
1226   detector2.Attach(actor2);
1227   detector2.DetectedSignal().Connect(&application, functor2);
1228
1229   // Render and notify
1230   application.SendNotification();
1231   application.Render();
1232
1233   // Start pan in actor1's area, only data1 should be set
1234   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1235   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1236   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1237   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1238   END_TEST;
1239 }
1240
1241 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1242 {
1243   TestApplication application;
1244
1245   Actor actor = Actor::New();
1246   actor.SetSize(100.0f, 100.0f);
1247   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1248   Stage::GetCurrent().Add(actor);
1249
1250   // Render and notify
1251   application.SendNotification();
1252   application.Render();
1253
1254   // Attach actor to detector
1255   SignalData data;
1256   GestureReceivedFunctor functor( data );
1257   PanGestureDetector detector = PanGestureDetector::New();
1258   detector.Attach(actor);
1259   detector.DetectedSignal().Connect( &application, functor );
1260
1261   // Gesture possible in actor's area.
1262   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1263   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1264
1265   // Move actor somewhere else
1266   actor.SetPosition( 100.0f, 100.0f );
1267
1268   // Render and notify
1269   application.SendNotification();
1270   application.Render();
1271
1272   // Emit Started event, we should not receive the long press.
1273   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1274   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1275   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1276
1277   // LongPress possible in empty area.
1278   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1279   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1280
1281   // Move actor in to the long press position.
1282   actor.SetPosition( 0.0f, 0.0f );
1283
1284   // Render and notify
1285   application.SendNotification();
1286   application.Render();
1287
1288   // Emit Started event, we should not receive the long press.
1289   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1290   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1291   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1292
1293   // Normal long press in actor's area for completeness.
1294   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1295   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1296   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1297   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1298   END_TEST;
1299 }
1300
1301 int UtcDaliPanGestureEmitIncorrectState(void)
1302 {
1303   TestApplication application;
1304
1305   Actor actor = Actor::New();
1306   actor.SetSize(100.0f, 100.0f);
1307   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1308   Stage::GetCurrent().Add(actor);
1309
1310   // Render and notify
1311   application.SendNotification();
1312   application.Render();
1313
1314   // Attach actor to detector
1315   SignalData data;
1316   GestureReceivedFunctor functor( data );
1317   PanGestureDetector detector = PanGestureDetector::New();
1318   detector.Attach(actor);
1319   detector.DetectedSignal().Connect( &application, functor );
1320
1321   // Try a Clear state
1322   try
1323   {
1324     application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1325     tet_result(TET_FAIL);
1326   }
1327   catch ( Dali::DaliException& e )
1328   {
1329     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1330   }
1331   END_TEST;
1332 }
1333
1334 int UtcDaliPanGestureActorUnstaged(void)
1335 {
1336   TestApplication application;
1337
1338   Actor actor = Actor::New();
1339   actor.SetSize(100.0f, 100.0f);
1340   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1341   Stage::GetCurrent().Add(actor);
1342
1343   // Render and notify
1344   application.SendNotification();
1345   application.Render();
1346
1347   // State to remove actor in.
1348   Gesture::State stateToUnstage( Gesture::Started );
1349
1350   // Attach actor to detector
1351   SignalData data;
1352   UnstageActorFunctor functor( data, stateToUnstage );
1353   PanGestureDetector detector = PanGestureDetector::New();
1354   detector.Attach(actor);
1355   detector.DetectedSignal().Connect( &application, functor );
1356
1357   // Emit signals
1358   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1359   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1360   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1361   data.Reset();
1362   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1363   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1364   data.Reset();
1365
1366   // Render and notify
1367   application.SendNotification();
1368   application.Render();
1369
1370   // Re-add actor to stage
1371   Stage::GetCurrent().Add(actor);
1372
1373   // Render and notify
1374   application.SendNotification();
1375   application.Render();
1376
1377   // Change state to Gesture::Continuing to remove
1378   stateToUnstage = Gesture::Continuing;
1379
1380   // Emit signals
1381   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1382   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1383   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1384   data.Reset();
1385   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1386   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1387   data.Reset();
1388   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1389   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1390   data.Reset();
1391
1392   // Render and notify
1393   application.SendNotification();
1394   application.Render();
1395
1396   // Re-add actor to stage
1397   Stage::GetCurrent().Add(actor);
1398
1399   // Render and notify
1400   application.SendNotification();
1401   application.Render();
1402
1403   // Change state to Gesture::Finished to remove
1404   stateToUnstage = Gesture::Finished;
1405
1406   // Emit signals
1407   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1408   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1409   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1410   data.Reset();
1411   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1412   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1413   data.Reset();
1414   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1415   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1416   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1417   END_TEST;
1418 }
1419
1420 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1421 {
1422   TestApplication application;
1423
1424   Actor actor = Actor::New();
1425   actor.SetSize(100.0f, 100.0f);
1426   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1427   Stage::GetCurrent().Add(actor);
1428
1429   // Create and add a second actor so that GestureDetector destruction does not come into play.
1430   Actor dummyActor( Actor::New() );
1431   dummyActor.SetSize( 100.0f, 100.0f );
1432   dummyActor.SetPosition( 100.0f, 100.0f );
1433   dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1434   Stage::GetCurrent().Add(dummyActor);
1435
1436   // Render and notify
1437   application.SendNotification();
1438   application.Render();
1439
1440   // State to remove actor in.
1441   Gesture::State stateToUnstage( Gesture::Started );
1442
1443   // Attach actor to detector
1444   SignalData data;
1445   UnstageActorFunctor functor( data, stateToUnstage );
1446   PanGestureDetector detector = PanGestureDetector::New();
1447   detector.Attach(actor);
1448   detector.Attach(dummyActor);
1449   detector.DetectedSignal().Connect( &application, functor );
1450
1451   // Here we are testing a Started actor which is removed in the Started callback, but then added back
1452   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
1453   // position, we should still not be signalled.
1454
1455   // Emit signals
1456   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1457   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1458   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1459   data.Reset();
1460
1461   // Render and notify
1462   application.SendNotification();
1463   application.Render();
1464
1465   // Re add to the stage, we should not be signalled
1466   Stage::GetCurrent().Add(actor);
1467
1468   // Render and notify
1469   application.SendNotification();
1470   application.Render();
1471
1472   // Continue signal emission
1473   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1474   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1475   data.Reset();
1476   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1477   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1478   data.Reset();
1479
1480   // Here we delete an actor in started, we should not receive any subsequent signalling.
1481
1482   // Emit signals
1483   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1484   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1485   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1486   data.Reset();
1487
1488   // Render and notify
1489   application.SendNotification();
1490   application.Render();
1491
1492   // Delete actor as well
1493   actor = NULL;
1494
1495   // Render and notify
1496   application.SendNotification();
1497   application.Render();
1498
1499   // Continue signal emission
1500   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1501   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1502   data.Reset();
1503   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1504   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1505   END_TEST;
1506 }
1507
1508 int UtcDaliPanGestureSystemOverlay(void)
1509 {
1510   TestApplication application;
1511   Dali::Integration::Core& core = application.GetCore();
1512   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1513   systemOverlay.GetOverlayRenderTasks().CreateTask();
1514
1515   Actor actor = Actor::New();
1516   actor.SetSize(100.0f, 100.0f);
1517   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1518   systemOverlay.Add(actor);
1519
1520   // Render and notify
1521   application.SendNotification();
1522   application.Render();
1523
1524   SignalData data;
1525   GestureReceivedFunctor functor(data);
1526
1527   PanGestureDetector detector = PanGestureDetector::New();
1528   detector.Attach(actor);
1529   detector.DetectedSignal().Connect(&application, functor);
1530
1531   Vector2 screenCoordsStart( 10.0f, 20.0f );
1532   Vector2 screenCoordsEnd( 20.0f, 20.0f );
1533
1534   // Start pan within the actor's area
1535   application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1536   application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1537   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1538   END_TEST;
1539 }
1540
1541 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1542 {
1543   TestApplication application;
1544   Dali::Integration::Core& core = application.GetCore();
1545   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1546   systemOverlay.GetOverlayRenderTasks().CreateTask();
1547
1548   // SystemOverlay actor
1549   Actor systemOverlayActor = Actor::New();
1550   systemOverlayActor.SetSize(100.0f, 100.0f);
1551   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1552   systemOverlay.Add(systemOverlayActor);
1553
1554   // Stage actor
1555   Actor stageActor = Actor::New();
1556   stageActor.SetSize(100.0f, 100.0f);
1557   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1558   Stage::GetCurrent().Add(stageActor);
1559
1560   // Render and notify
1561   application.SendNotification();
1562   application.Render();
1563
1564   // Set system-overlay actor to touchable
1565   TouchEventData touchData;
1566   TouchEventDataFunctor touchFunctor( touchData );
1567   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1568
1569   // Set stage actor to receive the gesture
1570   SignalData data;
1571   GestureReceivedFunctor functor(data);
1572
1573   PanGestureDetector detector = PanGestureDetector::New();
1574   detector.Attach(stageActor);
1575   detector.DetectedSignal().Connect(&application, functor);
1576
1577   Vector2 screenCoordsStart( 10.0f, 20.0f );
1578   Vector2 screenCoordsEnd( 20.0f, 20.0f );
1579
1580   // Start pan within the two actors' area
1581   application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1582   application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1583   application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1584   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1585   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1586
1587   data.Reset();
1588   touchData.Reset();
1589
1590   // Do touch in the same area
1591   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1592   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1593   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1594
1595   END_TEST;
1596 }
1597
1598 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1599 {
1600   TestApplication application;
1601   Dali::Integration::Core& core = application.GetCore();
1602   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1603   systemOverlay.GetOverlayRenderTasks().CreateTask();
1604
1605   // SystemOverlay actor
1606   Actor systemOverlayActor = Actor::New();
1607   systemOverlayActor.SetSize(100.0f, 100.0f);
1608   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1609   systemOverlay.Add(systemOverlayActor);
1610
1611   // Stage actor
1612   Actor stageActor = Actor::New();
1613   stageActor.SetSize(100.0f, 100.0f);
1614   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1615   Stage::GetCurrent().Add(stageActor);
1616
1617   // Render and notify
1618   application.SendNotification();
1619   application.Render();
1620
1621   // Set stage actor to touchable
1622   TouchEventData touchData;
1623   TouchEventDataFunctor touchFunctor( touchData );
1624   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1625
1626   // Set system-overlay actor to have the gesture
1627   SignalData data;
1628   GestureReceivedFunctor functor(data);
1629
1630   PanGestureDetector detector = PanGestureDetector::New();
1631   detector.Attach(systemOverlayActor);
1632   detector.DetectedSignal().Connect(&application, functor);
1633
1634   Vector2 screenCoordsStart( 10.0f, 20.0f );
1635   Vector2 screenCoordsEnd( 20.0f, 20.0f );
1636
1637   // Start pan within the two actors' area
1638   application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1639   application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1640   application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1641   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1642   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1643
1644   data.Reset();
1645   touchData.Reset();
1646
1647   // Do touch in the same area
1648   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1649   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1650   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1651
1652   END_TEST;
1653 }
1654
1655 int UtcDaliPanGestureAngleHandling(void)
1656 {
1657   TestApplication application;
1658
1659   PanGestureDetector detector = PanGestureDetector::New();
1660   const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1661   DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1662
1663   detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1664   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1665   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1666   {
1667     if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1668     {
1669       tet_result( TET_PASS );
1670       break;
1671     }
1672
1673     if ( iter == endIter )
1674     {
1675       tet_printf("%s, angle not added\n", TEST_LOCATION );
1676       tet_result( TET_FAIL );
1677     }
1678   }
1679
1680   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1681   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1682
1683   // Remove something not in the container.
1684   detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1685   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1686
1687   detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1688   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1689   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1690   {
1691     if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1692     {
1693       tet_printf("%s, angle not removed\n", TEST_LOCATION );
1694       tet_result( TET_FAIL );
1695       break;
1696     }
1697   }
1698
1699   detector.ClearAngles();
1700   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1701   END_TEST;
1702 }
1703
1704 inline float RadiansToDegrees( float radian )
1705 {
1706   return radian * 180.0f / Math::PI;
1707 }
1708
1709 int UtcDaliPanGestureAngleOutOfRange(void)
1710 {
1711   TestApplication application;
1712
1713   PanGestureDetector detector = PanGestureDetector::New();
1714   const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1715   DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1716
1717   //
1718   // Angle
1719   //
1720
1721   detector.AddAngle( Degree(180.0f) );
1722   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1723   detector.ClearAngles();
1724
1725   detector.AddAngle( Degree(190.0f) );
1726   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1727   detector.ClearAngles();
1728
1729   detector.AddAngle( Degree(-190.0f) );
1730   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1731   detector.ClearAngles();
1732
1733   detector.AddAngle( Degree(350.0f) );
1734   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1735   detector.ClearAngles();
1736
1737   detector.AddAngle( Degree(-350.0f) );
1738   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1739   detector.ClearAngles();
1740
1741   detector.AddAngle( Degree(370.0f) );
1742   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1743   detector.ClearAngles();
1744
1745   detector.AddAngle( Degree(-370.0f) );
1746   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1747   detector.ClearAngles();
1748
1749   //
1750   // Threshold
1751   //
1752
1753   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1754   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1755   detector.ClearAngles();
1756
1757   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1758   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1759   detector.ClearAngles();
1760
1761   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1762   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1763   detector.ClearAngles();
1764
1765   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1766   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1767   detector.ClearAngles();
1768   END_TEST;
1769 }
1770
1771 int UtcDaliPanGestureAngleProcessing(void)
1772 {
1773   TestApplication application;
1774
1775   Actor parent = Actor::New();
1776   parent.SetSize(100.0f, 100.0f);
1777   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1778   Stage::GetCurrent().Add(parent);
1779
1780   Actor child = Actor::New();
1781   child.SetSize(100.0f, 100.0f);
1782   child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1783   parent.Add(child);
1784
1785   // Render and notify
1786   application.SendNotification();
1787   application.Render();
1788
1789   // Parent detector only requires up pans
1790   PanGestureDetector parentDetector = PanGestureDetector::New();
1791   parentDetector.Attach( parent );
1792   parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1793   SignalData parentData;
1794   GestureReceivedFunctor parentFunctor(parentData);
1795   parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1796
1797   // Child detector only requires right pans
1798   PanGestureDetector childDetector = PanGestureDetector::New();
1799   childDetector.Attach( child );
1800   childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1801   SignalData childData;
1802   GestureReceivedFunctor childFunctor(childData);
1803   childDetector.DetectedSignal().Connect(&application, childFunctor);
1804
1805   // Generate an Up pan gesture, only parent should receive it.
1806   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1807   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1808   DALI_TEST_EQUALS( true,  parentData.functorCalled, TEST_LOCATION );
1809   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1810   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1811   parentData.Reset();
1812   childData.Reset();
1813
1814   // Generate a Right pan gesture, only child should receive it.
1815   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1816   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1817   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1818   DALI_TEST_EQUALS( true,  childData.functorCalled,  TEST_LOCATION );
1819   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1820   parentData.Reset();
1821   childData.Reset();
1822
1823   // Generate a Down pan gesture, no one should receive it.
1824   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1825   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1826   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1827   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1828   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1829   parentData.Reset();
1830   childData.Reset();
1831
1832   // Generate a Left pan gesture, no one should receive it.
1833   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1834   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1835   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1836   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1837   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1838   parentData.Reset();
1839   childData.Reset();
1840   END_TEST;
1841 }
1842
1843 int UtcDaliPanGestureDirectionHandling(void)
1844 {
1845   TestApplication application;
1846
1847   PanGestureDetector detector = PanGestureDetector::New();
1848   const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1849   DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1850
1851   detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1852   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1853   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1854   {
1855     if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1856     {
1857       tet_result( TET_PASS );
1858       break;
1859     }
1860
1861     if ( iter == endIter )
1862     {
1863       tet_printf("%s, angle not added\n", TEST_LOCATION );
1864       tet_result( TET_FAIL );
1865     }
1866   }
1867
1868   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1869   {
1870     if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1871     {
1872       tet_result( TET_PASS );
1873       break;
1874     }
1875
1876     if ( iter == endIter )
1877     {
1878       tet_printf("%s, angle not added\n", TEST_LOCATION );
1879       tet_result( TET_FAIL );
1880     }
1881   }
1882
1883   // Remove something not in the container.
1884   detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1885   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1886
1887   detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1888   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1889   END_TEST;
1890 }
1891
1892 int UtcDaliPanGestureDirectionProcessing(void)
1893 {
1894   TestApplication application;
1895
1896   Actor parent = Actor::New();
1897   parent.SetSize(100.0f, 100.0f);
1898   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1899   Stage::GetCurrent().Add(parent);
1900
1901   Actor child = Actor::New();
1902   child.SetSize(100.0f, 100.0f);
1903   child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1904   parent.Add(child);
1905
1906   // Render and notify
1907   application.SendNotification();
1908   application.Render();
1909
1910   // Parent detector only requires vertical panning
1911   PanGestureDetector parentDetector = PanGestureDetector::New();
1912   parentDetector.Attach( parent );
1913   parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1914   SignalData parentData;
1915   GestureReceivedFunctor parentFunctor(parentData);
1916   parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1917
1918   // Child detector only requires horizontal panning
1919   PanGestureDetector childDetector = PanGestureDetector::New();
1920   childDetector.Attach( child );
1921   childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1922   SignalData childData;
1923   GestureReceivedFunctor childFunctor(childData);
1924   childDetector.DetectedSignal().Connect(&application, childFunctor);
1925
1926   // Generate an Up pan gesture, only parent should receive it.
1927   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1928   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1929   DALI_TEST_EQUALS( true,  parentData.functorCalled, TEST_LOCATION );
1930   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1931   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1932   parentData.Reset();
1933   childData.Reset();
1934
1935   // Generate a Right pan gesture, only child should receive it.
1936   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1937   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1938   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1939   DALI_TEST_EQUALS( true,  childData.functorCalled,  TEST_LOCATION );
1940   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1941   parentData.Reset();
1942   childData.Reset();
1943
1944   // Generate a Down pan gesture, only parent should receive it.
1945   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1946   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1947   DALI_TEST_EQUALS( true,  parentData.functorCalled, TEST_LOCATION );
1948   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1949   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1950   parentData.Reset();
1951   childData.Reset();
1952
1953   // Generate a Left pan gesture, only child should receive it.
1954   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1955   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1956   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1957   DALI_TEST_EQUALS( true,  childData.functorCalled,  TEST_LOCATION );
1958   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1959   parentData.Reset();
1960   childData.Reset();
1961
1962   // Generate a pan at -45 degrees, no one should receive it.
1963   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1964   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1965   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1966   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1967   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1968   parentData.Reset();
1969   childData.Reset();
1970
1971   // Generate a pan at 45 degrees, no one should receive it.
1972   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1973   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
1974   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1975   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1976   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1977   parentData.Reset();
1978   childData.Reset();
1979
1980   // Generate a pan at 135 degrees, no one should receive it.
1981   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1982   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1983   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1984   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1985   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1986   parentData.Reset();
1987   childData.Reset();
1988
1989   // Generate a pan at -135 degrees, no one should receive it.
1990   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1991   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
1992   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1993   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1994   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1995   parentData.Reset();
1996   childData.Reset();
1997   END_TEST;
1998 }
1999
2000 int UtcDaliPanGestureSetProperties(void)
2001 {
2002   TestApplication application;
2003   TestRenderController& renderController( application.GetRenderController() );
2004   Integration::SetPanGesturePredictionMode(0);
2005
2006   Actor actor = Actor::New();
2007   actor.SetSize(100.0f, 100.0f);
2008   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2009   Stage::GetCurrent().Add(actor);
2010
2011   // Add a pan detector
2012   PanGestureDetector detector = PanGestureDetector::New();
2013   detector.Attach( actor );
2014   SignalData data;
2015   GestureReceivedFunctor functor( data );
2016   detector.DetectedSignal().Connect( &application, functor );
2017
2018   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2019
2020   ConstraintData constraintData;
2021   actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2022                                                              Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2023                                                              Source( detector, PanGestureDetector::LOCAL_POSITION ),
2024                                                              Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2025                                                              PanConstraint( constraintData ) ) );
2026
2027   // Render and notify
2028   application.SendNotification();
2029   application.Render();
2030
2031   renderController.Initialize();
2032   DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2033
2034   Vector2 screenPosition( 20.0f, 20.0f );
2035   Vector2 screenDisplacement( 1.0f, 1.0f );
2036   Vector2 localPosition( 21.0f, 21.0f );
2037   Vector2 localDisplacement( 0.5f, 0.5f );
2038
2039   PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) );
2040   DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2041
2042   // Render and notify
2043   application.SendNotification();
2044   application.Render();
2045
2046   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2047   DALI_TEST_EQUALS( constraintData.screenPosition,     screenPosition,     TEST_LOCATION );
2048   DALI_TEST_EQUALS( constraintData.localPosition,      localPosition,      TEST_LOCATION );
2049   DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2050   DALI_TEST_EQUALS( constraintData.localDisplacement,  localDisplacement,  TEST_LOCATION );
2051   constraintData.Reset();
2052   END_TEST;
2053 }
2054
2055 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2056 {
2057   TestApplication application;
2058   Integration::SetPanGesturePredictionMode(0);
2059
2060   Actor actor = Actor::New();
2061   actor.SetSize(100.0f, 100.0f);
2062   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2063   Stage::GetCurrent().Add(actor);
2064
2065   // Add a pan detector
2066   PanGestureDetector detector = PanGestureDetector::New();
2067   detector.Attach( actor );
2068   SignalData data;
2069   GestureReceivedFunctor functor( data );
2070   detector.DetectedSignal().Connect( &application, functor );
2071
2072   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2073
2074   ConstraintData constraintData;
2075   actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2076                                                              Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2077                                                              Source( detector, PanGestureDetector::LOCAL_POSITION ),
2078                                                              Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2079                                                              PanConstraint( constraintData ) ) );
2080
2081   // Render and notify
2082   application.SendNotification();
2083   application.Render();
2084
2085   Vector2 previousPosition( 20.0f, 20.0f );
2086   Vector2 currentPosition( 20.0f, 10.0f );
2087   application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2088   application.ProcessEvent( GeneratePan( Gesture::Started,  previousPosition, currentPosition, 10 ) );
2089   DALI_TEST_EQUALS( true,  data.functorCalled, TEST_LOCATION );
2090
2091   Vector2 screenPosition( 100.0f, 20.0f );
2092   Vector2 localPosition( 110.0f, 110.0f );
2093
2094   PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2095
2096   // Render and notify
2097   application.SendNotification();
2098   application.Render();
2099
2100   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2101   DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2102   DALI_TEST_EQUALS( constraintData.localPosition,  currentPosition, 0.1f, TEST_LOCATION );
2103   constraintData.Reset();
2104   END_TEST;
2105 }
2106
2107 int UtcDaliPanGesturePropertyIndices(void)
2108 {
2109   TestApplication application;
2110   PanGestureDetector detector = PanGestureDetector::New();
2111
2112   Property::IndexContainer indices;
2113   detector.GetPropertyIndices( indices );
2114   DALI_TEST_CHECK( ! indices.empty() );
2115   DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );
2116   END_TEST;
2117 }