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