1 #ifndef DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H
5 * Copyright (c) 2022 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/gesture-processor.h>
23 #include <dali/internal/event/events/pan-gesture/pan-gesture-detector-impl.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
33 struct PanGestureEvent;
39 } // namespace SceneGraph
42 * Pan Gesture Event Processing:
44 * When we receive a pan gesture event, we do the following:
45 * - Find the actor that requires a pan where the pan started from (i.e. the down position).
46 * - Emit the gesture if the event satisfies the detector conditions.
48 * The above is only checked when our gesture starts. We continue sending the pan gesture to the
49 * same actor and detector until the pan ends or is cancelled.
51 class PanGestureProcessor : public GestureProcessor, public RecognizerObserver<PanGestureEvent>
55 * Create a pan gesture processor.
56 * @param[in] updateManager The Update Manager
58 PanGestureProcessor(SceneGraph::UpdateManager& updateManager);
63 ~PanGestureProcessor() override;
65 public: // To be called by GestureEventProcessor
67 * This method is called whenever a pan gesture event occurs.
68 * @param[in] scene The scene the pan gesture event occurs in.
69 * @param[in] panEvent The event that has occurred.
71 void Process(Scene& scene, const PanGestureEvent& panEvent) override;
74 * Adds a gesture detector to this gesture processor.
75 * If this is the first gesture detector being added, then this method registers the required
76 * gesture with the adaptor.
77 * @param[in] gestureDetector The gesture detector being added.
78 * @param[in] scene The scene the pan gesture event occurs in.
79 * @param[in] minDistance The minimum required motion distance to start pan gesture. If this value is less than 0, we use default setuped distance.
80 * @param[in] minPanEvents The minimum required motion event number to start pan gesture. If this value is less than 1, we use default setuped number.
82 void AddGestureDetector(PanGestureDetector* gestureDetector, Scene& scene, int32_t minDistance, int32_t minPanEvents);
85 * Removes the specified gesture detector from this gesture processor. If, after removing this
86 * gesture detector, there are no more gesture detectors registered, then this method unregisters
87 * the gesture from the adaptor.
88 * @param[in] gestureDetector The gesture detector being removed.
90 void RemoveGestureDetector(PanGestureDetector* gestureDetector);
93 * This method updates the gesture detection parameters.
94 * @param[in] gestureDetector The gesture detector that has been updated.
96 void GestureDetectorUpdated(PanGestureDetector* gestureDetector);
99 * Sets the pan gesture properties stored in the scene object directly,
100 * @param[in] pan The pan gesture to override the properties with.
101 * @return true if Core::Update required
102 * @note If we are already processing a normal pan, then this call is ignored.
104 bool SetPanGestureProperties(const Dali::PanGesture& pan);
107 * Called to provide pan-gesture profiling information.
109 void EnableProfiling();
112 * Called to set the prediction mode for pan gestures
114 * @param[in] mode The prediction mode
118 * 1 - Prediction using average acceleration
120 void SetPredictionMode(int mode);
123 * @brief Sets the prediction amount of the pan gesture
125 * @param[in] amount The prediction amount in milliseconds
127 void SetPredictionAmount(unsigned int amount);
130 * @brief Sets the upper bound of the prediction amount for clamping
132 * @param[in] amount The prediction amount in milliseconds
134 void SetMaximumPredictionAmount(unsigned int amount);
137 * @brief Sets the lower bound of the prediction amount for clamping
139 * @param[in] amount The prediction amount in milliseconds
141 void SetMinimumPredictionAmount(unsigned int amount);
144 * @brief Sets the amount of prediction interpolation to adjust when the pan velocity is changed
146 * @param[in] amount The prediction amount in milliseconds
148 void SetPredictionAmountAdjustment(unsigned int amount);
151 * Called to set the prediction mode for pan gestures
153 * @param[in] mode The prediction mode
157 * 1 - average between last 2 values
159 void SetSmoothingMode(int mode);
162 * @brief Sets the smoothing amount of the pan gesture
164 * @param[in] amount The smotthing amount from 0.0f (none) to 1.0f (full)
166 void SetSmoothingAmount(float amount);
169 * @brief Sets whether to use actual times of the real gesture and frames or not.
171 * @param[in] value True = use actual times, False = use perfect values
173 void SetUseActualTimes(bool value);
176 * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
178 * @param[in] value Time range in ms
180 void SetInterpolationTimeRange(int value);
183 * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
185 * @param[in] value True = use scalar prediction only
187 void SetScalarOnlyPredictionEnabled(bool value);
190 * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
192 * @param[in] value True = use two point prediction
194 void SetTwoPointPredictionEnabled(bool value);
197 * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
199 * @param[in] value Time in past in ms
201 void SetTwoPointInterpolatePastTime(int value);
204 * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
206 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
208 void SetTwoPointVelocityBias(float value);
211 * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
213 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
215 void SetTwoPointAccelerationBias(float value);
218 * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
220 * @param[in] value Time in past in ms
222 void SetMultitapSmoothingRange(int value);
224 public: // for PanGestureDetector
226 * @return the pan gesture scene object
228 const SceneGraph::PanGesture& GetSceneObject() const;
232 PanGestureProcessor(const PanGestureProcessor&);
233 PanGestureProcessor& operator=(const PanGestureProcessor& rhs);
236 * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
237 * its detection policy. If it does, it sends the appropriate gesture update request to adaptor.
239 void UpdateDetection();
242 * Creates a PanGesture and asks the specified detector to emit its detected signal.
243 * @param[in] actor The actor that has been panned.
244 * @param[in] gestureDetectors The gesture detector container that should emit the signal.
245 * @param[in] panEvent The panEvent received from the adaptor.
246 * @param[in] localCurrent Current position relative to the actor attached to the detector.
247 * @param[in] state The state of the gesture.
248 * @param[in] renderTask The renderTask to use.
250 void EmitPanSignal(Actor* actor,
251 const GestureDetectorContainer& gestureDetectors,
252 const PanGestureEvent& panEvent,
253 Vector2 localCurrent,
255 RenderTaskPtr renderTask);
257 // GestureProcessor overrides
260 * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
262 void OnGesturedActorStageDisconnection() override;
265 * @copydoc GestureProcessor::CheckGestureDetector()
267 bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
270 * @copydoc GestureProcessor::EmitGestureSignal()
272 void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
275 PanGestureDetectorContainer mPanGestureDetectors;
276 GestureDetectorContainer mCurrentPanEmitters;
277 RenderTaskPtr mCurrentRenderTask;
278 Vector2 mPossiblePanPosition;
280 uint32_t mMinTouchesRequired;
281 uint32_t mMaxTouchesRequired;
282 uint32_t mMaxMotionEventAge;
284 Vector2 mLastVelocity; ///< The last recorded velocity in local actor coordinates.
285 Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
287 const 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_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H