1 #ifndef DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H
5 * Copyright (c) 2023 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-detector-impl.h>
23 #include <dali/internal/event/events/long-press-gesture/long-press-gesture-processor.h>
24 #include <dali/internal/event/events/pan-gesture/pan-gesture-processor.h>
25 #include <dali/internal/event/events/pinch-gesture/pinch-gesture-processor.h>
26 #include <dali/internal/event/events/rotation-gesture/rotation-gesture-processor.h>
27 #include <dali/internal/event/events/tap-gesture/tap-gesture-processor.h>
28 #include <dali/public-api/actors/actor.h>
29 #include <dali/public-api/events/gesture.h>
35 class RenderController;
49 * Gesture Event Processing:
51 * The GestureEventProcessor determines what type of gesture event we have received and sends it to
52 * the appropriate gesture processor for processing.
54 class GestureEventProcessor
58 * Create a gesture event processor.
59 * @param[in] updateManager The update manager
60 * @param[in] renderController The render controller
62 GestureEventProcessor(SceneGraph::UpdateManager& updateManager, Integration::RenderController& renderController);
65 * Non-virtual destructor; GestureProcessor is not a base class
67 ~GestureEventProcessor();
69 public: // To be called by EventProcessor
71 * This function is called by Core whenever a touch event occurs
72 * @param[in] scene The scene
73 * @param[in] event The event that has occurred
75 void ProcessTouchEvent(Scene& scene, const Integration::TouchEvent& event);
78 * This function is called by gesture detector whenever a touch event occurs
79 * @param[in] gestureDetector The gesture detector
80 * @param[in] actor The actor
81 * @param[in] renderTask The renderTask
82 * @param[in] scene The scene
83 * @param[in] event The event that has occurred
85 void ProcessTouchEvent(GestureDetector* gestureDetector, Actor& actor, Dali::Internal::RenderTask& renderTask, Scene& scene, const Integration::TouchEvent& event);
87 public: // To be called by gesture detectors
89 * This method adds the specified gesture detector to the relevant gesture processor.
90 * @param[in] gestureDetector The gesture detector to add
92 void AddGestureDetector(GestureDetector* gestureDetector, Scene& scene);
95 * This method removes the specified gesture detector from the relevant gesture processor.
96 * @param[in] gestureDetector The gesture detector to remove.
98 void RemoveGestureDetector(GestureDetector* gestureDetector);
101 * This method informs the appropriate processor that the gesture detector has been updated.
102 * @param[in] gestureDetector The gesture detector that has been updated.
104 void GestureDetectorUpdated(GestureDetector* gestureDetector);
107 * Called by GestureDetectors to set the gesture properties in the update thread.
108 * @param[in] gesture The gesture whose values will be used in the Update object.
109 * @note If we are in the middle of processing the gesture being set, then this call is ignored.
111 void SetGestureProperties(const Dali::Gesture& gesture);
113 public: // Called by Core
115 * Returns true if any GestureDetector requires a Core::Update. Clears
116 * the state flag after reading.
118 * @return true if any GestureDetector requires a Core::Update
123 * Called to provide pan-gesture profiling information.
125 void EnablePanGestureProfiling();
128 * @brief Called to set how pan gestures predict input
130 * @param[in] mode The prediction mode to use
132 void SetPanGesturePredictionMode(int32_t mode);
135 * @brief Sets the prediction amount of the pan gesture
137 * @param[in] amount The prediction amount in milliseconds
139 void SetPanGesturePredictionAmount(uint32_t amount);
142 * @brief Sets the upper bound of the prediction amount for clamping
144 * @param[in] amount The prediction amount in milliseconds
146 void SetPanGestureMaximumPredictionAmount(uint32_t amount);
149 * @brief Sets the lower bound of the prediction amount for clamping
151 * @param[in] amount The prediction amount in milliseconds
153 void SetPanGestureMinimumPredictionAmount(uint32_t amount);
156 * @brief Sets the prediction amount to adjust when the pan velocity is changed.
157 * If the pan velocity is accelerating, the prediction amount will be increased
158 * by the specified amount until it reaches the upper bound. If the pan velocity
159 * is decelerating, the prediction amount will be decreased by the specified amount
160 * until it reaches the lower bound.
162 * @param[in] amount The prediction amount in milliseconds
164 void SetPanGesturePredictionAmountAdjustment(uint32_t amount);
167 * @brief Called to set how pan gestures smooth input
169 * @param[in] mode The smoothing mode to use
171 void SetPanGestureSmoothingMode(int32_t mode);
174 * @brief Sets the prediction amount of the pan gesture
176 * @param[in] amount The smoothing amount [0.0f,1.0f] - 0.0f would be no smoothing, 1.0f maximum smoothing
178 void SetPanGestureSmoothingAmount(float amount);
181 * @brief Sets whether to use actual times of the real gesture and frames or not.
183 * @param[in] value True = use actual times, False = use perfect values
185 void SetPanGestureUseActualTimes(bool value);
188 * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
190 * @param[in] value Time range in ms
192 void SetPanGestureInterpolationTimeRange(int32_t value);
195 * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
197 * @param[in] value True = use scalar prediction only
199 void SetPanGestureScalarOnlyPredictionEnabled(bool value);
202 * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
204 * @param[in] value True = use two point prediction
206 void SetPanGestureTwoPointPredictionEnabled(bool value);
209 * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
211 * @param[in] value Time in past in ms
213 void SetPanGestureTwoPointInterpolatePastTime(int32_t value);
216 * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
218 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
220 void SetPanGestureTwoPointVelocityBias(float value);
223 * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
225 * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
227 void SetPanGestureTwoPointAccelerationBias(float value);
230 * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
232 * @param[in] value Time in past in ms
234 void SetPanGestureMultitapSmoothingRange(int32_t value);
237 * @brief Sets the minimum distance required to start a pan event
239 * @param[in] value Distance in pixels
241 void SetPanGestureMinimumDistance(int32_t value);
244 * @brief Sets the minimum number of touch events required to start a pan
246 * @param[in] value Number of touch events
248 void SetPanGestureMinimumPanEvents(int32_t value);
251 * @brief Sets the minimum distance required to start a pinch event
253 * @param[in] value Distance in pixels
255 void SetPinchGestureMinimumDistance(float value);
258 * @brief Sets the minimum touch events required before a pinch can be started
260 * @param[in] value The number of touch events
262 void SetPinchGestureMinimumTouchEvents(uint32_t value);
265 * @brief Sets the minimum touch events required after a pinch started
267 * @param[in] value The number of touch events
269 void SetPinchGestureMinimumTouchEventsAfterStart(uint32_t value);
272 * @brief Sets the minimum touch events required before a rotation can be started
274 * @param[in] value The number of touch events
276 void SetRotationGestureMinimumTouchEvents(uint32_t value);
279 * @brief Sets the minimum touch events required after a rotation started
281 * @param[in] value The number of touch events
283 void SetRotationGestureMinimumTouchEventsAfterStart(uint32_t value);
286 * @brief Sets the minimum holding time required to be recognized as a long press gesture
288 * @param[in] value The time value in milliseconds
290 void SetLongPressMinimumHoldingTime(uint32_t value);
293 * @return The minimum holding time required to be recognized as a long press gesture in milliseconds
295 uint32_t GetLongPressMinimumHoldingTime() const;
298 * @brief Sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond)
300 * @param[in] time The time value in milliseconds
302 void SetTapMaximumAllowedTime(uint32_t time);
305 * @brief Sets the recognizer time required to be recognized as a tap gesture (millisecond)
307 * This time is from touch down to touch up to recognize the tap gesture.
309 * @param[in] time The time value in milliseconds
311 void SetTapRecognizerTime(uint32_t time);
314 * @brief Sets the recognizer distance required to be recognized as a tap gesture
316 * This distance is from touch down to touch up to recognize the tap gesture.
318 * @param[in] distance The distance
320 void SetTapMaximumMotionAllowedDistance(float distance);
322 public: // needed for PanGesture
324 * @return the pan gesture processor
326 const PanGestureProcessor& GetPanGestureProcessor();
329 * @return the tap gesture processor
331 const TapGestureProcessor& GetTapGestureProcessor();
335 GestureEventProcessor(const GestureEventProcessor&);
336 GestureEventProcessor& operator=(const GestureEventProcessor& rhs);
339 LongPressGestureProcessor mLongPressGestureProcessor;
340 PanGestureProcessor mPanGestureProcessor;
341 PinchGestureProcessor mPinchGestureProcessor;
342 TapGestureProcessor mTapGestureProcessor;
343 RotationGestureProcessor mRotationGestureProcessor;
344 Integration::RenderController& mRenderController;
346 int32_t envOptionMinimumPanDistance;
347 int32_t envOptionMinimumPanEvents;
348 bool mIsProcessingFeedTouch; // Whether the gesture is being recognized via FeedTouch in gestureDetector
351 } // namespace Internal
355 #endif // DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H