Use touch consumed return to set whether we process a gesture or not
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PinchGestureDetector.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <test-touch-utils.h>
26 #include <test-touch-data-utils.h>
27
28 using namespace Dali;
29
30 void utc_dali_pinch_gesture_detector_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_pinch_gesture_detector_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////
41 namespace
42 {
43
44 // Stores data that is populated in the callback and will be read by the TET cases
45 struct SignalData
46 {
47   SignalData()
48   : functorCalled(false),
49     voidFunctorCalled(false),
50     receivedGesture(Gesture::Started)
51   {}
52
53   void Reset()
54   {
55     functorCalled = false;
56     voidFunctorCalled = false;
57
58     receivedGesture.state = Gesture::Started;
59     receivedGesture.scale = 0.0f;
60     receivedGesture.speed = 0.0f;
61     receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
62     receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
63
64     pinchedActor.Reset();
65   }
66
67   bool functorCalled;
68   bool voidFunctorCalled;
69   PinchGesture receivedGesture;
70   Actor pinchedActor;
71 };
72
73 // Functor that sets the data when called
74 struct GestureReceivedFunctor
75 {
76   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
77
78   void operator()(Actor actor, const PinchGesture& pinch)
79   {
80     signalData.functorCalled = true;
81     signalData.receivedGesture = pinch;
82     signalData.pinchedActor = actor;
83   }
84
85   void operator()()
86   {
87     signalData.voidFunctorCalled = true;
88   }
89
90   SignalData& signalData;
91 };
92
93 // Functor that removes the gestured actor from stage
94 struct UnstageActorFunctor : public GestureReceivedFunctor
95 {
96   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
97   : GestureReceivedFunctor( data ),
98     stateToUnstage( stateToUnstage ),
99     scene( scene )
100   {
101   }
102
103   void operator()( Actor actor, const PinchGesture& pinch )
104   {
105     GestureReceivedFunctor::operator()( actor, pinch );
106
107     if ( pinch.state == stateToUnstage )
108     {
109       scene.Remove( actor );
110     }
111   }
112
113   Gesture::State& stateToUnstage;
114   Integration::Scene scene;
115 };
116
117 // Functor for receiving a touch event
118 struct TouchEventFunctor
119 {
120   bool operator()(Actor actor, const TouchEvent& touch)
121   {
122     return false;
123   }
124 };
125
126 } // anon namespace
127
128 ///////////////////////////////////////////////////////////////////////////////
129
130 int UtcDaliPinchGestureDetectorConstructor(void)
131 {
132   TestApplication application;
133
134   PinchGestureDetector detector;
135   DALI_TEST_CHECK(!detector);
136   END_TEST;
137 }
138
139 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
140 {
141   TestApplication application;
142
143   PinchGestureDetector detector = PinchGestureDetector::New();;
144
145   PinchGestureDetector copy( detector );
146   DALI_TEST_CHECK( detector );
147   END_TEST;
148 }
149
150 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
151 {
152   TestApplication application;
153
154   PinchGestureDetector detector = PinchGestureDetector::New();;
155
156   PinchGestureDetector assign;
157   assign = detector;
158   DALI_TEST_CHECK( detector );
159
160   DALI_TEST_CHECK( detector == assign );
161   END_TEST;
162 }
163
164 int UtcDaliPinchGestureDetectorNew(void)
165 {
166   TestApplication application;
167
168   PinchGestureDetector detector = PinchGestureDetector::New();
169
170   DALI_TEST_CHECK(detector);
171
172   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
173   Actor actor = Actor::New();
174   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
175   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
176   application.GetScene().Add(actor);
177
178   // Render and notify
179   application.SendNotification();
180   application.Render();
181
182   detector.Attach(actor);
183
184   Integration::TouchEvent touchEvent(1);
185   Integration::Point point;
186   point.SetDeviceId( 1 );
187   point.SetState( PointState::DOWN );
188   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
189   touchEvent.AddPoint(point);
190   application.ProcessEvent(touchEvent);
191
192   Integration::Point point2;
193   point.SetDeviceId( 1 );
194   point.SetState( PointState::DOWN );
195   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
196   touchEvent.AddPoint(point2);
197   application.ProcessEvent(touchEvent);
198   END_TEST;
199 }
200
201 int UtcDaliPinchGestureDetectorDownCast(void)
202 {
203   TestApplication application;
204   tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
205
206   PinchGestureDetector detector = PinchGestureDetector::New();
207
208   BaseHandle object(detector);
209
210   PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
211   DALI_TEST_CHECK(detector2);
212
213   PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
214   DALI_TEST_CHECK(detector3);
215
216   BaseHandle unInitializedObject;
217   PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
218   DALI_TEST_CHECK(!detector4);
219
220   PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
221   DALI_TEST_CHECK(!detector5);
222
223   GestureDetector detector6 = PinchGestureDetector::New();
224   PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
225   DALI_TEST_CHECK(detector7);
226   END_TEST;
227 }
228
229 // Negative test case for a method
230 int UtcDaliPinchGestureSignalReceptionNegative(void)
231 {
232   TestApplication application;
233
234   Actor actor = Actor::New();
235   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
236   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
237   application.GetScene().Add(actor);
238
239   // Render and notify
240   application.SendNotification();
241   application.Render();
242
243   SignalData data;
244   GestureReceivedFunctor functor(data);
245
246   PinchGestureDetector detector = PinchGestureDetector::New();
247   detector.Attach(actor);
248   detector.DetectedSignal().Connect(&application, functor);
249
250   // Do a pinch outside actor's area
251   TestStartPinch( application,  Vector2( 112.0f, 62.0f ), Vector2( 112.0f, 162.0f ),
252                                 Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ), 100 );
253
254   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
255
256   // Continue pinch into actor's area - we should still not receive the signal
257   data.Reset();
258   TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
259                                   Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
260
261   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
262
263   // Stop pinching - we should still not receive the signal
264   data.Reset();
265   TestEndPinch( application,  Vector2( 6.0f, 6.0f ), Vector2( 18.0f, 18.0f ),
266                               Vector2( 10.0f, 8.0f ), Vector2( 14.0f, 16.0f ), 300 );
267
268   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
269   END_TEST;
270 }
271
272 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
273 {
274   TestApplication application;
275
276   Actor actor = Actor::New();
277   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
278   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
279   application.GetScene().Add(actor);
280
281   // Render and notify
282   application.SendNotification();
283   application.Render();
284
285   SignalData data;
286   GestureReceivedFunctor functor(data);
287
288   PinchGestureDetector detector = PinchGestureDetector::New();
289   detector.Attach(actor);
290   detector.DetectedSignal().Connect(&application, functor);
291
292   // Start pan within the actor's area
293   TestStartPinch( application,  Vector2( 5.0f, 20.0f ), Vector2( 35.0f, 20.0f ),
294                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
295   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
296   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
297   DALI_TEST_EQUALS(0.666f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
298   DALI_TEST_EQUALS(66.666f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
299   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
300
301   // Continue the pan within the actor's area - we should still receive the signal
302   data.Reset();
303   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
304                                   Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 400 );
305   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
306   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
307   DALI_TEST_EQUALS(0.2666f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
308   DALI_TEST_EQUALS(80.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
309   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
310
311   // Pan Gesture leaves actor's area - we should still receive the signal
312   data.Reset();
313   TestContinuePinch( application, Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
314                                   Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ), 1000 );
315   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
316   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
317   DALI_TEST_EQUALS(1.333f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
318   DALI_TEST_EQUALS(213.333f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
319   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
320
321   // Gesture ends - we would receive a finished state
322   data.Reset();
323   TestEndPinch( application,  Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ),
324                               Vector2( 305.0f, 10.0f ), Vector2( 315.0f, 10.0f ), 1500);
325   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
326   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
327   DALI_TEST_EQUALS(0.333f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
328   DALI_TEST_EQUALS(600.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
329   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
330   END_TEST;
331 }
332
333 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
334 {
335   TestApplication application;
336
337   Actor actor = Actor::New();
338   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
339   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
340   application.GetScene().Add(actor);
341
342   // Render and notify
343   application.SendNotification();
344   application.Render();
345
346   SignalData data;
347   GestureReceivedFunctor functor(data);
348
349   PinchGestureDetector detector = PinchGestureDetector::New();
350   detector.Attach(actor);
351   detector.DetectedSignal().Connect(&application, functor);
352
353   // Start pinch within the actor's area
354   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
355                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
356   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
357   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
358   DALI_TEST_EQUALS(0.555f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
359   DALI_TEST_EQUALS(106.667f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
360   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
361
362   // Continue the pinch within the actor's area - we should still receive the signal
363   data.Reset();
364   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
365                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
366   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
367   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
368   DALI_TEST_EQUALS(0.277f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
369   DALI_TEST_EQUALS(66.666f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
370   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
371
372   // Gesture ends within actor's area - we would receive a finished state
373   data.Reset();
374   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
375                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
376   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
377   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
378   DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
379   DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
380   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
381   END_TEST;
382 }
383
384 int UtcDaliPinchGestureSignalReceptionDetach(void)
385 {
386   TestApplication application;
387
388   Actor actor = Actor::New();
389   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
390   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
391   application.GetScene().Add(actor);
392
393   // Render and notify
394   application.SendNotification();
395   application.Render();
396
397   SignalData data;
398   GestureReceivedFunctor functor(data);
399
400   PinchGestureDetector detector = PinchGestureDetector::New();
401   detector.Attach(actor);
402   detector.DetectedSignal().Connect(&application, functor);
403
404   // Start pinch within the actor's area
405   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
406                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
407   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
408   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
409
410
411   // Continue the pinch within the actor's area - we should still receive the signal
412   data.Reset();
413   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
414                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
415   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
416   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
417
418   // Gesture ends within actor's area
419   data.Reset();
420   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
421                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
422   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
423   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
424
425   // Detach actor
426   detector.DetachAll();
427
428   // Ensure we are no longer signalled
429   data.Reset();
430   TestGeneratePinch(  application );
431   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
432   END_TEST;
433 }
434
435 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
436 {
437   TestApplication application;
438
439   Actor actor = Actor::New();
440   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
441   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
442   application.GetScene().Add(actor);
443
444   // Render and notify
445   application.SendNotification();
446   application.Render();
447
448   SignalData data;
449   GestureReceivedFunctor functor(data);
450
451   PinchGestureDetector detector = PinchGestureDetector::New();
452   detector.Attach(actor);
453   detector.DetectedSignal().Connect(&application, functor);
454
455   // Start pinch within the actor's area
456   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
457                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
458   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
459   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
460
461   // Continue the pinch within the actor's area - we should still receive the signal
462   data.Reset();
463   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
464                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
465   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
466   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
467
468   // Detach actor during the pinch, we should not receive the next event
469   detector.DetachAll();
470
471   // Gesture ends within actor's area
472   data.Reset();
473   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
474                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
475   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
476   END_TEST;
477 }
478
479 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
480 {
481   TestApplication application;
482
483   SignalData data;
484   GestureReceivedFunctor functor(data);
485
486   PinchGestureDetector detector = PinchGestureDetector::New();
487   detector.DetectedSignal().Connect(&application, functor);
488
489   // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
490   // is destroyed.
491   Actor tempActor = Actor::New();
492   tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
493   tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
494   application.GetScene().Add(tempActor);
495   detector.Attach(tempActor);
496
497   // Actor lifetime is scoped
498   {
499     Actor actor = Actor::New();
500     actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
501     actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
502     application.GetScene().Add(actor);
503
504     // Render and notify
505     application.SendNotification();
506     application.Render();
507
508     detector.Attach(actor);
509
510     // Start pinch within the actor's area
511     TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
512                                   Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
513     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
514     DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
515
516     // Continue the pinch within the actor's area - we should still receive the signal
517     data.Reset();
518     TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
519                                     Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
520     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
521     DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
522
523     // Remove the actor from stage and reset the data
524     application.GetScene().Remove(actor);
525
526     // Render and notify
527     application.SendNotification();
528     application.Render();
529   }
530
531   // Actor should now have been destroyed
532
533   // Gesture ends within the area where the actor used to be
534   data.Reset();
535   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
536                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
537   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
538   END_TEST;
539 }
540
541 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
542 {
543   TestApplication application;
544
545   Actor actor = Actor::New();
546   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
547   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
548   application.GetScene().Add(actor);
549
550   // Render and notify a couple of times
551   application.SendNotification();
552   application.Render();
553
554   SignalData data;
555   GestureReceivedFunctor functor(data);
556
557   PinchGestureDetector detector = PinchGestureDetector::New();
558   detector.Attach(actor);
559   detector.DetectedSignal().Connect(&application, functor);
560
561   // Do an entire pinch, only check finished value
562   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
563                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
564   data.Reset();
565   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
566                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
567   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568   DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
569   DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
570   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
571
572   // Rotate actor again and render and notify
573   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
574   application.SendNotification();
575   application.Render();
576
577   // Do an entire pinch, only check finished value
578   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
579                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
580   data.Reset();
581   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
582                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
583   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
584   DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
585   DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
586   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
587
588   // Rotate actor again and render and notify
589   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
590   application.SendNotification();
591   application.Render();
592
593   // Do an entire pinch, only check finished value
594   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
595                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 4100 );
596   data.Reset();
597   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
598                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 5000);
599   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
600   DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
601   DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
602   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
603   END_TEST;
604 }
605
606 int UtcDaliPinchGestureSignalReceptionChildHit(void)
607 {
608   TestApplication application;
609
610   Actor parent = Actor::New();
611   parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
612   parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
613   application.GetScene().Add(parent);
614
615   // Set child to completely cover parent.
616   // Change rotation of child to be different from parent so that we can check if our local coordinate
617   // conversion of the parent actor is correct.
618   Actor child = Actor::New();
619   child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
620   child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
621   child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
622   child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
623   parent.Add(child);
624
625   TouchEventFunctor touchFunctor;
626   child.TouchedSignal().Connect(&application, touchFunctor);
627
628   // Render and notify
629   application.SendNotification();
630   application.Render();
631
632   SignalData data;
633   GestureReceivedFunctor functor(data);
634
635   PinchGestureDetector detector = PinchGestureDetector::New();
636   detector.Attach(parent);
637   detector.DetectedSignal().Connect(&application, functor);
638
639   // Do an entire pan, only check finished value - hits child area but parent should still receive it
640   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
641                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
642   data.Reset();
643   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
644                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
645   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
646   DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
647   DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
648   DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
649   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
650
651   // Attach child and generate same touch points to yield same results
652   // (Also proves that you can detach and then re-attach another actor)
653   detector.Attach(child);
654   detector.Detach(parent);
655
656   // Do an entire pan, only check finished value
657   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
658                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
659   data.Reset();
660   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
661                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
662   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
663   DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
664   DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
665   DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
666   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
667   END_TEST;
668 }
669
670 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
671 {
672   TestApplication application;
673
674   Actor first = Actor::New();
675   first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
676   first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
677   application.GetScene().Add(first);
678
679   Actor second = Actor::New();
680   second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
681   second.SetProperty( Actor::Property::POSITION_X, 100.0f);
682   second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
683   application.GetScene().Add(second);
684
685   // Render and notify
686   application.SendNotification();
687   application.Render();
688
689   SignalData data;
690   GestureReceivedFunctor functor(data);
691
692   PinchGestureDetector detector = PinchGestureDetector::New();
693   detector.Attach(first);
694   detector.Attach(second);
695   detector.DetectedSignal().Connect(&application, functor);
696
697   // Start pinch within second actor's area
698   TestStartPinch( application,  Vector2( 102.0f, 20.0f ), Vector2( 138.0f, 20.0f ),
699                                     Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ), 100 );
700   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
701   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
702
703   // Pinch moves into first actor's area - second actor should receive the pinch
704   data.Reset();
705   TestContinuePinch( application, Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ),
706                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
707   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
708   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
709
710   // Detach the second actor during the pinch, we should not receive the next event
711   detector.Detach(second);
712
713   // Gesture ends within actor's area
714   data.Reset();
715   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
716                               Vector2( 119.0f, 20.0f ), Vector2( 121.0f, 20.0f ), 3000);
717   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
718   END_TEST;
719 }
720
721 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
722 {
723   TestApplication application;
724
725   Actor actor = Actor::New();
726   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
727   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
728   application.GetScene().Add(actor);
729
730   // Render and notify
731   application.SendNotification();
732   application.Render();
733
734   SignalData data;
735   GestureReceivedFunctor functor(data);
736
737   PinchGestureDetector detector = PinchGestureDetector::New();
738   detector.Attach(actor);
739   detector.DetectedSignal().Connect(&application, functor);
740
741   // Start pinch in actor's area
742   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
743                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
744   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
745
746   // Pan continues within actor's area
747   data.Reset();
748   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
749                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
750   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
751
752   // Actor become invisible - actor should not receive the next pinch
753   actor.SetProperty( Actor::Property::VISIBLE,false);
754
755   // Render and notify
756   application.SendNotification();
757   application.Render();
758
759   // Gesture ends within actor's area
760   data.Reset();
761   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
762                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
763   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
764   END_TEST;
765 }
766
767 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
768 {
769   TestApplication application;
770
771   Actor actor = Actor::New();
772   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
773   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
774   application.GetScene().Add(actor);
775
776   Actor actor2 = Actor::New();
777   actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
778   actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
779   application.GetScene().Add(actor2);
780
781   // Render and notify
782   application.SendNotification();
783   application.Render();
784
785   // Attach actor to one detector
786   SignalData firstData;
787   GestureReceivedFunctor firstFunctor(firstData);
788   PinchGestureDetector firstDetector = PinchGestureDetector::New();
789   firstDetector.Attach(actor);
790   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
791
792   // Attach actor to another detector
793   SignalData secondData;
794   GestureReceivedFunctor secondFunctor(secondData);
795   PinchGestureDetector secondDetector = PinchGestureDetector::New();
796   secondDetector.Attach(actor);
797   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
798
799   // Add second actor to second detector, when we remove the actor, this will make sure that this
800   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
801   // functor should still not be called (which is what we're also testing).
802   secondDetector.Attach(actor2);
803
804   // Pinch in actor's area - both detector's functors should be called
805   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
806                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
807   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
808   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
809
810   // Pinch continues in actor's area - both detector's functors should be called
811   firstData.Reset();
812   secondData.Reset();
813   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
814                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
815   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
816   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
817
818   // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
819   firstDetector.Detach(actor);
820   firstData.Reset();
821   secondData.Reset();
822   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
823                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
824   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
825   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
826
827   // New pinch on actor, only secondDetector has actor attached
828   firstData.Reset();
829   secondData.Reset();
830   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
831                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
832   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
833   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
834
835   // Detach actor from secondDetector
836   secondDetector.Detach(actor);
837   firstData.Reset();
838   secondData.Reset();
839   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
840                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
841   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
842   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
843   END_TEST;
844 }
845
846 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
847 {
848   TestApplication application;
849
850   Actor actor1 = Actor::New();
851   actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
852   actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
853   application.GetScene().Add(actor1);
854   SignalData data1;
855   GestureReceivedFunctor functor1(data1);
856   PinchGestureDetector detector1 = PinchGestureDetector::New();
857   detector1.Attach(actor1);
858   detector1.DetectedSignal().Connect(&application, functor1);
859
860   Actor actor2 = Actor::New();
861   actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
862   actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
863   actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
864   application.GetScene().Add(actor2);
865   SignalData data2;
866   GestureReceivedFunctor functor2(data2);
867   PinchGestureDetector detector2 = PinchGestureDetector::New();
868   detector2.Attach(actor2);
869   detector2.DetectedSignal().Connect(&application, functor2);
870
871   // Render and notify
872   application.SendNotification();
873   application.Render();
874
875   // Start pan in actor1's area, only data1 should be set
876   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
877                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
878   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
879   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
880   END_TEST;
881 }
882
883 int UtcDaliPinchGestureActorUnstaged(void)
884 {
885   TestApplication application;
886
887   Actor actor = Actor::New();
888   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
889   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
890   application.GetScene().Add(actor);
891
892   // Render and notify
893   application.SendNotification();
894   application.Render();
895
896   // State to remove actor in.
897   Gesture::State stateToUnstage( Gesture::Started );
898
899   // Attach actor to detector
900   SignalData data;
901   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
902   PinchGestureDetector detector = PinchGestureDetector::New();
903   detector.Attach(actor);
904   detector.DetectedSignal().Connect( &application, functor );
905
906   // Emit signals
907   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
908                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
909   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
910   data.Reset();
911   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
912                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
913   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
914   data.Reset();
915
916   // Render and notify
917   application.SendNotification();
918   application.Render();
919
920   // Re-add actor to stage
921   application.GetScene().Add(actor);
922
923   // Render and notify
924   application.SendNotification();
925   application.Render();
926
927   // Change state to Gesture::Continuing to remove
928   stateToUnstage = Gesture::Continuing;
929
930   // Emit signals
931   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
932                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
933   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
934   data.Reset();
935   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
936                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
937   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
938   data.Reset();
939   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
940                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
941   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
942   data.Reset();
943
944   // Render and notify
945   application.SendNotification();
946   application.Render();
947
948   // Re-add actor to stage
949   application.GetScene().Add(actor);
950
951   // Render and notify
952   application.SendNotification();
953   application.Render();
954
955   // Change state to Gesture::Continuing to remove
956   stateToUnstage = Gesture::Finished;
957
958   // Emit signals
959   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
960                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
961   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
962   data.Reset();
963   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
964                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
965   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
966   data.Reset();
967   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
968                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
969   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
970   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
971   END_TEST;
972 }
973
974 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
975 {
976   TestApplication application;
977
978   Actor actor = Actor::New();
979   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
980   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
981   application.GetScene().Add(actor);
982
983   // Create and add a second actor so that GestureDetector destruction does not come into play.
984   Actor dummyActor( Actor::New() );
985   dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
986   dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
987   dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
988   application.GetScene().Add(dummyActor);
989
990   // Render and notify
991   application.SendNotification();
992   application.Render();
993
994   // State to remove actor in.
995   Gesture::State stateToUnstage( Gesture::Started );
996
997   // Attach actor to detector
998   SignalData data;
999   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1000   PinchGestureDetector detector = PinchGestureDetector::New();
1001   detector.Attach(actor);
1002   detector.Attach(dummyActor);
1003   detector.DetectedSignal().Connect( &application, functor );
1004
1005   // Here we are testing a Started actor which is removed in the Started callback, but then added back
1006   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
1007   // position, we should still not be signalled.
1008
1009   // Emit signals
1010   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1011                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1012   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1013   data.Reset();
1014
1015   // Render and notify
1016   application.SendNotification();
1017   application.Render();
1018
1019   // Re add to the stage, we should not be signalled
1020   application.GetScene().Add(actor);
1021
1022   // Render and notify
1023   application.SendNotification();
1024   application.Render();
1025
1026   // Continue signal emission
1027   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1028                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1029   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1030   data.Reset();
1031   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1032                                 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1033   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1034   data.Reset();
1035
1036   // Here we delete an actor in started, we should not receive any subsequent signalling.
1037
1038   // Emit signals
1039   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1040                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1041   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1042   data.Reset();
1043
1044   // Render and notify
1045   application.SendNotification();
1046   application.Render();
1047
1048   // Delete actor as well
1049   actor.Reset();
1050
1051   // Render and notify
1052   application.SendNotification();
1053   application.Render();
1054
1055   // Continue signal emission
1056   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1057                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
1058   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1059   data.Reset();
1060   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1061                                 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
1062   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1063   END_TEST;
1064 }
1065
1066 int UtcDaliPinchGestureLayerConsumesTouch(void)
1067 {
1068   TestApplication application;
1069
1070   Actor actor = Actor::New();
1071   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1072   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1073   application.GetScene().Add(actor);
1074
1075   // Add a detector
1076   SignalData data;
1077   GestureReceivedFunctor functor(data);
1078   PinchGestureDetector detector = PinchGestureDetector::New();
1079   detector.Attach(actor);
1080   detector.DetectedSignal().Connect( &application, functor );
1081
1082   // Add a layer to overlap the actor
1083   Layer layer = Layer::New();
1084   layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1085   layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1086   application.GetScene().Add( layer );
1087   layer.RaiseToTop();
1088
1089   // Render and notify
1090   application.SendNotification();
1091   application.Render();
1092
1093   // Emit signals, should receive
1094   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1095                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1096   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1097                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1098   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1099   data.Reset();
1100
1101   // Set layer to consume all touch
1102   layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1103
1104   // Render and notify
1105   application.SendNotification();
1106   application.Render();
1107
1108   // Emit the same signals again, should not receive
1109   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1110                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1111   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1112                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 2000);
1113   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1114   data.Reset();
1115
1116   END_TEST;
1117 }
1118
1119 int UtcDaliPinchGestureInterruptedWhenTouchConsumed(void)
1120 {
1121   TestApplication application;
1122
1123   Actor actor = Actor::New();
1124   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1125   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1126   application.GetScene().Add(actor);
1127
1128   bool consume = false;
1129   TouchDataFunctorConsumeSetter touchFunctor(consume);
1130   actor.TouchSignal().Connect(&application,touchFunctor);
1131
1132   // Render and notify
1133   application.SendNotification();
1134   application.Render();
1135
1136   SignalData data;
1137   GestureReceivedFunctor functor(data);
1138
1139   PinchGestureDetector detector = PinchGestureDetector::New();
1140   detector.Attach(actor);
1141   detector.DetectedSignal().Connect(&application, functor);
1142
1143   // Start gesture within the actor's area, we should receive the pinch as the touch is NOT being consumed
1144   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1145                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1146
1147   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1148   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
1149   data.Reset();
1150
1151   // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
1152   consume = true;
1153
1154   TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
1155                                   Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
1156
1157   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1158   DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
1159   data.Reset();
1160
1161   // Start another pinch, we should not even get the callback this time
1162   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1163                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1164   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1165
1166   END_TEST;
1167 }
1168