2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/render-task-list-integ.h>
26 #include <dali-test-suite-utils.h>
31 ///////////////////////////////////////////////////////////////////////////////
38 : functorCalled(false),
39 voidFunctorCalled(false),
40 receivedGesture(Gesture::Started)
45 functorCalled = false;
46 voidFunctorCalled = false;
48 receivedGesture.state = Gesture::Started;
54 bool voidFunctorCalled;
55 LongPressGesture receivedGesture;
59 // Functor that sets the data when called
60 struct GestureReceivedFunctor
62 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
64 void operator()(Actor actor, const LongPressGesture& pan)
66 signalData.functorCalled = true;
67 signalData.receivedGesture = pan;
68 signalData.pressedActor = actor;
73 signalData.voidFunctorCalled = true;
76 SignalData& signalData;
80 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition, uint32_t time )
82 Integration::TouchEvent touchEvent;
83 Integration::Point point;
84 point.SetState( state );
86 point.SetScreenPosition( screenPosition );
87 point.SetDeviceClass( Device::Class::TOUCH );
88 point.SetDeviceSubclass( Device::Subclass::NONE );
89 touchEvent.points.push_back( point );
90 touchEvent.time = time;
94 Integration::TouchEvent GenerateDoubleTouch( PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time )
96 Integration::TouchEvent touchEvent;
97 Integration::Point point;
98 point.SetState( stateA );
100 point.SetScreenPosition( screenPositionA );
101 point.SetDeviceClass( Device::Class::TOUCH );
102 point.SetDeviceSubclass( Device::Subclass::NONE );
103 touchEvent.points.push_back( point );
104 point.SetScreenPosition( screenPositionB );
105 point.SetState( stateB);
106 point.SetDeviceId(7);
107 touchEvent.points.push_back( point );
108 touchEvent.time = time;
115 ///////////////////////////////////////////////////////////////////////////////
118 int UtcDaliLongPressGestureRecognizerBasicNoAction(void)
120 TestApplication application;
122 LongPressGestureDetector detector = LongPressGestureDetector::New();
124 Actor actor = Actor::New();
125 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
126 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
127 application.GetScene().Add(actor);
130 application.SendNotification();
131 application.Render();
133 detector.Attach(actor);
136 GestureReceivedFunctor functor(data);
137 detector.DetectedSignal().Connect(&application, functor);
139 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
141 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
143 application.SendNotification();
145 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
150 int UtcDaliLongPressGestureRecognizerBasic(void)
152 TestApplication application;
154 LongPressGestureDetector detector = LongPressGestureDetector::New();
156 Actor actor = Actor::New();
157 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
158 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
159 application.GetScene().Add(actor);
162 application.SendNotification();
163 application.Render();
165 detector.Attach(actor);
168 GestureReceivedFunctor functor(data);
169 detector.DetectedSignal().Connect(&application, functor);
171 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
173 application.GetPlatform().TriggerTimer();
175 application.SendNotification();
177 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
182 int UtcDaliLongPressGestureRecognizerTooShortWait(void)
184 TestApplication application;
186 LongPressGestureDetector detector = LongPressGestureDetector::New();
188 Actor actor = Actor::New();
189 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
190 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
191 application.GetScene().Add(actor);
194 application.SendNotification();
195 application.Render();
197 detector.Attach(actor);
200 GestureReceivedFunctor functor(data);
201 detector.DetectedSignal().Connect(&application, functor);
203 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
205 application.SendNotification();
207 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
212 int UtcDaliLongPressGestureRecognizerTooFewPoints(void)
214 TestApplication application;
216 LongPressGestureDetector detector = LongPressGestureDetector::New();
218 detector.SetTouchesRequired(2,2);
220 Actor actor = Actor::New();
221 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
222 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
223 application.GetScene().Add(actor);
226 application.SendNotification();
227 application.Render();
229 detector.Attach(actor);
232 GestureReceivedFunctor functor(data);
233 detector.DetectedSignal().Connect(&application, functor);
235 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
237 // There should be no function to call
238 application.GetPlatform().TriggerTimer();
240 application.SendNotification();
242 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
247 int UtcDaliLongPressGestureRecognizerTooManyPoints(void)
249 TestApplication application;
251 LongPressGestureDetector detector = LongPressGestureDetector::New();
253 Actor actor = Actor::New();
254 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
255 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
256 application.GetScene().Add(actor);
259 application.SendNotification();
260 application.Render();
262 detector.Attach(actor);
265 GestureReceivedFunctor functor(data);
266 detector.DetectedSignal().Connect(&application, functor);
268 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
269 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 151 ) );
271 // There should be no function to call as the double touch should have cancelled it
272 application.GetPlatform().TriggerTimer();
274 application.SendNotification();
276 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
281 int UtcDaliLongPressGestureRecognizerMultiplePointsMoving(void)
283 TestApplication application;
285 LongPressGestureDetector detector = LongPressGestureDetector::New();
287 detector.SetTouchesRequired(2,2);
289 Actor actor = Actor::New();
290 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
291 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
292 application.GetScene().Add(actor);
295 application.SendNotification();
296 application.Render();
298 detector.Attach(actor);
301 GestureReceivedFunctor functor(data);
302 detector.DetectedSignal().Connect(&application, functor);
304 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 0.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 151 ) );
305 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 10.0f ), PointState::MOTION, Vector2( 20.0f, 80.0f ), 153 ) );
306 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 70.0f ), 155 ) );
307 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 30.0f ), PointState::MOTION, Vector2( 20.0f, 60.0f ), 157 ) );
308 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), PointState::MOTION, Vector2( 20.0f, 50.0f ), 159 ) );
309 application.ProcessEvent( GenerateDoubleTouch( PointState::STATIONARY, Vector2( 20.0f, 40.0f ), PointState::UP, Vector2( 20.0f, 50.0f ), 160 ) );
310 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 40.0f ), 161 ) );
312 application.GetPlatform().TriggerTimer();
314 application.SendNotification();
316 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
321 int UtcDaliLongPressGestureRecognizerMultiplePointsLongPress(void)
323 TestApplication application;
325 LongPressGestureDetector detector = LongPressGestureDetector::New();
327 Actor actor = Actor::New();
328 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
329 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
330 application.GetScene().Add(actor);
333 application.SendNotification();
334 application.Render();
336 detector.Attach(actor);
337 detector.SetTouchesRequired(2,2); // Set after we've attached forcing us to change things internally
340 GestureReceivedFunctor functor(data);
341 detector.DetectedSignal().Connect(&application, functor);
343 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 40.0f ), 140 ) );
344 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 40.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
346 application.GetPlatform().TriggerTimer();
348 application.ProcessEvent( GenerateDoubleTouch( PointState::STATIONARY, Vector2( 20.0f, 20.0f ), PointState::UP, Vector2( 20.0f, 90.0f ), 760 ) );
349 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 761 ) );
351 application.SendNotification();
353 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
358 int UtcDaliLongPressGestureRecognizerMultipleDetectors(void)
360 TestApplication application;
362 Actor actor = Actor::New();
363 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
364 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
365 application.GetScene().Add(actor);
367 Actor actor2 = Actor::New();
368 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
369 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
370 actor2.SetProperty( Actor::Property::POSITION_X, 100.0f);
371 application.GetScene().Add(actor2);
374 application.SendNotification();
375 application.Render();
377 LongPressGestureDetector detector = LongPressGestureDetector::New();
378 detector.Attach(actor);
380 LongPressGestureDetector detector2 = LongPressGestureDetector::New(2);
381 detector2.Attach(actor2);
384 GestureReceivedFunctor functor(data);
385 detector.DetectedSignal().Connect(&application, functor);
388 GestureReceivedFunctor functor2(data2);
389 detector2.DetectedSignal().Connect(&application, functor2);
391 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
393 application.GetPlatform().TriggerTimer();
395 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 700 ) );
397 application.SendNotification();
399 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
400 DALI_TEST_EQUALS(true, actor == data.pressedActor, TEST_LOCATION);
402 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
404 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 120.0f, 40.0f ), 800 ) );
405 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 120.0f, 40.0f ), PointState::DOWN, Vector2( 120.0f, 90.0f ), 805 ) );
407 application.GetPlatform().TriggerTimer();
409 application.SendNotification();
411 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
412 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);