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 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
11 // http://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_FRAMEWORK
26 #include <dali/public-api/events/gesture-detector.h>
27 #include <dali/public-api/signals/dali-signal-v2.h>
29 namespace Dali DALI_IMPORT_API
34 namespace Internal DALI_INTERNAL
36 class PanGestureDetector;
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.
45 * The application programmer can use this gesture detector as follows:
47 * PanGestureDetector detector = PanGestureDetector::New();
48 * detector.Attach(myActor);
49 * detector.SignalDetected().Connect(this, &MyApplication::OnPan);
51 * // Detect pan gesture for single and double touch.
52 * detector.SetMaximumTouchesRequired(2);
57 class PanGestureDetector : public GestureDetector
62 typedef SignalV2< void (Actor, PanGesture) > DetectedSignalV2;
65 static const char* const SIGNAL_PAN_DETECTED;
68 typedef std::pair< Radian, Radian > AngleThresholdPair;
69 typedef std::vector< AngleThresholdPair > AngleContainer;
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().
78 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 LOCAL_POSITION; ///< name "local-position", type VECTOR2
84 static const Property::Index LOCAL_DISPLACEMENT; ///< name "local-displacement", type VECTOR2
86 public: // Creation & Destruction
89 * Create an uninitialized PanGestureDetector; this can be initialized with PanGestureDetector::New()
90 * Calling member functions with an uninitialized Dali::Object is not allowed.
95 * Create an initialized PanGestureDetector.
96 * @return A handle to a newly allocated Dali resource.
98 static PanGestureDetector New();
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
106 static PanGestureDetector DownCast( BaseHandle handle );
109 * Virtual destructor.
110 * Dali::Object derived classes typically do not contain member data.
112 virtual ~PanGestureDetector();
115 * @copydoc Dali::BaseHandle::operator=
117 using BaseHandle::operator=;
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'.
127 void SetMinimumTouchesRequired(unsigned int minimum);
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'.
135 void SetMaximumTouchesRequired(unsigned int maximum);
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.
144 unsigned int GetMinimumTouchesRequired() const;
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.
151 unsigned int GetMaximumTouchesRequired() const;
153 public: // Directional Panning
156 * The pan gesture is only emitted if the pan occurs in the direction specified by this method
157 * with a +/- threshold allowance.
159 * The angle is from -180 -> 0 -> 180 degrees (or -M_PI -> 0 -> M_PI in radians) i.e:
162 * -90.0f ( -0.5f * PI )
165 * 180.0f ( PI ) ------------- 0.0f ( 0.0f )
168 * 90.0f ( 0.5f * PI )
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.
174 * @param[in] angle The angle that pan should be allowed.
175 * @param[in] threshold The threshold around that angle.
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.
186 * @pre The gesture detector has been initialized.
188 void AddAngle( Radian angle, Radian threshold = DEFAULT_THRESHOLD );
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
195 * @param[in] direction The direction of panning required.
196 * @param[in] threshold The threshold.
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.
204 * @pre The gesture detector has been initialized.
208 void AddDirection( Radian direction, Radian threshold = DEFAULT_THRESHOLD );
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.
215 const AngleContainer& GetAngles() const;
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.
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.
232 void RemoveAngle( Radian angle );
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.
241 void RemoveDirection( Radian direction );
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:
249 * void YourCallbackName(Actor actor, PanGesture gesture);
251 * @pre The gesture detector has been initialized.
252 * @return The signal to connect to.
254 DetectedSignalV2& DetectedSignal();
256 public: // Pan Properties Setters
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.
263 static void SetPanGestureProperties( const PanGesture& pan );
265 public: // Not intended for Application developers
268 * This constructor is used by Dali New() methods.
269 * @param [in] internal A pointer to a newly allocated Dali resource.
271 explicit DALI_INTERNAL PanGestureDetector(Internal::PanGestureDetector* internal);
280 #endif // __DALI_PAN_GESTURE_DETECTOR_H__