From 40a0a894d0ba7ec4c875295252ef366a23e37688 Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Tue, 9 May 2023 15:37:02 +0900 Subject: [PATCH] Add Touch source type for gesture Change-Id: Ib3782eb3e7125e045b469b314641de4cec7901c6 --- .../src/dali/utc-Dali-TapGestureDetector.cpp | 64 +++++++++++++++++++--- dali/internal/event/events/gesture-recognizer.h | 12 +++- dali/public-api/events/gesture-enumerations.h | 3 +- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp b/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp index 4ca3e3a..6eeab2f 100644 --- a/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp +++ b/automated-tests/src/dali/utc-Dali-TapGestureDetector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -143,6 +143,21 @@ Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector return touchEvent; } +Integration::TouchEvent GenerateSingleMouse(PointState::Type state, const Vector2& screenPosition, int source, uint32_t time) +{ + Integration::TouchEvent touchEvent; + Integration::Point point; + point.SetState(state); + point.SetDeviceId(4); + point.SetScreenPosition(screenPosition); + point.SetDeviceClass(Device::Class::MOUSE); + point.SetDeviceSubclass(Device::Subclass::NONE); + point.SetMouseButton(static_cast(source)); + touchEvent.points.push_back(point); + touchEvent.time = time; + return touchEvent; +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -1056,7 +1071,7 @@ int UtcDaliTapGestureWhenGesturePropargation(void) END_TEST; } -int UtcDaliTapGestureGetSourceType(void) +int UtcDaliTapGestureGetSourceTypeWithMouse(void) { TestApplication application; @@ -1077,8 +1092,8 @@ int UtcDaliTapGestureGetSourceType(void) detector.DetectedSignal().Connect(&application, functor); // Emit a down signal with MouseButton - application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 1, 100)); - application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 1, 120)); + application.ProcessEvent(GenerateSingleMouse(PointState::DOWN, Vector2(20.0f, 20.0f), 1, 100)); + application.ProcessEvent(GenerateSingleMouse(PointState::UP, Vector2(20.0f, 20.0f), 1, 120)); application.SendNotification(); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); @@ -1088,8 +1103,8 @@ int UtcDaliTapGestureGetSourceType(void) data.Reset(); // Emit a down signal with MouseButton - application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 3, 1300)); - application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 3, 1320)); + application.ProcessEvent(GenerateSingleMouse(PointState::DOWN, Vector2(20.0f, 20.0f), 3, 1300)); + application.ProcessEvent(GenerateSingleMouse(PointState::UP, Vector2(20.0f, 20.0f), 3, 1320)); application.SendNotification(); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); @@ -1099,8 +1114,8 @@ int UtcDaliTapGestureGetSourceType(void) data.Reset(); // Emit a down signal with MouseButton - application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 2, 1900)); - application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 2, 1920)); + application.ProcessEvent(GenerateSingleMouse(PointState::DOWN, Vector2(20.0f, 20.0f), 2, 1900)); + application.ProcessEvent(GenerateSingleMouse(PointState::UP, Vector2(20.0f, 20.0f), 2, 1920)); application.SendNotification(); DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); @@ -1110,6 +1125,39 @@ int UtcDaliTapGestureGetSourceType(void) END_TEST; } +int UtcDaliTapGestureGetSourceTypeWithTouch(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); + + // Render and notify + application.SendNotification(); + application.Render(); + + SignalData data; + GestureReceivedFunctor functor(data); + + TapGestureDetector detector = TapGestureDetector::New(); + detector.Attach(actor); + detector.DetectedSignal().Connect(&application, functor); + + // Emit a down signal with touch + application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 1, 100)); + application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 1, 120)); + application.SendNotification(); + + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::TOUCH, TEST_LOCATION); + + data.Reset(); + + END_TEST; +} + int UtcDaliTapGestureReceiveAllTapEvents(void) { TestApplication application; diff --git a/dali/internal/event/events/gesture-recognizer.h b/dali/internal/event/events/gesture-recognizer.h index 7aafb36..0bc013d 100644 --- a/dali/internal/event/events/gesture-recognizer.h +++ b/dali/internal/event/events/gesture-recognizer.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_GESTURE_RECOGNIZER_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,15 @@ public: MouseButton::Type mouseButton = point.GetMouseButton(); if(mouseButton != MouseButton::INVALID) { - mSourceType = GestureSourceType::MOUSE; + Device::Class::Type type = point.GetDeviceClass(); + if(type == Device::Class::Type::MOUSE) + { + mSourceType = GestureSourceType::MOUSE; + } + else if(type == Device::Class::Type::TOUCH) + { + mSourceType = GestureSourceType::TOUCH; + } switch(mouseButton) { case MouseButton::PRIMARY: diff --git a/dali/public-api/events/gesture-enumerations.h b/dali/public-api/events/gesture-enumerations.h index 4600467..5e2b13c 100644 --- a/dali/public-api/events/gesture-enumerations.h +++ b/dali/public-api/events/gesture-enumerations.h @@ -2,7 +2,7 @@ #define DALI_GESTURE_ENUMERATIONS_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,6 +61,7 @@ enum class GestureSourceType : int8_t { INVALID, ///< invalid data MOUSE, ///< mouse + TOUCH, ///< touch }; /** -- 2.7.4