Merge changes I1aa1107c,Iede00fcd,I43ba1a81 into devel/master
[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) 2018 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 struct GestureEvent;
37 class GestureManager;
38 class RenderController;
39 }
40
41 namespace SceneGraph
42 {
43 class UpdateManager;
44 }
45
46 namespace Internal
47 {
48
49 class Stage;
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] stage The stage.
64    * @param[in] updateManager The update manager
65    * @param[in] gestureManager The gesture manager
66    * @param[in] renderController The render controller
67    */
68   GestureEventProcessor( Stage& stage, SceneGraph::UpdateManager& updateManager, Integration::GestureManager& gestureManager, Integration::RenderController& renderController );
69
70   /**
71    * Non-virtual destructor; GestureProcessor is not a base class
72    */
73   ~GestureEventProcessor();
74
75 public: // To be called by EventProcessor
76
77   /**
78    * This function is called by Core whenever a gesture event occurs.
79    * @param[in] event The event that has occurred.
80    */
81   void ProcessGestureEvent(const Integration::GestureEvent& event);
82
83 public: // To be called by gesture detectors
84
85   /**
86    * This method adds the specified gesture detector to the relevant gesture processor.
87    * @param[in]  gestureDetector  The gesture detector to add
88    */
89   void AddGestureDetector(GestureDetector* gestureDetector);
90
91   /**
92    * This method removes the specified gesture detector from the relevant gesture processor.
93    * @param[in]  gestureDetector  The gesture detector to remove.
94    */
95   void RemoveGestureDetector(GestureDetector* gestureDetector);
96
97   /**
98    * This method informs the appropriate processor that the gesture detector has been updated.
99    * @param[in]  gestureDetector  The gesture detector that has been updated.
100    */
101   void GestureDetectorUpdated(GestureDetector* gestureDetector);
102
103   /**
104    * This method is called by GestureDetectors on Started or Continue state events.
105    * Status is queried and reset by Core in ProcessEvents
106    */
107   void SetUpdateRequired();
108
109   /**
110    * Called by GestureDetectors to set the gesture properties in the update thread.
111    * @param[in]  gesture  The gesture whose values will be used in the Update object.
112    * @note If we are in the middle of processing the gesture being set, then this call is ignored.
113    */
114   void SetGestureProperties( const Gesture& gesture );
115
116 public: // Called by Core
117
118   /**
119    * Returns true if any GestureDetector requires a Core::Update. Clears
120    * the state flag after reading.
121    *
122    * @return true if any GestureDetector requires a Core::Update
123    */
124   bool NeedsUpdate();
125
126   /**
127    * Called to provide pan-gesture profiling information.
128    */
129   void EnablePanGestureProfiling();
130
131   /**
132    * @brief Called to set how pan gestures predict input
133    *
134    * @param[in] mode The prediction mode to use
135    */
136   void SetPanGesturePredictionMode( int32_t mode );
137
138   /**
139    * @brief Sets the prediction amount of the pan gesture
140    *
141    * @param[in] amount The prediction amount in milliseconds
142    */
143   void SetPanGesturePredictionAmount( uint32_t amount );
144
145   /**
146    * @brief Sets the upper bound of the prediction amount for clamping
147    *
148    * @param[in] amount The prediction amount in milliseconds
149    */
150   void SetPanGestureMaximumPredictionAmount( uint32_t amount );
151
152   /**
153    * @brief Sets the lower bound of the prediction amount for clamping
154    *
155    * @param[in] amount The prediction amount in milliseconds
156    */
157   void SetPanGestureMinimumPredictionAmount( uint32_t amount );
158
159   /**
160    * @brief Sets the prediction amount to adjust when the pan velocity is changed.
161    * If the pan velocity is accelerating, the prediction amount will be increased
162    * by the specified amount until it reaches the upper bound. If the pan velocity
163    * is decelerating, the prediction amount will be decreased by the specified amount
164    * until it reaches the lower bound.
165    *
166    * @param[in] amount The prediction amount in milliseconds
167    */
168   void SetPanGesturePredictionAmountAdjustment( uint32_t amount );
169
170   /**
171    * @brief Called to set how pan gestures smooth input
172    *
173    * @param[in] mode The smoothing mode to use
174    */
175   void SetPanGestureSmoothingMode( int32_t mode );
176
177   /**
178    * @brief Sets the prediction amount of the pan gesture
179    *
180    * @param[in] amount The smoothing amount [0.0f,1.0f] - 0.0f would be no smoothing, 1.0f maximum smoothing
181    */
182   void SetPanGestureSmoothingAmount( float amount );
183
184   /*
185    * @brief Sets whether to use actual times of the real gesture and frames or not.
186    *
187    * @param[in] value True = use actual times, False = use perfect values
188    */
189   void SetPanGestureUseActualTimes( bool value );
190
191   /**
192    * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
193    *
194    * @param[in] value Time range in ms
195    */
196   void SetPanGestureInterpolationTimeRange( int32_t value );
197
198   /**
199    * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
200    *
201    * @param[in] value True = use scalar prediction only
202    */
203   void SetPanGestureScalarOnlyPredictionEnabled( bool value );
204
205   /**
206    * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
207    *
208    * @param[in] value True = use two point prediction
209    */
210   void SetPanGestureTwoPointPredictionEnabled( bool value );
211
212   /**
213    * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
214    *
215    * @param[in] value Time in past in ms
216    */
217   void SetPanGestureTwoPointInterpolatePastTime( int32_t value );
218
219   /**
220    * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
221    *
222    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
223    */
224   void SetPanGestureTwoPointVelocityBias( float value );
225
226   /**
227    * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
228    *
229    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
230    */
231   void SetPanGestureTwoPointAccelerationBias( float value );
232
233   /**
234    * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
235    *
236    * @param[in] value Time in past in ms
237    */
238   void SetPanGestureMultitapSmoothingRange( int32_t value );
239
240 public: // needed for PanGesture
241
242   /**
243    * @return the pan gesture processor
244    */
245   const PanGestureProcessor& GetPanGestureProcessor();
246
247 private:
248
249   // Undefined
250   GestureEventProcessor(const GestureEventProcessor&);
251   GestureEventProcessor& operator=(const GestureEventProcessor& rhs);
252
253 private:
254
255   Stage& mStage;
256   Integration::GestureManager& mGestureManager;
257
258   LongPressGestureProcessor mLongPressGestureProcessor;
259   PanGestureProcessor mPanGestureProcessor;
260   PinchGestureProcessor mPinchGestureProcessor;
261   TapGestureProcessor mTapGestureProcessor;
262   Integration::RenderController& mRenderController;
263
264   bool mUpdateRequired;     ///< set to true by gesture detectors if they require a Core::Update
265 };
266
267 } // namespace Internal
268
269 } // namespace Dali
270
271 #endif // __DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H__