1 #ifndef DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H
5 * Copyright (c) 2019 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/internal/event/events/pan-gesture-detector-impl.h>
23 #include <dali/internal/event/events/gesture-processor.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
35 struct PanGestureEvent;
44 * Pan Gesture Event Processing:
46 * When we receive a pan gesture event, we do the following:
47 * - Find the actor that requires a pan where the pan started from (i.e. the down position).
48 * - Emit the gesture if the event satisfies the detector conditions.
50 * The above is only checked when our gesture starts. We continue sending the pan gesture to the
51 * same actor and detector until the pan ends or is cancelled.
53 class PanGestureProcessor : public GestureProcessor, public RecognizerObserver<PanGestureEvent>
58 * Create a pan gesture processor.
59 * @param[in] gestureManager The gesture manager
60 * @param[in] updateManager The Update Manager
62 PanGestureProcessor( SceneGraph::UpdateManager& updateManager );
67 virtual ~PanGestureProcessor();
69 public: // To be called by GestureEventProcessor
72 * This method is called whenever a pan gesture event occurs.
73 * @param[in] scene The scene the pan gesture event occurs in.
74 * @param[in] panEvent The event that has occurred.
76 void Process( Scene& scene, const PanGestureEvent& panEvent );
79 * Adds a gesture detector to this gesture processor.
80 * If this is the first gesture detector being added, then this method registers the required
81 * gesture with the adaptor.
82 * @param[in] gestureDetector The gesture detector being added.
84 void AddGestureDetector( PanGestureDetector* gestureDetector, Scene& scene, int32_t minDistance, int32_t minPanEvents );
87 * Removes the specified gesture detector from this gesture processor. If, after removing this
88 * gesture detector, there are no more gesture detectors registered, then this method unregisters
89 * the gesture from the adaptor.
90 * @param[in] gestureDetector The gesture detector being removed.
92 void RemoveGestureDetector( PanGestureDetector* gestureDetector );
95 * This method updates the gesture detection parameters.
96 * @param[in] gestureDetector The gesture detector that has been updated.
98 void GestureDetectorUpdated( PanGestureDetector* gestureDetector );
101 * Sets the pan gesture properties stored in the scene object directly,
102 * @param[in] pan The pan gesture to override the properties with.
103 * @return true if Core::Update required
104 * @note If we are already processing a normal pan, then this call is ignored.
106 bool SetPanGestureProperties( const PanGesture& pan );
109 * Called to provide pan-gesture profiling information.
111 void EnableProfiling();
114 * Called to set the prediction mode for pan gestures
116 * @param[in] mode The prediction mode
120 * 1 - Prediction using average acceleration
122 void SetPredictionMode(int mode);
125 * @brief Sets the prediction amount of the pan gesture
127 * @param[in] amount The prediction amount in milliseconds
129 void SetPredictionAmount(unsigned int amount);
132 * @brief Sets the upper bound of the prediction amount for clamping
134 * @param[in] amount The prediction amount in milliseconds
136 void SetMaximumPredictionAmount(unsigned int amount);
139 * @brief Sets the lower bound of the prediction amount for clamping
141 * @param[in] amount The prediction amount in milliseconds
143 void SetMinimumPredictionAmount(unsigned int amount);
146 * @brief Sets the amount of prediction interpolation to adjust when the pan velocity is changed
148 * @param[in] amount The prediction amount in milliseconds
150 void SetPredictionAmountAdjustment(unsigned int amount);
153 * Called to set the prediction mode for pan gestures
155 * @param[in] mode The prediction mode
159 * 1 - average between last 2 values
161 void SetSmoothingMode(int mode);
164 * @brief Sets the smoothing amount of the pan gesture
166 * @param[in] amount The smotthing amount from 0.0f (none) to 1.0f (full)
168 void SetSmoothingAmount(float amount);
171 * @brief Sets whether to use actual times of the real gesture and frames or not.
173 * @param[in] value True = use actual times, False = use perfect values
175 void SetUseActualTimes( bool value );
178 * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
180 * @param[in] value Time range in ms
182 void SetInterpolationTimeRange( int value );
185 * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
187 * @param[in] value True = use scalar prediction only
189 void SetScalarOnlyPredictionEnabled( bool value );
192 * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
194 * @param[in] value True = use two point prediction
196 void SetTwoPointPredictionEnabled( bool value );
199 * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
201 * @param[in] value Time in past in ms
203 void SetTwoPointInterpolatePastTime( int value );
206 * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
208 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
210 void SetTwoPointVelocityBias( float value );
213 * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
215 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
217 void SetTwoPointAccelerationBias( float value );
220 * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
222 * @param[in] value Time in past in ms
224 void SetMultitapSmoothingRange( int value );
226 public: // for PanGestureDetector
229 * @return the pan gesture scene object
231 const SceneGraph::PanGesture& GetSceneObject() const;
236 PanGestureProcessor( const PanGestureProcessor& );
237 PanGestureProcessor& operator=( const PanGestureProcessor& rhs );
240 * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
241 * its detection policy. If it does, it sends the appropriate gesture update request to adaptor.
243 void UpdateDetection();
246 * Creates a PanGesture and asks the specified detector to emit its detected signal.
247 * @param[in] actor The actor that has been panned.
248 * @param[in] gestureDetectors The gesture detector container that should emit the signal.
249 * @param[in] panEvent The panEvent received from the adaptor.
250 * @param[in] localCurrent Current position relative to the actor attached to the detector.
251 * @param[in] state The state of the gesture.
252 * @param[in] renderTask The renderTask to use.
254 void EmitPanSignal( Actor* actor,
255 const GestureDetectorContainer& gestureDetectors,
256 const PanGestureEvent& panEvent,
257 Vector2 localCurrent,
258 Gesture::State state,
259 RenderTaskPtr renderTask );
261 // GestureProcessor overrides
264 * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
266 void OnGesturedActorStageDisconnection();
269 * @copydoc GestureProcessor::CheckGestureDetector()
271 bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
274 * @copydoc GestureProcessor::EmitGestureSignal()
276 void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
280 PanGestureDetectorContainer mPanGestureDetectors;
281 GestureDetectorContainer mCurrentPanEmitters;
282 RenderTaskPtr mCurrentRenderTask;
283 Vector2 mPossiblePanPosition;
285 uint32_t mMinTouchesRequired;
286 uint32_t mMaxTouchesRequired;
288 Vector2 mLastVelocity; ///< The last recorded velocity in local actor coordinates.
289 Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
291 const PanGestureEvent* mCurrentPanEvent; ///< Pointer to current PanEvent, used when calling ProcessAndEmit()
292 SceneGraph::PanGesture* mSceneObject; ///< Not owned, but we write to it directly
295 } // namespace Internal
299 #endif // DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H