[dali_2.3.27] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pinch-gesture / pinch-gesture-impl.h
1 #ifndef DALI_INTERNAL_PINCH_GESTURE_H
2 #define DALI_INTERNAL_PINCH_GESTURE_H
3
4 /*
5  * Copyright (c) 2021 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/internal/event/events/gesture-impl.h>
23 #include <dali/public-api/events/pinch-gesture.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/object/base-object.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class PinchGesture;
32 using PinchGesturePtr = IntrusivePtr<PinchGesture>;
33
34 /**
35  * @copydoc Dali::PinchGesture
36  */
37 class PinchGesture final : public Gesture
38 {
39 public:
40   /**
41    * @brief Default constructor
42    */
43   PinchGesture(GestureState state)
44   : Gesture(GestureType::PINCH, state)
45   {
46   }
47
48   PinchGesture(const PinchGesture&) = delete;            ///< Deleted copy constructor
49   PinchGesture(PinchGesture&&)      = delete;            ///< Deleted move constructor
50   PinchGesture& operator=(const PinchGesture&) = delete; ///< Deleted copy assignment operator
51   PinchGesture& operator=(PinchGesture&&) = delete;      ///< Deleted move assignment operator
52
53   /**
54    * @brief The scale factor from the start of the pinch gesture till the latest pinch gesture.
55    * @param[in] scale The scale to set.
56    */
57   inline void SetScale(float scale)
58   {
59     mScale = scale;
60   }
61
62   /**
63    * @copydoc Dali::PinchGesture::GetScale()
64    */
65   inline float GetScale() const
66   {
67     return mScale;
68   }
69
70   /**
71    * @brief The speed at which the user is moving their fingers.
72    * @param[in] speed The speed to set.
73    */
74   inline void SetSpeed(float speed)
75   {
76     mSpeed = speed;
77   }
78
79   /**
80    * @copydoc Dali::PinchGesture::GetSpeed()
81    */
82   inline float GetSpeed() const
83   {
84     return mSpeed;
85   }
86
87   /**
88    * @brief The center point of the two points that caused the pinch gesture in screen coordinates.
89    * @param[in] screenCenterPoint The point in screen coordinates to set.
90    */
91   inline void SetScreenCenterPoint(const Vector2& screenCenterPoint)
92   {
93     mScreenCenterPoint = screenCenterPoint;
94   }
95
96   /**
97    * @copydoc Dali::PinchGesture::GetScreenCenterPoint()
98    */
99   inline const Vector2& GetScreenCenterPoint() const
100   {
101     return mScreenCenterPoint;
102   }
103
104   /**
105    * @brief The center point of the two points that caused the pinch gesture in local actor coordinates.
106    * @param[in] localCenterPoint The point in local actor coordinates to set.
107    */
108   inline void SetLocalCenterPoint(const Vector2& localCenterPoint)
109   {
110     mLocalCenterPoint = localCenterPoint;
111   }
112
113   /**
114    * @copydoc Dali::PinchGesture::GetLocalCenterPoint()
115    */
116   inline const Vector2& GetLocalCenterPoint() const
117   {
118     return mLocalCenterPoint;
119   }
120
121 private:
122   /**
123    * @brief Virtual destructor
124    *
125    * A reference counted object may only be deleted by calling Unreference()
126    */
127   ~PinchGesture() override = default;
128
129 private:
130   Vector2 mScreenCenterPoint;
131   Vector2 mLocalCenterPoint;
132   float   mScale{0.0f};
133   float   mSpeed{0.0f};
134 };
135
136 } // namespace Internal
137
138 // Helpers for public-api forwarding methods
139
140 inline Internal::PinchGesture& GetImplementation(Dali::PinchGesture& pinchGesture)
141 {
142   DALI_ASSERT_ALWAYS(pinchGesture && "pinchGesture handle is empty");
143
144   BaseObject& object = pinchGesture.GetBaseObject();
145
146   return static_cast<Internal::PinchGesture&>(object);
147 }
148
149 inline const Internal::PinchGesture& GetImplementation(const Dali::PinchGesture& pinchGesture)
150 {
151   DALI_ASSERT_ALWAYS(pinchGesture && "pinchGesture handle is empty");
152
153   const BaseObject& object = pinchGesture.GetBaseObject();
154
155   return static_cast<const Internal::PinchGesture&>(object);
156 }
157
158 } // namespace Dali
159
160 #endif // DALI_INTERNAL_PINCH_GESTURE_H