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