1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PAN_GESTURE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PAN_GESTURE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/events/pan-gesture.h>
23 #include <dali/internal/update/common/property-owner.h>
24 #include <dali/internal/update/gestures/gesture-properties.h>
34 struct PanGestureProfiling;
40 * The latest pan gesture information is stored in this scene object.
42 class PanGesture : public PropertyOwner
54 static const PredictionMode DEFAULT_PREDICTION_MODE;
55 static const int NUM_PREDICTION_MODES;
57 // Latest Pan Information
60 * Only stores the information we actually require from Dali::PanGesture
65 * Stores the velocity, displacement and position.
76 Info( const Info& rhs )
77 : velocity( rhs.velocity ),
78 displacement( rhs.displacement ),
79 position( rhs.position )
86 Info& operator=( const Info& rhs )
88 velocity = rhs.velocity;
89 displacement = rhs.displacement;
90 position = rhs.position;
107 state( Gesture::Clear ),
115 PanInfo( const PanInfo& rhs )
119 screen( rhs.screen ),
125 * Assignment operator
127 PanInfo& operator=( const PanInfo& rhs )
138 * Assignment operator
139 * @param[in] gesture A Dali::Gesture
141 PanInfo& operator=( const Dali::PanGesture& rhs )
146 local.velocity = rhs.velocity;
147 local.displacement = rhs.displacement;
148 local.position = rhs.position;
150 screen.velocity = rhs.screenVelocity;
151 screen.displacement = rhs.screenDisplacement;
152 screen.position = rhs.screenPosition;
159 Gesture::State state;
165 typedef std::vector<PanInfo> PanInfoHistory;
166 typedef PanInfoHistory::iterator PanInfoHistoryIter;
167 typedef PanInfoHistory::const_iterator PanInfoHistoryConstIter;
170 static const unsigned int PAN_GESTURE_HISTORY = 4u;
175 * Create a new PanGesture
177 static PanGesture* New();
182 virtual ~PanGesture();
185 * Adds a PanGesture to the internal circular-buffer waiting to be handled by UpdateProperties.
186 * @param[in] gesture The latest pan gesture.
188 void AddGesture( const Dali::PanGesture& gesture );
191 * @brief Removes pan events from the history that are older than maxAge, leaving at least minEvents
193 * @param[in] panHistory The pan event history container
194 * @param[in] currentTime The current frame time
195 * @param[in] maxAge Maximum age of an event before removing (in millis)
196 * @param[in] minEvents The minimum number of events to leave in history, oldest events are removed before newest
198 void RemoveOldHistory(PanInfoHistory& panHistory, uint currentTime, uint maxAge, uint minEvents);
201 * USes last two gestures
203 * @param[out] gestureOut Output gesture using average values from last two gestures
205 void SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut);
208 * Uses elapsed time and time stamps
210 void PredictiveAlgorithm1(int eventsThisFrame, PanInfo& gestureOut, PanInfoHistory& panHistory, unsigned int lastVSyncTime, unsigned int nextVSyncTime);
213 * Uses elapsed time, time stamps and future render time
215 void PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut, PanInfoHistory& panHistory, unsigned int lastVSyncTime, unsigned int nextVSyncTime);
218 * Called by the update manager so that we can update the value of our properties.
219 * @param[in] nextRenderTime The estimated time of the next render (in milliseconds).
220 * @return true, if properties were updated.
222 virtual bool UpdateProperties( unsigned int lastRenderTime, unsigned int nextRenderTime );
225 * Retrieves a reference to the screen position property.
226 * @return The screen position property.
228 const GesturePropertyVector2& GetScreenPositionProperty() const;
231 * Retrieves a reference to the screen displacement property.
232 * @return The screen displacement property.
234 const GesturePropertyVector2& GetScreenDisplacementProperty() const;
237 * Retrieves a reference to the local position property.
238 * @return The local position property.
240 const GesturePropertyVector2& GetLocalPositionProperty() const;
243 * Retrieves a reference to the local displacement property.
244 * @return The local displacement property.
246 const GesturePropertyVector2& GetLocalDisplacementProperty() const;
249 * @brief Sets the prediction mode of the pan gesture
251 * @param[in] mode The prediction mode
253 void SetPredictionMode(PredictionMode mode) { mPredictionMode = mode; }
256 * Called to provide pan-gesture profiling information.
258 void EnableProfiling();
263 * Protected constructor.
268 PanGesture(const PanGesture&);
271 PanGesture& operator=(const PanGesture&);
274 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
279 GesturePropertyVector2 mScreenPosition; ///< screen-position
280 GesturePropertyVector2 mScreenDisplacement; ///< screen-displacement
281 GesturePropertyVector2 mLocalPosition; ///< local-position
282 GesturePropertyVector2 mLocalDisplacement; ///< local-displacement
284 PanInfo mGestures[PAN_GESTURE_HISTORY]; ///< Circular buffer storing the 4 most recent gestures.
285 PanInfoHistory mPanHistory;
286 unsigned int mWritePosition; ///< The next PanInfo buffer to write to. (starts at 0)
287 unsigned int mReadPosition; ///< The next PanInfo buffer to read. (starts at 0)
289 PanInfo mEventGesture; ///< Result of all pan events received since last frame
290 PanInfo mLatestGesture; ///< The latest gesture. (this update frame)
291 bool mInGesture; ///< True if the gesture is currently being handled i.e. between Started <-> Finished/Cancelled
293 PredictionMode mPredictionMode; ///< The pan gesture prediction mode
294 PanGestureProfiling* mProfiling; ///< NULL unless pan-gesture profiling information is required.
297 } // namespace SceneGraph
299 } // namespace Internal
303 #endif // __DALI_INTERNAL_SCENE_GRAPH_PAN_GESTURE_H__