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