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