1 #ifndef __DALI_PAN_GESTURE_DETECTOR_H__
2 #define __DALI_PAN_GESTURE_DETECTOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @addtogroup CAPI_DALI_EVENTS_MODULE
27 #include <dali/public-api/events/gesture-detector.h>
28 #include <dali/public-api/signals/dali-signal-v2.h>
30 namespace Dali DALI_IMPORT_API
35 namespace Internal DALI_INTERNAL
37 class PanGestureDetector;
43 * @brief This class looks for panning (or dragging) gestures.
45 * The user will be pressing one or more fingers on an actor while they pan it.
47 * The application programmer can use this gesture detector as follows:
49 * PanGestureDetector detector = PanGestureDetector::New();
50 * detector.Attach(myActor);
51 * detector.DetectedSignal().Connect(this, &MyApplication::OnPan);
53 * // Detect pan gesture for single and double touch.
54 * detector.SetMaximumTouchesRequired(2);
59 class PanGestureDetector : public GestureDetector
64 typedef SignalV2< void (Actor, PanGesture) > DetectedSignalV2; ///< Pan gesture detected signal type
67 typedef std::pair< Radian, Radian > AngleThresholdPair; ///< Range of angles for a direction
68 typedef std::vector< AngleThresholdPair > AngleContainer; ///< Group of angular thresholds for all directions
70 static const Radian DIRECTION_LEFT; ///< For a left pan (-PI Radians).
71 static const Radian DIRECTION_RIGHT; ///< For a right pan (0 Radians).
72 static const Radian DIRECTION_UP; ///< For an up pan (-0.5 * PI Radians).
73 static const Radian DIRECTION_DOWN; ///< For a down pan (0.5 * PI Radians).
74 static const Radian DIRECTION_HORIZONTAL; ///< For a left and right pan (PI Radians). Useful for AddDirection().
75 static const Radian DIRECTION_VERTICAL; ///< For an up and down pan (-0.5 * PI Radians). Useful for AddDirection().
77 static const Radian DEFAULT_THRESHOLD; ///< The default threshold is PI * 0.25 radians (or 45 degrees).
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 SCREEN_VELOCITY; ///< name "screen-velocity", type VECTOR2
84 static const Property::Index LOCAL_POSITION; ///< name "local-position", type VECTOR2
85 static const Property::Index LOCAL_DISPLACEMENT; ///< name "local-displacement", type VECTOR2
86 static const Property::Index LOCAL_VELOCITY; ///< name "local-velocity", type VECTOR2
87 static const Property::Index PANNING; ///< name "panning", type BOOLEAN
92 static const char* const SIGNAL_PAN_DETECTED; ///< name "pan-detected", @see DetectedSignal()
95 public: // Creation & Destruction
98 * @brief Create an uninitialized PanGestureDetector; this can be initialized with PanGestureDetector::New().
100 * Calling member functions with an uninitialized Dali::Object is not allowed.
102 PanGestureDetector();
105 * @brief Create an initialized PanGestureDetector.
107 * @return A handle to a newly allocated Dali resource.
109 static PanGestureDetector New();
112 * @brief Downcast an Object handle to PanGestureDetector handle.
114 * If handle points to a PanGestureDetector object the
115 * downcast produces valid handle. If not the returned handle is left uninitialized.
116 * @param[in] handle to An object
117 * @return handle to a PanGestureDetector object or an uninitialized handle
119 static PanGestureDetector DownCast( BaseHandle handle );
124 * This is non-virtual since derived Handle types must not contain data or virtual methods.
126 ~PanGestureDetector();
129 * @copydoc Dali::BaseHandle::operator=
131 using BaseHandle::operator=;
136 * @brief This is the minimum number of touches required for the pan gesture to be detected.
138 * @param[in] minimum Minimum touches required.
139 * @pre The gesture detector has been initialized.
140 * @note The default minimum is '1'.
142 void SetMinimumTouchesRequired(unsigned int minimum);
145 * @brief This is the maximum number of touches required for the pan gesture to be detected.
147 * @param[in] maximum Maximum touches required.
148 * @pre The gesture detector has been initialized.
149 * @note The default maximum is '1'.
151 void SetMaximumTouchesRequired(unsigned int maximum);
156 * @brief Retrieves the minimum number of touches required for the pan gesture to be detected.
158 * @return The minimum touches required.
159 * @pre The gesture detector has been initialized.
161 unsigned int GetMinimumTouchesRequired() const;
164 * @brief Retrieves the maximum number of touches required for the pan gesture to be detected.
166 * @return The maximum touches required.
167 * @pre The gesture detector has been initialized.
169 unsigned int GetMaximumTouchesRequired() const;
171 public: // Directional Panning
174 * @brief The pan gesture is only emitted if the pan occurs in the direction specified by this method with a +/- threshold allowance.
176 * The angle is from -180 -> 0 -> 180 degrees (or -M_PI -> 0 -> M_PI in radians) i.e:
179 * -90.0f ( -0.5f * PI )
182 * 180.0f ( PI ) ------------- 0.0f ( 0.0f )
185 * 90.0f ( 0.5f * PI )
188 * If an angle of 0.0 degrees is specified and the threshold is 45 degrees then the acceptable
189 * direction range is from -45 to 45 degrees.
191 * @param[in] angle The angle that pan should be allowed.
192 * @param[in] threshold The threshold around that angle.
194 * @note The angle added using this API is only checked when the gesture first starts, after that,
195 * this detector will emit the gesture regardless of what angle the pan is moving.
196 * @note The user can add as many angles as they require.
197 * @note If an angle outside the range above is given, then it is wrapped within the range, i.e.
198 * 190 degrees becomes -170 degrees and 370 degrees becomes 10 degrees.
199 * @note As long as you specify the type, you can also pass in a Dali::Degree to this method.
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.
203 * @pre The gesture detector has been initialized.
205 void AddAngle( Radian angle, Radian threshold = DEFAULT_THRESHOLD );
208 * @brief A helper method for adding bi-directional angles where the pan should take place.
210 * In other words, if 0 is requested, then PI will also be added so that we have both left and
213 * @param[in] direction The direction of panning required.
214 * @param[in] threshold The threshold.
216 * @note If a direction outside the range above is given, then it is wrapped within the range, i.e.
217 * 190 degrees becomes -170 degrees and 370 degrees becomes 10 degrees.
218 * @note If no threshold is provided, then the default threshold (PI * 0.25) is used.
219 * @note If the threshold is greater than PI, then PI will be used as the threshold.
220 * @note As long as you specify the type, you can also pass in a Dali::Degree to this method.
222 * @pre The gesture detector has been initialized.
226 void AddDirection( Radian direction, Radian threshold = DEFAULT_THRESHOLD );
229 * @brief Returns the container of all the angles this pan gesture detector emits a signal.
231 * @return a const reference to the container of all the angles.
232 * @pre The gesture detector has been initialized.
234 const AngleContainer& GetAngles() const;
237 * @brief Clears any directional angles that are used by the gesture detector.
239 * After this, the pan gesture
240 * will be emitted for a pan in ANY direction.
241 * @pre The gesture detector has been initialized.
246 * @brief Removes the angle specified from the container.
248 * @param[in] angle The angle to remove.
249 * @pre The gesture detector has been initialized.
250 * @note This will only remove the first instance of the angle found from the container.
251 * @note If an angle outside the range in AddAngle() is given, then the value is wrapped within
252 * the range and that is removed.
254 void RemoveAngle( Radian angle );
257 * @brief Removes the two angles that make up the direction from the container.
259 * @param[in] direction The direction to remove.
260 * @pre The gesture detector has been initialized.
261 * @note If a direction outside the range in AddAngle() is given, then the value is wrapped within
262 * the range and that is removed.
264 void RemoveDirection( Radian direction );
269 * @brief This signal is emitted when the pan gesture is detected on the attached actor.
271 * A callback of the following type may be connected:
273 * void YourCallbackName(Actor actor, PanGesture gesture);
275 * @pre The gesture detector has been initialized.
276 * @return The signal to connect to.
278 DetectedSignalV2& DetectedSignal();
280 public: // Pan Properties Setters
283 * @brief Allows setting of the pan properties that are returned in constraints.
285 * @param[in] pan The pan gesture to set.
286 *@note If a normal pan is taking place, then any value set is ignored.
288 static void SetPanGestureProperties( const PanGesture& pan );
290 public: // Not intended for Application developers
293 * @brief This constructor is used by Dali New() methods.
295 * @param [in] internal A pointer to a newly allocated Dali resource.
297 explicit DALI_INTERNAL PanGestureDetector(Internal::PanGestureDetector* internal);
306 #endif // __DALI_PAN_GESTURE_DETECTOR_H__