1 #ifndef __DALI_INTERNAL_PAN_GESTURE_EVENT_PROCESSOR_H__
2 #define __DALI_INTERNAL_PAN_GESTURE_EVENT_PROCESSOR_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 #include <dali/public-api/render-tasks/render-task.h>
23 #include <dali/internal/event/events/pan-gesture-detector-impl.h>
24 #include <dali/internal/event/events/gesture-processor.h>
33 struct PanGestureEvent;
47 * Pan Gesture Event Processing:
49 * When we receive a pan gesture event, we do the following:
50 * - Find the actor that requires a pan where the pan started from (i.e. the down position).
51 * - Emit the gesture if the event satisfies the detector conditions.
53 * The above is only checked when our gesture starts. We continue sending the pan gesture to the
54 * same actor and detector until the pan ends or is cancelled.
56 class PanGestureProcessor : public GestureProcessor
61 * Create a pan gesture processor.
62 * @param[in] stage The stage.
63 * @param[in] gestureManager The gesture manager
65 PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager );
68 * Non-virtual destructor; PanGestureProcessor is not a base class
70 ~PanGestureProcessor();
72 public: // To be called by GestureEventProcessor
75 * This method is called whenever a pan gesture event occurs.
76 * @param[in] panEvent The event that has occurred.
78 void Process( const Integration::PanGestureEvent& panEvent );
81 * Adds a gesture detector to this gesture processor.
82 * If this is the first gesture detector being added, then this method registers the required
83 * gesture with the adaptor.
84 * @param[in] gestureDetector The gesture detector being added.
86 void AddGestureDetector( PanGestureDetector* gestureDetector );
89 * Removes the specified gesture detector from this gesture processor. If, after removing this
90 * gesture detector, there are no more gesture detectors registered, then this method unregisters
91 * the gesture from the adaptor.
92 * @param[in] gestureDetector The gesture detector being removed.
94 void RemoveGestureDetector( PanGestureDetector* gestureDetector );
97 * This method updates the gesture detection parameters.
98 * @param[in] gestureDetector The gesture detector that has been updated.
100 void GestureDetectorUpdated( PanGestureDetector* gestureDetector );
103 * Sets the pan gesture properties stored in the scene object directly,
104 * @param[in] pan The pan gesture to override the properties with.
105 * @note If we are already processing a normal pan, then this call is ignored.
107 void SetPanGestureProperties( const PanGesture& pan );
110 * Called to provide pan-gesture profiling information.
112 void EnableProfiling();
115 * Called to set the prediction mode for pan gestures
117 * @param[in] mode The prediction mode
121 * 1 - Prediction using average acceleration
123 void SetPredictionMode(int mode);
126 * @brief Sets the prediction amount of the pan gesture
128 * @param[in] amount The prediction amount in milliseconds
130 void SetPredictionAmount(unsigned int amount);
133 * @brief Sets the upper bound of the prediction amount for clamping
135 * @param[in] amount The prediction amount in milliseconds
137 void SetMaximumPredictionAmount(unsigned int amount);
140 * @brief Sets the lower bound of the prediction amount for clamping
142 * @param[in] amount The prediction amount in milliseconds
144 void SetMinimumPredictionAmount(unsigned int amount);
147 * @brief Sets the amount of prediction interpolation to adjust when the pan velocity is changed
149 * @param[in] amount The prediction amount in milliseconds
151 void SetPredictionAmountAdjustment(unsigned int amount);
154 * Called to set the prediction mode for pan gestures
156 * @param[in] mode The prediction mode
160 * 1 - average between last 2 values
162 void SetSmoothingMode(int mode);
165 * @brief Sets the smoothing amount of the pan gesture
167 * @param[in] amount The smotthing amount from 0.0f (none) to 1.0f (full)
169 void SetSmoothingAmount(float amount);
172 * @brief Sets whether to use actual times of the real gesture and frames or not.
174 * @param[in] value True = use actual times, False = use perfect values
176 void SetUseActualTimes( bool value );
179 * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
181 * @param[in] value Time range in ms
183 void SetInterpolationTimeRange( int value );
186 * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
188 * @param[in] value True = use scalar prediction only
190 void SetScalarOnlyPredictionEnabled( bool value );
193 * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
195 * @param[in] value True = use two point prediction
197 void SetTwoPointPredictionEnabled( bool value );
200 * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
202 * @param[in] value Time in past in ms
204 void SetTwoPointInterpolatePastTime( int value );
207 * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
209 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
211 void SetTwoPointVelocityBias( float value );
214 * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
216 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
218 void SetTwoPointAccelerationBias( float value );
221 * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
223 * @param[in] value Time in past in ms
225 void SetMultitapSmoothingRange( int value );
230 PanGestureProcessor( const PanGestureProcessor& );
231 PanGestureProcessor& operator=( const PanGestureProcessor& rhs );
234 * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
235 * its detection policy. If it does, it sends the appropriate gesture update request to adaptor.
237 void UpdateDetection();
240 * Creates a PanGesture and asks the specified detector to emit its detected signal.
241 * @param[in] actor The actor that has been panned.
242 * @param[in] gestureDetectors The gesture detector container that should emit the signal.
243 * @param[in] panEvent The panEvent received from the adaptor.
244 * @param[in] localCurrent Current position relative to the actor attached to the detector.
245 * @param[in] state The state of the gesture.
246 * @param[in] renderTask The renderTask to use.
248 void EmitPanSignal( Actor* actor,
249 const GestureDetectorContainer& gestureDetectors,
250 const Integration::PanGestureEvent& panEvent,
251 Vector2 localCurrent,
252 Gesture::State state,
253 Dali::RenderTask renderTask );
255 // GestureProcessor overrides
258 * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
260 void OnGesturedActorStageDisconnection();
263 * @copydoc GestureProcessor::CheckGestureDetector()
265 bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
268 * @copydoc GestureProcessor::EmitGestureSignal()
270 void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
275 Integration::GestureManager& mGestureManager;
276 PanGestureDetectorContainer mGestureDetectors;
277 GestureDetectorContainer mCurrentPanEmitters;
278 Dali::RenderTask mCurrentRenderTask;
279 Vector2 mPossiblePanPosition;
281 unsigned int mMinTouchesRequired;
282 unsigned int mMaxTouchesRequired;
284 Vector2 mLastVelocity; ///< The last recorded velocity in local actor coordinates.
285 Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
287 const Integration::PanGestureEvent* mCurrentPanEvent; ///< Pointer to current PanEvent, used when calling ProcessAndEmit()
288 SceneGraph::PanGesture* mSceneObject; ///< Not owned, but we write to it directly
291 } // namespace Internal
295 #endif // __DALI_INTERNAL_PAN_GESTURE_EVENT_PROCESSOR_H__