845b714cb9e2912220d14d3245d8fb58acdd82ef
[platform/core/uifw/dali-core.git] / dali / internal / event / events / 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) 2017 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
27 namespace Dali
28 {
29
30 struct TouchEvent;
31 struct Radian;
32
33 namespace Internal
34 {
35
36 class PanGestureDetector;
37 typedef IntrusivePtr<PanGestureDetector> PanGestureDetectorPtr;
38 typedef DerivedGestureDetectorContainer<PanGestureDetector>::type PanGestureDetectorContainer;
39
40 namespace SceneGraph
41 {
42 class PanGesture;
43 }
44
45 /**
46  * @copydoc Dali::PanGestureDetector
47  */
48 class PanGestureDetector : public GestureDetector
49 {
50 public: // Typedefs
51
52   typedef Dali::PanGestureDetector::AngleThresholdPair AngleThresholdPair;
53   typedef std::vector<AngleThresholdPair> AngleContainer;
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   /**
64    * Construct a new PanGestureDetector.
65    */
66   PanGestureDetector();
67
68 public:
69
70   /**
71    * @copydoc Dali::PanGestureDetector::SetMinimumTouchesRequired(unsigned int)
72    */
73   void SetMinimumTouchesRequired(unsigned int minimum);
74
75   /**
76    * @copydoc Dali::PanGestureDetector::SetMaximumTouchesRequired(unsigned int)
77    */
78   void SetMaximumTouchesRequired(unsigned int maximum);
79
80   /**
81    * @copydoc Dali::PanGestureDetector::GetMinimumTouchesRequired() const
82    */
83   unsigned int GetMinimumTouchesRequired() const;
84
85   /**
86    * @copydoc Dali::PanGestureDetector::GetMaximumTouchesRequired() const
87    */
88   unsigned int GetMaximumTouchesRequired() const;
89
90   /**
91    * @copydoc Dali::PanGestureDetector::AddAngle()
92    */
93   void AddAngle( Radian angle, Radian threshold );
94
95   /**
96    * @copydoc Dali::PanGestureDetector::AddDirection()
97    */
98   void AddDirection( Radian direction, Radian threshold );
99
100   /**
101    * @copydoc Dali::PanGestureDetector::GetAngleCount()
102    */
103   size_t GetAngleCount() const;
104
105   /**
106    * @copydoc Dali::PanGestureDetector::GetAngle()
107    */
108   AngleThresholdPair GetAngle(size_t index) const;
109
110   /**
111    * @copydoc Dali::PanGestureDetector::ClearAngles()
112    */
113   void ClearAngles();
114
115   /**
116    * @copydoc Dali::PanGestureDetector::RemoveAngle()
117    */
118   void RemoveAngle( Radian angle );
119
120   /**
121    * @copydoc Dali::PanGestureDetector::RemoveDirection()
122    */
123   void RemoveDirection( Radian direction );
124
125   /**
126    * Checks whether the pan gesture detector requires a directional pan for emission.
127    * @return true, if directional panning required, false otherwise.
128    */
129   bool RequiresDirectionalPan() const;
130
131   /**
132    * Checks whether the given pan angle is allowed for this gesture detector.
133    * @param[in]  angle  The angle to check.
134    */
135   bool CheckAngleAllowed( Radian angle ) const;
136
137 public:
138
139   /**
140    * Called by the PanGestureProcessor when a pan gesture event occurs within the bounds of our
141    * attached actor.
142    * @param[in]  actor  The panned actor.
143    * @param[in]  pan    The pan gesture.
144    */
145   void EmitPanGestureSignal(Dali::Actor actor, const PanGesture& pan);
146
147   /**
148    * Called by the PanGestureProcessor to set the scene object.
149    * @param[in]  object  The scene object.
150    */
151   void SetSceneObject( const SceneGraph::PanGesture* object );
152
153 public: // Signals
154
155   /**
156    * @copydoc Dali::PanGestureDetector::DetectedSignal()
157    */
158   Dali::PanGestureDetector::DetectedSignalType& DetectedSignal()
159   {
160     return mDetectedSignal;
161   }
162
163   /**
164    * Connects a callback function with the object's signals.
165    * @param[in] object The object providing the signal.
166    * @param[in] tracker Used to disconnect the signal.
167    * @param[in] signalName The signal to connect to.
168    * @param[in] functor A newly allocated FunctorDelegate.
169    * @return True if the signal was connected.
170    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
171    */
172   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
173
174 public: // Override Pan Gesture
175
176   /**
177    * @copydoc Dali::PanGestureDetector::SetPanGestureProperties()
178    */
179   static void SetPanGestureProperties( const PanGesture& pan );
180
181 protected:
182
183   /**
184    * A reference counted object may only be deleted by calling Unreference()
185    */
186   virtual ~PanGestureDetector();
187
188 private:
189
190   // Undefined
191   PanGestureDetector(const PanGestureDetector&);
192
193   // Undefined
194   PanGestureDetector& operator=(const PanGestureDetector& rhs);
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::GetDefaultPropertyCount()
218    */
219   virtual unsigned int GetDefaultPropertyCount() const;
220
221   /**
222    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
223    */
224   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
225
226   /**
227    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
228    */
229   virtual const char* GetDefaultPropertyName(Property::Index index) const;
230
231   /**
232    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
233    */
234   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
235
236   /**
237    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
238    */
239   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
240
241   /**
242    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
243    */
244   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
245
246   /**
247    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
248    */
249   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
250
251   /**
252    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
253    */
254   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
255
256   /**
257    * @copydoc Dali::Internal::Object::SetDefaultProperty()
258    */
259   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
260
261   /**
262    * @copydoc Dali::Internal::Object::GetDefaultProperty()
263    */
264   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
265
266   /**
267    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
268    */
269   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
270
271   /**
272    * @copydoc Dali::Internal::Object::GetSceneObject()
273    */
274   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
275
276   /**
277    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
278    */
279   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
280
281   /**
282    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
283    */
284   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
285
286 private:
287
288   Dali::PanGestureDetector::DetectedSignalType mDetectedSignal;
289
290   unsigned int mMinimumTouches; ///< The minimum number of fingers required to be touching for pan.
291   unsigned int mMaximumTouches; ///< The maximum number of fingers required to be touching for pan.
292
293   AngleContainer mAngleContainer; ///< A container of all angles allowed for pan to occur.
294
295   const SceneGraph::PanGesture* mSceneObject; ///< Not owned
296
297 };
298
299 } // namespace Internal
300
301 // Helpers for public-api forwarding methods
302
303 inline Internal::PanGestureDetector& GetImplementation(Dali::PanGestureDetector& detector)
304 {
305   DALI_ASSERT_ALWAYS( detector && "PanGestureDetector handle is empty" );
306
307   BaseObject& handle = detector.GetBaseObject();
308
309   return static_cast<Internal::PanGestureDetector&>(handle);
310 }
311
312 inline const Internal::PanGestureDetector& GetImplementation(const Dali::PanGestureDetector& detector)
313 {
314   DALI_ASSERT_ALWAYS( detector && "PanGestureDetector handle is empty" );
315
316   const BaseObject& handle = detector.GetBaseObject();
317
318   return static_cast<const Internal::PanGestureDetector&>(handle);
319 }
320
321 } // namespace Dali
322
323 #endif // __DALI_INTERNAL_PAN_GESTURE_DETECTOR_H__