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