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