Tizen 2.4.0 rev3 SDK Public Release
[framework/graphics/dali.git] / dali / public-api / events / pan-gesture-detector.h
1 #ifndef __DALI_PAN_GESTURE_DETECTOR_H__
2 #define __DALI_PAN_GESTURE_DETECTOR_H__
3
4 /*
5  * Copyright (c) 2015 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-detector.h>
23 #include <dali/public-api/object/property-index-ranges.h>
24 #include <dali/public-api/signals/dali-signal.h>
25
26 namespace Dali
27 {
28
29 struct Radian;
30
31 namespace Internal DALI_INTERNAL
32 {
33 class PanGestureDetector;
34 }
35
36 struct PanGesture;
37
38 /**
39  * @addtogroup dali_core_events
40  * @{
41  */
42
43 /**
44  * @brief This class looks for panning (or dragging) gestures.
45  *
46  * The user will be pressing one or more fingers on an actor while they pan it.
47  *
48  * The application programmer can use this gesture detector as follows:
49  * @code
50  * PanGestureDetector detector = PanGestureDetector::New();
51  * detector.Attach(myActor);
52  * detector.DetectedSignal().Connect(this, &MyApplication::OnPan);
53  *
54  * // Detect pan gesture for single and double touch.
55  * detector.SetMaximumTouchesRequired(2);
56  * @endcode
57  *
58  * @since_tizen 2.4
59  * @see PanGesture
60  *
61  */
62 class DALI_IMPORT_API PanGestureDetector : public GestureDetector
63 {
64 public:
65
66   /**
67    * @brief An enumeration of properties belonging to the PanGestureDetector class.
68    * @since_tizen 2.4
69    */
70   struct Property
71   {
72     enum
73     {
74       SCREEN_POSITION = DEFAULT_GESTURE_DETECTOR_PROPERTY_START_INDEX, ///< type Vector2 @since_tizen 2.4
75       SCREEN_DISPLACEMENT,                                             ///< type Vector2 @since_tizen 2.4
76       SCREEN_VELOCITY,                                                 ///< type Vector2 @since_tizen 2.4
77       LOCAL_POSITION,                                                  ///< type Vector2 @since_tizen 2.4
78       LOCAL_DISPLACEMENT,                                              ///< type Vector2 @since_tizen 2.4
79       LOCAL_VELOCITY,                                                  ///< type Vector2 @since_tizen 2.4
80       PANNING,                                                         ///< type bool @since_tizen 2.4
81     };
82   };
83
84   // Typedefs
85   typedef Signal< void ( Actor, const PanGesture& ) > DetectedSignalType; ///< Pan gesture detected signal type @since_tizen 2.4
86
87   // Directional Pan
88   typedef std::pair< Radian, Radian > AngleThresholdPair; ///< Range of angles for a direction @since_tizen 2.4
89
90   static const Radian DIRECTION_LEFT;       ///< For a left pan (-PI Radians).
91   static const Radian DIRECTION_RIGHT;      ///< For a right pan (0 Radians).
92   static const Radian DIRECTION_UP;         ///< For an up pan (-0.5 * PI Radians).
93   static const Radian DIRECTION_DOWN;       ///< For a down pan (0.5 * PI Radians).
94   static const Radian DIRECTION_HORIZONTAL; ///< For a left and right pan (PI Radians). Useful for AddDirection().
95   static const Radian DIRECTION_VERTICAL;   ///< For an up and down pan (-0.5 * PI Radians). Useful for AddDirection().
96
97   static const Radian DEFAULT_THRESHOLD;    ///< The default threshold is PI * 0.25 radians (or 45 degrees).
98
99 public: // Creation & Destruction
100
101   /**
102    * @brief Create an uninitialized PanGestureDetector; this can be initialized with PanGestureDetector::New().
103    *
104    * Calling member functions with an uninitialized PanGestureDetector handle is not allowed.
105    * @since_tizen 2.4
106    */
107   PanGestureDetector();
108
109   /**
110    * @brief Create an initialized PanGestureDetector.
111    *
112    * @since_tizen 2.4
113    * @return A handle to a newly allocated Dali resource.
114    */
115   static PanGestureDetector New();
116
117   /**
118    * @brief Downcast a handle to PanGestureDetector handle.
119    *
120    * If handle points to a PanGestureDetector object the
121    * downcast produces valid handle. If not the returned handle is left uninitialized.
122    * @since_tizen 2.4
123    * @param[in] handle Handle to an object
124    * @return Handle to a PanGestureDetector object or an uninitialized handle
125    */
126   static PanGestureDetector DownCast( BaseHandle handle );
127
128   /**
129    * @brief Destructor
130    *
131    * This is non-virtual since derived Handle types must not contain data or virtual methods.
132    * @since_tizen 2.4
133    */
134   ~PanGestureDetector();
135
136   /**
137    * @brief This copy constructor is required for (smart) pointer semantics.
138    *
139    * @since_tizen 2.4
140    * @param [in] handle A reference to the copied handle
141    */
142   PanGestureDetector(const PanGestureDetector& handle);
143
144   /**
145    * @brief This assignment operator is required for (smart) pointer semantics.
146    *
147    * @since_tizen 2.4
148    * @param [in] rhs  A reference to the copied handle
149    * @return A reference to this
150    */
151   PanGestureDetector& operator=(const PanGestureDetector& rhs);
152
153 public: // Setters
154
155   /**
156    * @brief This is the minimum number of touches required for the pan gesture to be detected.
157    *
158    * @since_tizen 2.4
159    * @param[in]  minimum  Minimum touches required.
160    * @pre The gesture detector has been initialized.
161    * @note The default minimum is '1'.
162    */
163   void SetMinimumTouchesRequired(unsigned int minimum);
164
165   /**
166    * @brief This is the maximum number of touches required for the pan gesture to be detected.
167    *
168    * @since_tizen 2.4
169    * @param[in]  maximum  Maximum touches required.
170    * @pre The gesture detector has been initialized.
171    * @note The default maximum is '1'.
172    */
173   void SetMaximumTouchesRequired(unsigned int maximum);
174
175 public: // Getters
176
177   /**
178    * @brief Retrieves the minimum number of touches required for the pan gesture to be detected.
179    *
180    * @since_tizen 2.4
181    * @return The minimum touches required.
182    * @pre The gesture detector has been initialized.
183    */
184   unsigned int GetMinimumTouchesRequired() const;
185
186   /**
187    * @brief Retrieves the maximum number of touches required for the pan gesture to be detected.
188    *
189    * @since_tizen 2.4
190    * @return The maximum touches required.
191    * @pre The gesture detector has been initialized.
192    */
193   unsigned int GetMaximumTouchesRequired() const;
194
195 public: // Directional Panning
196
197   /**
198    * @brief The pan gesture is only emitted if the pan occurs in the direction specified by this method with a +/- threshold allowance.
199    *
200    * The angle is from -180 -> 0 -> 180 degrees (or -M_PI -> 0 -> M_PI in radians) i.e:
201    *
202    * @code
203    *           -90.0f ( -0.5f * PI )
204    *                     |
205    *                     |
206    * 180.0f ( PI ) ------------- 0.0f ( 0.0f )
207    *                     |
208    *                     |
209    *            90.0f ( 0.5f * PI )
210    * @endcode
211    *
212    * If an angle of 0.0 degrees is specified and the threshold is 45 degrees then the acceptable
213    * direction range is from -45 to 45 degrees.
214    *
215    * @since_tizen 2.4
216    * @param[in]  angle      The angle that pan should be allowed.
217    * @param[in]  threshold  The threshold around that angle.
218    *
219    * @pre The gesture detector has been initialized.
220    * @note The angle added using this API is only checked when the gesture first starts, after that,
221    *       this detector will emit the gesture regardless of what angle the pan is moving.
222    * @note The user can add as many angles as they require.
223    * @note If an angle outside the range above is given, then it is wrapped within the range, i.e.
224    *       190 degrees becomes -170 degrees and 370 degrees becomes 10 degrees.
225    * @note As long as you specify the type, you can also pass in a Dali::Degree to this method.
226    * @note If no threshold is provided, then the default threshold (PI * 0.25) is used.
227    * @note If the threshold is greater than PI, then PI will be used as the threshold.
228    *
229    */
230   void AddAngle( Radian angle, Radian threshold = DEFAULT_THRESHOLD );
231
232   /**
233    * @brief A helper method for adding bi-directional angles where the pan should take place.
234    *
235    * In other words, if 0 is requested, then PI will also be added so that we have both left and
236    * right scrolling.
237    *
238    * @since_tizen 2.4
239    * @param[in]  direction  The direction of panning required.
240    * @param[in]  threshold  The threshold.
241    *
242    * @pre The gesture detector has been initialized.
243    *
244    * @note If a direction outside the range above is given, then it is wrapped within the range, i.e.
245    *       190 degrees becomes -170 degrees and 370 degrees becomes 10 degrees.
246    * @note If no threshold is provided, then the default threshold (PI * 0.25) is used.
247    * @note If the threshold is greater than PI, then PI will be used as the threshold.
248    * @note As long as you specify the type, you can also pass in a Dali::Degree to this method.
249    *
250    * @see AddAngle
251    */
252   void AddDirection( Radian direction, Radian threshold = DEFAULT_THRESHOLD );
253
254   /**
255    * @brief Returns the count of angles that this pan gesture detector emits a signal.
256    *
257    * @since_tizen 2.4
258    * @return The count.
259    * @pre The gesture detector has been initialized.
260    */
261   size_t GetAngleCount() const;
262
263   /**
264    * @brief Returns the angle by index that this pan gesture detector emits a signal.
265    *
266    * @since_tizen 2.4
267    * @return An angle threshold pair, or a zero valued angle pair when index is invalid.
268    * @pre The gesture detector has been initialized.
269    * @pre The index is less than GetAngleCount()
270    */
271   AngleThresholdPair GetAngle(size_t index) const;
272
273   /**
274    * @brief Clears any directional angles that are used by the gesture detector.
275    *
276    * After this, the pan gesture
277    * will be emitted for a pan in ANY direction.
278    * @since_tizen 2.4
279    * @pre The gesture detector has been initialized.
280    */
281   void ClearAngles();
282
283   /**
284    * @brief Removes the angle specified from the container.
285    *
286    * @since_tizen 2.4
287    * @param[in]  angle  The angle to remove.
288    * @pre The gesture detector has been initialized.
289    * @note This will only remove the first instance of the angle found from the container.
290    * @note If an angle outside the range in AddAngle() is given, then the value is wrapped within
291    *       the range and that is removed.
292    */
293   void RemoveAngle( Radian angle );
294
295   /**
296    * @brief Removes the two angles that make up the direction from the container.
297    *
298    * @since_tizen 2.4
299    * @param[in]  direction  The direction to remove.
300    * @pre The gesture detector has been initialized.
301    * @note If a direction outside the range in AddAngle() is given, then the value is wrapped within
302    *       the range and that is removed.
303    */
304   void RemoveDirection( Radian direction );
305
306 public: // Signals
307
308   /**
309    * @brief This signal is emitted when the pan gesture is detected on the attached actor.
310    *
311    * A callback of the following type may be connected:
312    * @code
313    *   void YourCallbackName( Actor actor, const PanGesture& gesture );
314    * @endcode
315    * @since_tizen 2.4
316    * @return The signal to connect to.
317    * @pre The gesture detector has been initialized.
318    */
319   DetectedSignalType& DetectedSignal();
320
321 public: // Pan Properties Setters
322
323   /**
324    * @brief Allows setting of the pan properties that are returned in constraints.
325    *
326    * @since_tizen 2.4
327    * @param[in]  pan  The pan gesture to set.
328    * @note If a normal pan is taking place, then any value set is ignored.
329    */
330   static void SetPanGestureProperties( const PanGesture& pan );
331
332 public: // Not intended for Application developers
333
334   /**
335    * @brief This constructor is used by PanGestureDetector::New() methods.
336    *
337    * @since_tizen 2.4
338    * @param [in] internal A pointer to a newly allocated Dali resource.
339    */
340   explicit DALI_INTERNAL PanGestureDetector(Internal::PanGestureDetector* internal);
341
342 };
343
344 /**
345  * @}
346  */
347
348 } // namespace Dali
349
350 #endif // __DALI_PAN_GESTURE_DETECTOR_H__