From f329cb924a9525c4e268872c993d66fbec822b97 Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Tue, 29 May 2018 18:01:20 +0900 Subject: [PATCH] Add GetMouseButton to identify right/left mouse button click Change-Id: If2e2536851e081fc882786da1ff1595c255efae0 Signed-off-by: dongsug.song --- .../src/dali/utc-Dali-TouchDataProcessing.cpp | 60 ++++++++++++++++++++++ dali/integration-api/events/point.cpp | 18 ++++++- dali/integration-api/events/point.h | 12 +++++ dali/internal/event/events/touch-data-impl.cpp | 9 ++++ dali/internal/event/events/touch-data-impl.h | 8 +++ dali/public-api/CMakeLists.txt | 1 + dali/public-api/events/mouse-button.h | 53 +++++++++++++++++++ dali/public-api/events/touch-data.cpp | 5 ++ dali/public-api/events/touch-data.h | 12 +++++ dali/public-api/file.list | 3 +- 10 files changed, 178 insertions(+), 3 deletions(-) mode change 100644 => 100755 automated-tests/src/dali/utc-Dali-TouchDataProcessing.cpp mode change 100644 => 100755 dali/integration-api/events/point.cpp mode change 100644 => 100755 dali/integration-api/events/point.h mode change 100644 => 100755 dali/internal/event/events/touch-data-impl.cpp mode change 100644 => 100755 dali/internal/event/events/touch-data-impl.h create mode 100755 dali/public-api/events/mouse-button.h mode change 100644 => 100755 dali/public-api/events/touch-data.cpp mode change 100644 => 100755 dali/public-api/events/touch-data.h diff --git a/automated-tests/src/dali/utc-Dali-TouchDataProcessing.cpp b/automated-tests/src/dali/utc-Dali-TouchDataProcessing.cpp old mode 100644 new mode 100755 index 6250198..99c9826 --- a/automated-tests/src/dali/utc-Dali-TouchDataProcessing.cpp +++ b/automated-tests/src/dali/utc-Dali-TouchDataProcessing.cpp @@ -2010,3 +2010,63 @@ int UtcDaliTouchDataGetDeviceAPINegative(void) DALI_TEST_EQUALS( data.GetDeviceSubclass( -1 ), Device::Subclass::NONE, TEST_LOCATION ); END_TEST; } + +int UtcDaliTouchDataGetMouseButtonPositive(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + actor.SetSize(100.0f, 100.0f); + actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add(actor); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Connect to actor's touched signal + HandleData handleData; + TouchDataHandleFunctor functor( handleData ); + actor.TouchSignal().Connect( &application, functor ); + + // Emit a down signal with MouseButton + Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ); + touchEvent.points[ 0 ].SetMouseButton( static_cast< MouseButton::Type >( 3 ) ); + application.ProcessEvent( touchEvent ); + + TouchData data = handleData.touchData; + DALI_TEST_EQUALS( data.GetMouseButton( 0 ), MouseButton::SECONDARY, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTouchDataGetMouseButtonNagative(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + actor.SetSize(100.0f, 100.0f); + actor.SetAnchorPoint(AnchorPoint::TOP_LEFT); + Stage::GetCurrent().Add(actor); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Connect to actor's touched signal + HandleData handleData; + TouchDataHandleFunctor functor( handleData ); + actor.TouchSignal().Connect( &application, functor ); + + // Emit a down signal with MouseButton + Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ); + touchEvent.points[ 0 ].SetMouseButton( static_cast< MouseButton::Type >( 2 ) ); + application.ProcessEvent( touchEvent ); + + TouchData data = handleData.touchData; + DALI_TEST_EQUALS( data.GetMouseButton( 0 ), MouseButton::TERTIARY, TEST_LOCATION ); + DALI_TEST_EQUALS( data.GetMouseButton( 3 ), MouseButton::INVALID, TEST_LOCATION ); + + END_TEST; +} + diff --git a/dali/integration-api/events/point.cpp b/dali/integration-api/events/point.cpp old mode 100644 new mode 100755 index 19b44b0..7b52bc3 --- a/dali/integration-api/events/point.cpp +++ b/dali/integration-api/events/point.cpp @@ -17,6 +17,7 @@ // CLASS HEADER #include +#include namespace Dali { @@ -31,7 +32,8 @@ Point::Point() mDeviceClass( Device::Class::NONE ), mDeviceSubclass( Device::Subclass::NONE ), mPressure( 1.0f ), - mRadius( 0.0f ) + mRadius( 0.0f ), + mMouseButton( MouseButton::INVALID ) { } @@ -42,7 +44,8 @@ Point::Point( const TouchPoint& touchPoint ) mDeviceClass( Device::Class::NONE ), mDeviceSubclass( Device::Subclass::NONE ), mPressure( 1.0f ), - mRadius( 0.0f ) + mRadius( 0.0f ), + mMouseButton( MouseButton::INVALID ) { } @@ -166,6 +169,17 @@ Device::Subclass::Type Point::GetDeviceSubclass() const return mDeviceSubclass; } +MouseButton::Type Point::GetMouseButton() const +{ + return mMouseButton; +} + +void Point::SetMouseButton(MouseButton::Type button) +{ + mMouseButton = button; +} + + } // namespace Integration } // namespace Dali diff --git a/dali/integration-api/events/point.h b/dali/integration-api/events/point.h old mode 100644 new mode 100755 index d0c4f0f..9b33ed3 --- a/dali/integration-api/events/point.h +++ b/dali/integration-api/events/point.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace Dali { @@ -178,6 +179,16 @@ struct DALI_CORE_API Point */ Device::Subclass::Type GetDeviceSubclass() const; + /** + * @brief Get Mouse Button value. (ex: right/left button) + * @return The mouse button value. + */ + MouseButton::Type GetMouseButton() const; + + /** + * @brief Set Mouse Button value. (ex: right/left button) + */ + void SetMouseButton(MouseButton::Type button); public: // Not intended for Integration API developers @@ -223,6 +234,7 @@ private: Device::Subclass::Type mDeviceSubclass; float mPressure; ///< The touch pressure. float mRadius; ///< Radius of the press point, an average of the ellipse radius. + MouseButton::Type mMouseButton; /// < mouse button value. }; } // namespace Integration diff --git a/dali/internal/event/events/touch-data-impl.cpp b/dali/internal/event/events/touch-data-impl.cpp old mode 100644 new mode 100755 index 58547ea..481407a --- a/dali/internal/event/events/touch-data-impl.cpp +++ b/dali/internal/event/events/touch-data-impl.cpp @@ -177,6 +177,15 @@ Device::Subclass::Type TouchData::GetDeviceSubclass( std::size_t point ) const return Device::Subclass::NONE; } +MouseButton::Type TouchData::GetMouseButton( std::size_t point ) const +{ + if( point < mPoints.size() ) + { + return mPoints[ point ].GetMouseButton(); + } + return MouseButton::INVALID; +} + } // namsespace Internal } // namespace Dali diff --git a/dali/internal/event/events/touch-data-impl.h b/dali/internal/event/events/touch-data-impl.h old mode 100644 new mode 100755 index 15bfb4f..19e56a2 --- a/dali/internal/event/events/touch-data-impl.h +++ b/dali/internal/event/events/touch-data-impl.h @@ -172,6 +172,14 @@ public: */ Device::Subclass::Type GetDeviceSubclass( std::size_t point ) const; + /** + * @brief Get mouse's button value (ex: right/left button) + * + * @return The value of mouse button + */ + MouseButton::Type GetMouseButton( std::size_t point ) const; + + private: /// Undefined Copy constructor diff --git a/dali/public-api/CMakeLists.txt b/dali/public-api/CMakeLists.txt index 59b2839..ebd2cbe 100644 --- a/dali/public-api/CMakeLists.txt +++ b/dali/public-api/CMakeLists.txt @@ -147,6 +147,7 @@ SET(PUBLIC_API_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/events/touch-point.h ${CMAKE_CURRENT_SOURCE_DIR}/events/touch-event.h ${CMAKE_CURRENT_SOURCE_DIR}/events/touch-data.h + ${CMAKE_CURRENT_SOURCE_DIR}/events/mouse-button.h ${CMAKE_CURRENT_SOURCE_DIR}/images/buffer-image.h ${CMAKE_CURRENT_SOURCE_DIR}/images/encoded-buffer-image.h diff --git a/dali/public-api/events/mouse-button.h b/dali/public-api/events/mouse-button.h new file mode 100755 index 0000000..e6ec2a8 --- /dev/null +++ b/dali/public-api/events/mouse-button.h @@ -0,0 +1,53 @@ +#ifndef DALI_MOUSE_BUTTON_H +#define DALI_MOUSE_BUTTON_H + +/* + * Copyright (c) 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Dali +{ +/** + * @addtogroup dali_core_events + * @{ + */ + +/** + * @brief Mouse Button Type + * @SINCE_1_3.31 + */ +namespace MouseButton +{ + +/** + * @brief Enumeration for mouse button type. + * @SINCE_1_3.31 + */ +enum Type +{ + INVALID = -1, /**< No mouse button event or invalid data */ + PRIMARY = 1, /**< Primary(Left) mouse button */ + SECONDARY = 3, /**< Secondary(Right) mouse button */ + TERTIARY = 2, /**< Center(Wheel) mouse button */ +}; +} + +/** + * @} + */ +} // namespace Dali + +#endif // __DALI_MOUSE_BUTTON_H__ diff --git a/dali/public-api/events/touch-data.cpp b/dali/public-api/events/touch-data.cpp old mode 100644 new mode 100755 index a18a927..54d9a5e --- a/dali/public-api/events/touch-data.cpp +++ b/dali/public-api/events/touch-data.cpp @@ -112,6 +112,11 @@ Device::Subclass::Type TouchData::GetDeviceSubclass( std::size_t point ) const return GetImplementation( *this ).GetDeviceSubclass( point ); } +MouseButton::Type TouchData::GetMouseButton( std::size_t point ) const +{ + return GetImplementation( *this ).GetMouseButton( point ); +} + TouchData::TouchData( Internal::TouchData* internal ) : BaseHandle( internal ) { diff --git a/dali/public-api/events/touch-data.h b/dali/public-api/events/touch-data.h old mode 100644 new mode 100755 index 9a3dec5..89d00ea --- a/dali/public-api/events/touch-data.h +++ b/dali/public-api/events/touch-data.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace Dali { @@ -241,6 +242,17 @@ public: */ Device::Subclass::Type GetDeviceSubclass( std::size_t point ) const; + + /** + * @brief Get mouse device's button value (ex: right/left button) + * + * @SINCE_1_3.31 + * @param[in] point The point required + * @return The mouse button value + */ + MouseButton::Type GetMouseButton( std::size_t point ) const; + + public: // Not intended for application developers /// @cond internal diff --git a/dali/public-api/file.list b/dali/public-api/file.list index ba9f26b..1e0e443 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -151,7 +151,8 @@ public_api_core_events_header_files = \ $(public_api_src_dir)/events/tap-gesture-detector.h \ $(public_api_src_dir)/events/touch-point.h \ $(public_api_src_dir)/events/touch-event.h \ - $(public_api_src_dir)/events/touch-data.h + $(public_api_src_dir)/events/touch-data.h \ + $(public_api_src_dir)/events/mouse-button.h public_api_core_images_header_files = \ $(public_api_src_dir)/images/buffer-image.h \ -- 2.7.4