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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/devel-api/events/rotation-gesture.h>
25 #include <dali/devel-api/events/rotation-gesture-detector.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
31 void utc_dali_rotation_gesture_recognizer_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_rotation_gesture_recognizer_cleanup(void)
38 test_return_value = TET_PASS;
41 ///////////////////////////////////////////////////////////////////////////////
48 : functorCalled(false),
49 voidFunctorCalled(false),
50 receivedGesture(Gesture::Started)
55 functorCalled = false;
56 voidFunctorCalled = false;
58 receivedGesture.state = Gesture::Started;
59 receivedGesture.rotation = 0.0f;
60 receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
61 receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
67 bool voidFunctorCalled;
68 RotationGesture receivedGesture;
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
75 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
77 void operator()(Actor actor, const RotationGesture& rotation)
79 signalData.functorCalled = true;
80 signalData.receivedGesture = rotation;
81 signalData.rotatedActor = actor;
86 signalData.voidFunctorCalled = true;
89 SignalData& signalData;
92 Integration::TouchEvent GenerateDoubleTouch( PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time )
94 Integration::TouchEvent touchEvent;
95 Integration::Point point;
96 point.SetState( stateA );
97 point.SetScreenPosition( screenPositionA );
98 point.SetDeviceClass( Device::Class::TOUCH );
99 point.SetDeviceSubclass( Device::Subclass::NONE );
100 touchEvent.points.push_back( point );
101 point.SetScreenPosition( screenPositionB );
102 point.SetState( stateB);
103 touchEvent.points.push_back( point );
104 touchEvent.time = time;
111 ///////////////////////////////////////////////////////////////////////////////
113 int UtcDaliRotationGestureRecognizerMinimumTouchEvents(void)
115 TestApplication application;
117 Actor actor = Actor::New();
118 actor.SetSize( 100.0f, 100.0f );
119 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
120 Stage::GetCurrent().Add( actor );
122 application.SendNotification();
123 application.Render();
126 GestureReceivedFunctor functor( data );
128 RotationGestureDetector detector = RotationGestureDetector::New();
129 detector.Attach( actor );
130 detector.DetectedSignal().Connect( &application, functor );
133 // 2 touch events make a gesture begin
134 Integration::SetRotationGestureMinimumTouchEvents( 2 );
135 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
136 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
138 DALI_TEST_EQUALS( Gesture::Started, data.receivedGesture.state, TEST_LOCATION );
139 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
143 // 4 touch events make a gesture begin
144 Integration::SetRotationGestureMinimumTouchEvents( 4 );
145 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
146 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
148 // Check the gesture is not detected unlike previous case
149 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
154 int UtcDaliRotationGestureRecognizerMinimumTouchEventsAfterStart(void)
156 TestApplication application;
158 Actor actor = Actor::New();
159 actor.SetSize( 100.0f, 100.0f );
160 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
161 Stage::GetCurrent().Add( actor );
163 application.SendNotification();
164 application.Render();
167 GestureReceivedFunctor functor( data );
169 RotationGestureDetector detector = RotationGestureDetector::New();
170 detector.Attach( actor );
171 detector.DetectedSignal().Connect( &application, functor );
174 // > 2 touch events make a gesture begin
175 // > 4 touch events generate gestures after begin
176 Integration::SetRotationGestureMinimumTouchEvents(2);
177 Integration::SetRotationGestureMinimumTouchEventsAfterStart(6);
179 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
180 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
182 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
183 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
185 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 170 ) );
186 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 180 ) );
187 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 190 ) );
188 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 200 ) );
189 // > Test : not enough touch events to make the gesture state "Continuing"
190 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
192 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 210 ) );
193 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 220 ) );
194 // > Test : 6 touch events after start make the gesture state "Continuing"
195 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);