Merge "Fix the crash when adding new scene during core event processing" into devel...
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.h
1 #ifndef DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/internal/event/events/gesture-detector-impl.h>
24 #include <dali/internal/event/events/long-press-gesture-processor.h>
25 #include <dali/internal/event/events/pan-gesture-processor.h>
26 #include <dali/internal/event/events/pinch-gesture-processor.h>
27 #include <dali/internal/event/events/tap-gesture-processor.h>
28
29 namespace Dali
30 {
31
32 struct Gesture;
33
34 namespace Integration
35 {
36
37 class RenderController;
38 }
39
40 namespace SceneGraph
41 {
42 class UpdateManager;
43 }
44
45 namespace Internal
46 {
47
48 class Stage;
49 class Scene;
50
51 /**
52  * Gesture Event Processing:
53  *
54  * The GestureEventProcessor determines what type of gesture event we have received and sends it to
55  * the appropriate gesture processor for processing.
56  */
57 class GestureEventProcessor
58 {
59 public:
60
61   /**
62    * Create a gesture event processor.
63    * @param[in] updateManager The update manager
64    * @param[in] renderController The render controller
65    */
66   GestureEventProcessor( SceneGraph::UpdateManager& updateManager, Integration::RenderController& renderController );
67
68   /**
69    * Non-virtual destructor; GestureProcessor is not a base class
70    */
71   ~GestureEventProcessor();
72
73 public: // To be called by EventProcessor
74
75   /**
76    * This function is called by Core whenever a touch event occurs
77    * @param[in] scene The scene
78    * @param[in] event The event that has occurred
79    */
80   void ProcessTouchEvent( Scene& scene, const Integration::TouchEvent& event);
81
82 public: // To be called by gesture detectors
83
84   /**
85    * This method adds the specified gesture detector to the relevant gesture processor.
86    * @param[in]  gestureDetector  The gesture detector to add
87    */
88   void AddGestureDetector(GestureDetector* gestureDetector, Scene& scene);
89
90   /**
91    * This method removes the specified gesture detector from the relevant gesture processor.
92    * @param[in]  gestureDetector  The gesture detector to remove.
93    */
94   void RemoveGestureDetector(GestureDetector* gestureDetector);
95
96   /**
97    * This method informs the appropriate processor that the gesture detector has been updated.
98    * @param[in]  gestureDetector  The gesture detector that has been updated.
99    */
100   void GestureDetectorUpdated(GestureDetector* gestureDetector);
101
102   /**
103    * Called by GestureDetectors to set the gesture properties in the update thread.
104    * @param[in]  gesture  The gesture whose values will be used in the Update object.
105    * @note If we are in the middle of processing the gesture being set, then this call is ignored.
106    */
107   void SetGestureProperties( const Gesture& gesture );
108
109 public: // Called by Core
110
111   /**
112    * Returns true if any GestureDetector requires a Core::Update. Clears
113    * the state flag after reading.
114    *
115    * @return true if any GestureDetector requires a Core::Update
116    */
117   bool NeedsUpdate();
118
119   /**
120    * Called to provide pan-gesture profiling information.
121    */
122   void EnablePanGestureProfiling();
123
124   /**
125    * @brief Called to set how pan gestures predict input
126    *
127    * @param[in] mode The prediction mode to use
128    */
129   void SetPanGesturePredictionMode( int32_t mode );
130
131   /**
132    * @brief Sets the prediction amount of the pan gesture
133    *
134    * @param[in] amount The prediction amount in milliseconds
135    */
136   void SetPanGesturePredictionAmount( uint32_t amount );
137
138   /**
139    * @brief Sets the upper bound of the prediction amount for clamping
140    *
141    * @param[in] amount The prediction amount in milliseconds
142    */
143   void SetPanGestureMaximumPredictionAmount( uint32_t amount );
144
145   /**
146    * @brief Sets the lower bound of the prediction amount for clamping
147    *
148    * @param[in] amount The prediction amount in milliseconds
149    */
150   void SetPanGestureMinimumPredictionAmount( uint32_t amount );
151
152   /**
153    * @brief Sets the prediction amount to adjust when the pan velocity is changed.
154    * If the pan velocity is accelerating, the prediction amount will be increased
155    * by the specified amount until it reaches the upper bound. If the pan velocity
156    * is decelerating, the prediction amount will be decreased by the specified amount
157    * until it reaches the lower bound.
158    *
159    * @param[in] amount The prediction amount in milliseconds
160    */
161   void SetPanGesturePredictionAmountAdjustment( uint32_t amount );
162
163   /**
164    * @brief Called to set how pan gestures smooth input
165    *
166    * @param[in] mode The smoothing mode to use
167    */
168   void SetPanGestureSmoothingMode( int32_t mode );
169
170   /**
171    * @brief Sets the prediction amount of the pan gesture
172    *
173    * @param[in] amount The smoothing amount [0.0f,1.0f] - 0.0f would be no smoothing, 1.0f maximum smoothing
174    */
175   void SetPanGestureSmoothingAmount( float amount );
176
177   /*
178    * @brief Sets whether to use actual times of the real gesture and frames or not.
179    *
180    * @param[in] value True = use actual times, False = use perfect values
181    */
182   void SetPanGestureUseActualTimes( bool value );
183
184   /**
185    * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
186    *
187    * @param[in] value Time range in ms
188    */
189   void SetPanGestureInterpolationTimeRange( int32_t value );
190
191   /**
192    * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
193    *
194    * @param[in] value True = use scalar prediction only
195    */
196   void SetPanGestureScalarOnlyPredictionEnabled( bool value );
197
198   /**
199    * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
200    *
201    * @param[in] value True = use two point prediction
202    */
203   void SetPanGestureTwoPointPredictionEnabled( bool value );
204
205   /**
206    * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
207    *
208    * @param[in] value Time in past in ms
209    */
210   void SetPanGestureTwoPointInterpolatePastTime( int32_t value );
211
212   /**
213    * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
214    *
215    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
216    */
217   void SetPanGestureTwoPointVelocityBias( float value );
218
219   /**
220    * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
221    *
222    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
223    */
224   void SetPanGestureTwoPointAccelerationBias( float value );
225
226   /**
227    * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
228    *
229    * @param[in] value Time in past in ms
230    */
231   void SetPanGestureMultitapSmoothingRange( int32_t value );
232
233   /**
234    * @brief Sets the minimum distance required to start a pan event
235    *
236    * @param[in] value Distance in pixels
237    */
238   void SetPanGestureMinimumDistance( int32_t value );
239
240   /**
241    * @brief Sets the minimum number of touch events required to start a pan
242    *
243    * @param[in] value Number of touch events
244    */
245   void SetPanGestureMinimumPanEvents( int32_t value );
246
247   /**
248    * @brief Sets the minimum distance required to start a pinch event
249    *
250    * @param[in] value Distance in pixels
251    */
252   void SetPinchGestureMinimumDistance( float value);
253
254 public: // needed for PanGesture
255
256   /**
257    * @return the pan gesture processor
258    */
259   const PanGestureProcessor& GetPanGestureProcessor();
260
261 private:
262
263   // Undefined
264   GestureEventProcessor(const GestureEventProcessor&);
265   GestureEventProcessor& operator=(const GestureEventProcessor& rhs);
266
267 private:
268
269   LongPressGestureProcessor mLongPressGestureProcessor;
270   PanGestureProcessor mPanGestureProcessor;
271   PinchGestureProcessor mPinchGestureProcessor;
272   TapGestureProcessor mTapGestureProcessor;
273   Integration::RenderController& mRenderController;
274
275   int32_t envOptionMinimumPanDistance;
276   int32_t envOptionMinimumPanEvents;
277 };
278
279 } // namespace Internal
280
281 } // namespace Dali
282
283 #endif // DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H