1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PAN_GESTURE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PAN_GESTURE_H__
5 * Copyright (c) 2016 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/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/events/pan-gesture.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/gestures/gesture-properties.h>
35 struct PanGestureProfiling;
41 * The latest pan gesture information is stored in this scene object.
43 class PanGesture : public PropertyOwner
55 SMOOTHING_NONE, // no smoothing
56 SMOOTHING_LAST_VALUE, // smooth between last value and latest value
59 static const PredictionMode DEFAULT_PREDICTION_MODE;
60 static const int NUM_PREDICTION_MODES;
62 static const SmoothingMode DEFAULT_SMOOTHING_MODE;
63 static const int NUM_SMOOTHING_MODES;
65 // Latest Pan Information
68 * Only stores the information we actually require from Dali::PanGesture
73 * Stores the velocity, displacement and position.
84 Info( const Info& rhs )
85 : velocity( rhs.velocity ),
86 displacement( rhs.displacement ),
87 position( rhs.position )
94 Info& operator=( const Info& rhs )
98 velocity = rhs.velocity;
99 displacement = rhs.displacement;
100 position = rhs.position;
109 Vector2 displacement;
118 state( Gesture::Clear ),
126 PanInfo( const PanInfo& rhs )
130 screen( rhs.screen ),
136 * Assignment operator
138 PanInfo& operator=( const PanInfo& rhs )
152 * Assignment operator
153 * @param[in] gesture A Dali::Gesture
155 PanInfo& operator=( const Dali::PanGesture& rhs )
160 local.velocity = rhs.velocity;
161 local.displacement = rhs.displacement;
162 local.position = rhs.position;
164 screen.velocity = rhs.screenVelocity;
165 screen.displacement = rhs.screenDisplacement;
166 screen.position = rhs.screenPosition;
173 Gesture::State state;
179 typedef std::vector<PanInfo> PanInfoHistory;
180 typedef PanInfoHistory::iterator PanInfoHistoryIter;
181 typedef PanInfoHistory::const_iterator PanInfoHistoryConstIter;
184 static const unsigned int PAN_GESTURE_HISTORY = 10u;
189 * Create a new PanGesture
191 static PanGesture* New();
196 virtual ~PanGesture();
199 * Adds a PanGesture to the internal circular-buffer waiting to be handled by UpdateProperties.
200 * @param[in] gesture The latest pan gesture.
202 void AddGesture( const Dali::PanGesture& gesture );
205 * @brief Removes pan events from the history that are older than maxAge, leaving at least minEvents
207 * @param[in] panHistory The pan event history container
208 * @param[in] currentTime The current frame time
209 * @param[in] maxAge Maximum age of an event before removing (in millis)
210 * @param[in] minEvents The minimum number of events to leave in history, oldest events are removed before newest
212 void RemoveOldHistory(PanInfoHistory& panHistory, unsigned int currentTime, unsigned int maxAge, unsigned int minEvents);
215 * Uses elapsed time and time stamps
217 void PredictiveAlgorithm1(int eventsThisFrame, PanInfo& gestureOut, PanInfoHistory& panHistory, unsigned int lastVSyncTime, unsigned int nextVSyncTime);
220 * Uses last two gestures
222 * @param[in] justStarted Whether the pan has just started.
223 * @param[out] gestureOut Output gesture using average values from last two gestures
224 * @param[in] lastVSyncTime The time to set on gestureOut.
226 void SmoothingAlgorithm1(bool justStarted, PanInfo& gestureOut, unsigned int lastVSyncTime);
229 * Future smoothing method, implementation not complete
231 void SmoothingAlgorithm2(bool justStarted, PanInfo& gestureOut, unsigned int lastVSyncTime);
234 * Called by the update manager so that we can update the value of our properties.
235 * @param[in] nextRenderTime The estimated time of the next render (in milliseconds).
236 * @return true, if properties were updated.
238 virtual bool UpdateProperties( unsigned int lastRenderTime, unsigned int nextRenderTime );
241 * Retrieves a reference to the panning flag property.
242 * @return The panning flag property.
244 const GesturePropertyBool& GetPanningProperty() const;
247 * Retrieves a reference to the screen position property.
248 * @return The screen position property.
250 const GesturePropertyVector2& GetScreenPositionProperty() const;
253 * Retrieves a reference to the screen velocity property.
254 * @return The screen velocity property.
256 const GesturePropertyVector2& GetScreenVelocityProperty() const;
259 * Retrieves a reference to the screen displacement property.
260 * @return The screen displacement property.
262 const GesturePropertyVector2& GetScreenDisplacementProperty() const;
265 * Retrieves a reference to the local position property.
266 * @return The local position property.
268 const GesturePropertyVector2& GetLocalPositionProperty() const;
271 * Retrieves a reference to the local displacement property.
272 * @return The local displacement property.
274 const GesturePropertyVector2& GetLocalDisplacementProperty() const;
277 * Retrieves a reference to the local velocity property.
278 * @return The local velocity property.
280 const GesturePropertyVector2& GetLocalVelocityProperty() const;
283 * @brief Sets the prediction mode of the pan gesture
285 * @param[in] mode The prediction mode
287 void SetPredictionMode(PredictionMode mode);
290 * @brief Sets the prediction amount of the pan gesture
292 * @param[in] amount The prediction amount in milliseconds
294 void SetPredictionAmount(unsigned int amount);
297 * @brief Sets the upper bound of the prediction amount for clamping
299 * @param[in] amount The prediction amount in milliseconds
301 void SetMaximumPredictionAmount(unsigned int amount);
304 * @brief Sets the lower bound of the prediction amount for clamping
306 * @param[in] amount The prediction amount in milliseconds
308 void SetMinimumPredictionAmount(unsigned int amount);
311 * @brief Sets the amount of prediction interpolation to adjust when the pan velocity is changed
313 * @param[in] amount The prediction amount in milliseconds
315 void SetPredictionAmountAdjustment(unsigned int amount);
318 * @brief Sets the prediction mode of the pan gesture
320 * @param[in] mode The prediction mode
322 void SetSmoothingMode(SmoothingMode mode);
325 * @brief Sets the amount of smoothing to apply for the current smoothing mode
327 * @param[in] amount The amount of smoothing [0.0f,1.0f]
329 void SetSmoothingAmount(float amount);
332 * Called to provide pan-gesture profiling information.
334 void EnableProfiling();
339 * Protected constructor.
344 PanGesture(const PanGesture&);
347 PanGesture& operator=(const PanGesture&);
350 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
352 // Defines information to be gathered by the gesture reading code.
353 struct FrameGestureInfo
355 PanGesture::PanInfo frameGesture;
357 unsigned int eventsThisFrame;
362 : acceleration( 0.0f ),
363 eventsThisFrame( 0 ),
364 justStarted( false ),
365 justFinished( false )
371 * Reads gestures from input, builds history.
372 * @param[out] info Written to with information about gestures read this frame.
373 * @param[in] currentTimestamp The time of this frame.
375 bool ReadGestures( FrameGestureInfo& info, unsigned int currentTimestamp );
378 * Reads gestures from input and resamples data, builds history.
379 * @param[out] info Written to with information about gestures read this frame.
380 * @param[in] currentTimestamp The time of this frame.
382 bool ReadAndResampleGestures( FrameGestureInfo& info, unsigned int currentTimestamp );
387 GesturePropertyBool mPanning; ///< panning flag
388 GesturePropertyVector2 mScreenPosition; ///< screenPosition
389 GesturePropertyVector2 mScreenDisplacement; ///< screenDisplacement
390 GesturePropertyVector2 mScreenVelocity; ///< screenVelocity
391 GesturePropertyVector2 mLocalPosition; ///< localPosition
392 GesturePropertyVector2 mLocalDisplacement; ///< localDisplacement
393 GesturePropertyVector2 mLocalVelocity; ///< localVelocity
395 PanInfoHistory mPanHistory;
396 PanInfoHistory mPredictionHistory;
397 PanInfo mGestures[PAN_GESTURE_HISTORY]; ///< Circular buffer storing the 4 most recent gestures.
398 PanInfo mLastGesture; ///< The last gesture. (last update frame).
399 PanInfo mTargetGesture; ///< The most recent input gesture, if the current used gesture does not match.
400 PanInfo mLastUnmodifiedGesture; ///< The last gesture before any processing was done on it.
401 unsigned int mWritePosition; ///< The next PanInfo buffer to write to. (starts at 0).
402 unsigned int mReadPosition; ///< The next PanInfo buffer to read. (starts at 0).
403 bool mNotAtTarget; ///< Keeps track of if the last gesture used was the most recent received.
404 bool mInGesture; ///< True if the gesture is currently being handled i.e. between Started <-> Finished/Cancelled.
406 PredictionMode mPredictionMode; ///< The pan gesture prediction mode
407 unsigned int mPredictionAmount; ///< how far into future to predict in milliseconds
408 unsigned int mCurrentPredictionAmount; ///< the current prediction amount used by the prediction algorithm
409 unsigned int mMaxPredictionAmount; ///< the maximum prediction amount used by the prediction algorithm
410 unsigned int mMinPredictionAmount; ///< the minimum prediction amount used by the prediction algorithm
411 unsigned int mPredictionAmountAdjustment; ///< the prediction amount to adjust in milliseconds when pan velocity changes
412 SmoothingMode mSmoothingMode; ///< The pan gesture prediction mode
413 float mSmoothingAmount; ///< How much smoothing to apply [0.0f,1.0f]
414 PanGestureProfiling* mProfiling; ///< NULL unless pan-gesture profiling information is required.
417 } // namespace SceneGraph
419 } // namespace Internal
423 #endif // __DALI_INTERNAL_SCENE_GRAPH_PAN_GESTURE_H__