use modern construct 'override' in the derive class.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture / pan-gesture-impl.h
1 #ifndef DALI_INTERNAL_PAN_GESTURE_H
2 #define DALI_INTERNAL_PAN_GESTURE_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 class PanGesture;
34 using PanGesturePtr = IntrusivePtr<PanGesture>;
35
36 /**
37  * @copydoc Dali::PanGesture
38  */
39 class PanGesture final : public Gesture
40 {
41 public:
42
43   /**
44    * @brief Default constructor
45    */
46   PanGesture(GestureState state)
47   : Gesture(GestureType::PAN, state)
48   {
49   }
50
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
55
56   /**
57    * @brief Set The velocity at which the user is moving their fingers.
58    * @param[in] velocity The Vector2 in local coordinates to set.
59    */
60   inline void SetVelocity(const Vector2& velocity)
61   {
62     mVelocity = velocity;
63   }
64
65   /**
66    * @copydoc Dali::PanGesture::GetVelocity()
67    */
68   inline const Vector2& GetVelocity() const
69   {
70     return mVelocity;
71   }
72
73   /**
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.
77    */
78   inline void SetDisplacement(const Vector2& displacement)
79   {
80     mDisplacement = displacement;
81   }
82
83   /**
84    * @copydoc Dali::PanGesture::GetDisplacement()
85    */
86   inline const Vector2& GetDisplacement() const
87   {
88     return mDisplacement;
89   }
90
91   /**
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.
94    */
95   inline void SetPosition(const Vector2& position)
96   {
97     mPosition = position;
98   }
99
100   /**
101    * @copydoc Dali::PanGesture::GetPosition()
102    */
103   inline const Vector2& GetPosition() const
104   {
105     return mPosition;
106   }
107
108   /**
109    * @brief Set The velocity at which the user is moving their fingers.
110    * @param[in] screenVelocity The Vector2 in screen coordinates to set.
111    */
112   inline void SetScreenVelocity(const Vector2& screenVelocity)
113   {
114     mScreenVelocity = screenVelocity;
115   }
116
117   /**
118    * @copydoc Dali::PanGesture::GetScreenVelocity()
119    */
120   inline const Vector2& GetScreenVelocity() const
121   {
122     return mScreenVelocity;
123   }
124
125   /**
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.
129    */
130   inline void SetScreenDisplacement(const Vector2& screenDisplacement)
131   {
132     mScreenDisplacement = screenDisplacement;
133   }
134
135   /**
136    * @copydoc Dali::PanGesture::GetScreenDisplacement()
137    */
138   inline const Vector2& GetScreenDisplacement() const
139   {
140     return mScreenDisplacement;
141   }
142
143   /**
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.
146    */
147   inline void SetScreenPosition(const Vector2& screenPosition)
148   {
149     mScreenPosition = screenPosition;
150   }
151
152   /**
153    * @copydoc Dali::PanGesture::GetScreenPosition()
154    */
155   inline const Vector2& GetScreenPosition() const
156   {
157     return mScreenPosition;
158   }
159
160   /**
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.
163    */
164   inline void SetNumberOfTouches(uint32_t numberOfTouches)
165   {
166     mNumberOfTouches = numberOfTouches;
167   }
168
169   /**
170    * @brief The total number of fingers touching the screen in a pan gesture.
171    */
172   inline uint32_t GetNumberOfTouches() const
173   {
174     return mNumberOfTouches;
175   }
176
177   /**
178    * @copydoc Dali::PanGesture::GetSpeed()
179    */
180   inline float GetSpeed() const
181   {
182     return mVelocity.Length();
183   }
184
185   /**
186    * @copydoc Dali::PanGesture::GetDistance()
187    */
188   inline float GetDistance() const
189   {
190     return mDisplacement.Length();
191   }
192
193   /**
194    * @copydoc Dali::PanGesture::GetScreenSpeed()
195    */
196   inline float GetScreenSpeed() const
197   {
198     return mScreenVelocity.Length();
199   }
200
201   /**
202    * @copydoc Dali::PanGesture::GetScreenDistance()
203    */
204   inline float GetScreenDistance() const
205   {
206     return mScreenDisplacement.Length();
207   }
208
209 private:
210
211   /**
212    * @brief Virtual destructor
213    *
214    * A reference counted object may only be deleted by calling Unreference()
215    */
216   ~PanGesture() override = default;
217
218 private:
219   Vector2 mVelocity;
220   Vector2 mDisplacement;
221   Vector2 mPosition;
222   Vector2 mScreenVelocity;
223   Vector2 mScreenDisplacement;
224   Vector2 mScreenPosition;
225   uint32_t mNumberOfTouches{1u};
226 };
227
228 } // namespace Internal
229
230 // Helpers for public-api forwarding methods
231
232 inline Internal::PanGesture& GetImplementation( Dali::PanGesture& panGesture )
233 {
234   DALI_ASSERT_ALWAYS( panGesture && "panGesture handle is empty" );
235
236   BaseObject& object = panGesture.GetBaseObject();
237
238   return static_cast< Internal::PanGesture& >( object );
239 }
240
241 inline const Internal::PanGesture& GetImplementation( const Dali::PanGesture& panGesture )
242 {
243   DALI_ASSERT_ALWAYS( panGesture && "panGesture handle is empty" );
244
245   const BaseObject& object = panGesture.GetBaseObject();
246
247   return static_cast< const Internal::PanGesture& >( object );
248 }
249
250 } // namespace Dali
251
252 #endif // DALI_INTERNAL_PAN_GESTURE_H