DALi Version 2.0.1
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture / pan-gesture-detector-impl.h
1 #ifndef DALI_INTERNAL_PAN_GESTURE_DETECTOR_H
2 #define DALI_INTERNAL_PAN_GESTURE_DETECTOR_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/events/gesture.h>
23 #include <dali/public-api/events/pan-gesture-detector.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/internal/event/events/gesture-detector-impl.h>
26 #include <dali/public-api/events/pan-gesture.h>
27
28 namespace Dali
29 {
30
31 struct TouchEvent;
32 struct Radian;
33
34 namespace Internal
35 {
36
37 class PanGestureDetector;
38 using PanGestureDetectorPtr       = IntrusivePtr<PanGestureDetector>;
39 using PanGestureDetectorContainer = DerivedGestureDetectorContainer<PanGestureDetector>::type;
40
41 namespace SceneGraph
42 {
43 class PanGesture;
44 }
45
46 /**
47  * @copydoc Dali::PanGestureDetector
48  */
49 class PanGestureDetector : public GestureDetector
50 {
51 public: // Typedefs
52   using AngleThresholdPair = Dali::PanGestureDetector::AngleThresholdPair;
53   using AngleContainer     = std::vector<AngleThresholdPair>;
54
55 public: // Creation
56
57   /**
58    * Create a new gesture detector.
59    * @return A smart-pointer to the newly allocated detector.
60    */
61   static PanGestureDetectorPtr New();
62
63 public:
64
65   /**
66    * @copydoc Dali::PanGestureDetector::SetMinimumTouchesRequired(unsigned int)
67    */
68   void SetMinimumTouchesRequired(unsigned int minimum);
69
70   /**
71    * @copydoc Dali::PanGestureDetector::SetMaximumTouchesRequired(unsigned int)
72    */
73   void SetMaximumTouchesRequired(unsigned int maximum);
74
75   /**
76    * @copydoc Dali::PanGestureDetector::GetMinimumTouchesRequired() const
77    */
78   uint32_t GetMinimumTouchesRequired() const;
79
80   /**
81    * @copydoc Dali::PanGestureDetector::GetMaximumTouchesRequired() const
82    */
83   uint32_t GetMaximumTouchesRequired() const;
84
85   /**
86    * @copydoc Dali::PanGestureDetector::AddAngle()
87    */
88   void AddAngle( Radian angle, Radian threshold );
89
90   /**
91    * @copydoc Dali::PanGestureDetector::AddDirection()
92    */
93   void AddDirection( Radian direction, Radian threshold );
94
95   /**
96    * @copydoc Dali::PanGestureDetector::GetAngleCount()
97    */
98   uint32_t GetAngleCount() const;
99
100   /**
101    * @copydoc Dali::PanGestureDetector::GetAngle()
102    */
103   AngleThresholdPair GetAngle(uint32_t index) const;
104
105   /**
106    * @copydoc Dali::PanGestureDetector::ClearAngles()
107    */
108   void ClearAngles();
109
110   /**
111    * @copydoc Dali::PanGestureDetector::RemoveAngle()
112    */
113   void RemoveAngle( Radian angle );
114
115   /**
116    * @copydoc Dali::PanGestureDetector::RemoveDirection()
117    */
118   void RemoveDirection( Radian direction );
119
120   /**
121    * Checks whether the pan gesture detector requires a directional pan for emission.
122    * @return true, if directional panning required, false otherwise.
123    */
124   bool RequiresDirectionalPan() const;
125
126   /**
127    * Checks whether the given pan angle is allowed for this gesture detector.
128    * @param[in]  angle  The angle to check.
129    */
130   bool CheckAngleAllowed( Radian angle ) const;
131
132 public:
133
134   /**
135    * Called by the PanGestureProcessor when a pan gesture event occurs within the bounds of our
136    * attached actor.
137    * @param[in]  actor  The panned actor.
138    * @param[in]  pan    The pan gesture.
139    */
140   void EmitPanGestureSignal(Dali::Actor actor, const Dali::PanGesture& pan);
141
142 public: // Signals
143
144   /**
145    * @copydoc Dali::PanGestureDetector::DetectedSignal()
146    */
147   Dali::PanGestureDetector::DetectedSignalType& DetectedSignal()
148   {
149     return mDetectedSignal;
150   }
151
152   /**
153    * Connects a callback function with the object's signals.
154    * @param[in] object The object providing the signal.
155    * @param[in] tracker Used to disconnect the signal.
156    * @param[in] signalName The signal to connect to.
157    * @param[in] functor A newly allocated FunctorDelegate.
158    * @return True if the signal was connected.
159    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
160    */
161   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
162
163 public: // Override Pan Gesture
164
165   /**
166    * @copydoc Dali::PanGestureDetector::SetPanGestureProperties()
167    */
168   static void SetPanGestureProperties( const Dali::PanGesture& pan );
169
170 protected:
171
172   /**
173    * Construct a new PanGestureDetector.
174    * @param sceneObject the scene object
175    */
176   PanGestureDetector( const SceneGraph::PanGesture& sceneObject );
177
178   /**
179    * A reference counted object may only be deleted by calling Unreference()
180    */
181   ~PanGestureDetector() override;
182
183 private:
184
185   // Undefined
186   PanGestureDetector() = delete;
187   PanGestureDetector(const PanGestureDetector&) = delete;
188   PanGestureDetector& operator=(const PanGestureDetector& rhs) = delete;
189
190   /**
191    * @return the pan gesture scene object
192    */
193   const SceneGraph::PanGesture& GetPanGestureSceneObject() const;
194
195   // From GestureDetector
196
197   /**
198    * @copydoc Dali::Internal::GestureDetector::OnActorAttach(Actor&)
199    */
200   void OnActorAttach(Actor& actor) override;
201
202   /**
203    * @copydoc Dali::Internal::GestureDetector::OnActorDetach(Actor&)
204    */
205   void OnActorDetach(Actor& actor) override;
206
207   /**
208    * @copydoc Dali::Internal::GestureDetector::OnActorDestroyed(Object&)
209    */
210   void OnActorDestroyed(Object& object) override;
211
212
213   // Default property extensions from Object
214
215   /**
216    * @copydoc Dali::Internal::Object::SetDefaultProperty()
217    */
218   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
219
220   /**
221    * @copydoc Dali::Internal::Object::GetDefaultProperty()
222    */
223   Property::Value GetDefaultProperty( Property::Index index ) const override;
224
225   /**
226    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
227    */
228   Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const override;
229
230   /**
231    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
232    */
233   const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const override;
234
235 private:
236
237   Dali::PanGestureDetector::DetectedSignalType mDetectedSignal;
238
239   unsigned int mMinimumTouches; ///< The minimum number of fingers required to be touching for pan.
240   unsigned int mMaximumTouches; ///< The maximum number of fingers required to be touching for pan.
241
242   AngleContainer mAngleContainer; ///< A container of all angles allowed for pan to occur.
243
244 };
245
246 } // namespace Internal
247
248 // Helpers for public-api forwarding methods
249
250 inline Internal::PanGestureDetector& GetImplementation(Dali::PanGestureDetector& detector)
251 {
252   DALI_ASSERT_ALWAYS( detector && "PanGestureDetector handle is empty" );
253
254   BaseObject& handle = detector.GetBaseObject();
255
256   return static_cast<Internal::PanGestureDetector&>(handle);
257 }
258
259 inline const Internal::PanGestureDetector& GetImplementation(const Dali::PanGestureDetector& detector)
260 {
261   DALI_ASSERT_ALWAYS( detector && "PanGestureDetector handle is empty" );
262
263   const BaseObject& handle = detector.GetBaseObject();
264
265   return static_cast<const Internal::PanGestureDetector&>(handle);
266 }
267
268 } // namespace Dali
269
270 #endif // DALI_INTERNAL_PAN_GESTURE_DETECTOR_H