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