1 #ifndef DALI_INTERNAL_PAN_GESTURE_H
2 #define DALI_INTERNAL_PAN_GESTURE_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/math/vector2.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/events/pan-gesture.h>
25 #include <dali/internal/event/events/gesture-impl.h>
34 using PanGesturePtr = IntrusivePtr<PanGesture>;
37 * @copydoc Dali::PanGesture
39 class PanGesture final : public Gesture
44 * @brief Default constructor
46 PanGesture(GestureState state)
47 : Gesture(GestureType::PAN, state)
51 PanGesture(const PanGesture&) = delete; ///< Deleted copy constructor
52 PanGesture(PanGesture&&) = delete; ///< Deleted move constructor
53 PanGesture& operator=(const PanGesture&) = delete; ///< Deleted copy assignment operator
54 PanGesture& operator=(PanGesture&&) = delete; ///< Deleted move assignment operator
57 * @brief Set The velocity at which the user is moving their fingers.
58 * @param[in] velocity The Vector2 in local coordinates to set.
60 inline void SetVelocity(const Vector2& velocity)
66 * @copydoc Dali::PanGesture::GetVelocity()
68 inline const Vector2& GetVelocity() const
74 * @brief Set This is a Vector2 showing how much the user has panned (dragged) since the last pan gesture or,
75 * if the gesture has just started, then the amount panned since the user touched the screen.
76 * @param[in] displacement The Vector2 in local coordinates to set.
78 inline void SetDisplacement(const Vector2& displacement)
80 mDisplacement = displacement;
84 * @copydoc Dali::PanGesture::GetDisplacement()
86 inline const Vector2& GetDisplacement() const
92 * @brief Set This current touch position of the primary touch point in local actor coordinates.
93 * @param[in] velocity The current touch position to set.
95 inline void SetPosition(const Vector2& position)
101 * @copydoc Dali::PanGesture::GetPosition()
103 inline const Vector2& GetPosition() const
109 * @brief Set The velocity at which the user is moving their fingers.
110 * @param[in] screenVelocity The Vector2 in screen coordinates to set.
112 inline void SetScreenVelocity(const Vector2& screenVelocity)
114 mScreenVelocity = screenVelocity;
118 * @copydoc Dali::PanGesture::GetScreenVelocity()
120 inline const Vector2& GetScreenVelocity() const
122 return mScreenVelocity;
126 * @brief Set This is a Vector2 showing how much the user has panned (dragged) since the last pan gesture or,
127 * if the gesture has just started, then the amount panned since the user touched the screen.
128 * @param[in] screenDisplacement The Vector2 in screen coordinates to set.
130 inline void SetScreenDisplacement(const Vector2& screenDisplacement)
132 mScreenDisplacement = screenDisplacement;
136 * @copydoc Dali::PanGesture::GetScreenDisplacement()
138 inline const Vector2& GetScreenDisplacement() const
140 return mScreenDisplacement;
144 * @brief Set This current touch position of the primary touch point in screen coordinates.
145 * @param[in] screenPosition The Vector2 in screen coordinates to set.
147 inline void SetScreenPosition(const Vector2& screenPosition)
149 mScreenPosition = screenPosition;
153 * @copydoc Dali::PanGesture::GetScreenPosition()
155 inline const Vector2& GetScreenPosition() const
157 return mScreenPosition;
161 * @brief The total number of fingers touching the screen in a pan gesture.
162 * @param[in] numberOfTouches The total number of fingers touching the screen to set.
164 inline void SetNumberOfTouches(uint32_t numberOfTouches)
166 mNumberOfTouches = numberOfTouches;
170 * @brief The total number of fingers touching the screen in a pan gesture.
172 inline uint32_t GetNumberOfTouches() const
174 return mNumberOfTouches;
178 * @copydoc Dali::PanGesture::GetSpeed()
180 inline float GetSpeed() const
182 return mVelocity.Length();
186 * @copydoc Dali::PanGesture::GetDistance()
188 inline float GetDistance() const
190 return mDisplacement.Length();
194 * @copydoc Dali::PanGesture::GetScreenSpeed()
196 inline float GetScreenSpeed() const
198 return mScreenVelocity.Length();
202 * @copydoc Dali::PanGesture::GetScreenDistance()
204 inline float GetScreenDistance() const
206 return mScreenDisplacement.Length();
212 * @brief Virtual destructor
214 * A reference counted object may only be deleted by calling Unreference()
216 ~PanGesture() override = default;
220 Vector2 mDisplacement;
222 Vector2 mScreenVelocity;
223 Vector2 mScreenDisplacement;
224 Vector2 mScreenPosition;
225 uint32_t mNumberOfTouches{1u};
228 } // namespace Internal
230 // Helpers for public-api forwarding methods
232 inline Internal::PanGesture& GetImplementation( Dali::PanGesture& panGesture )
234 DALI_ASSERT_ALWAYS( panGesture && "panGesture handle is empty" );
236 BaseObject& object = panGesture.GetBaseObject();
238 return static_cast< Internal::PanGesture& >( object );
241 inline const Internal::PanGesture& GetImplementation( const Dali::PanGesture& panGesture )
243 DALI_ASSERT_ALWAYS( panGesture && "panGesture handle is empty" );
245 const BaseObject& object = panGesture.GetBaseObject();
247 return static_cast< const Internal::PanGesture& >( object );
252 #endif // DALI_INTERNAL_PAN_GESTURE_H