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 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 static const PredictionMode DEFAULT_PREDICTION_MODE;
56 static const int NUM_PREDICTION_MODES;
58 // Latest Pan Information
61 * Only stores the information we actually require from Dali::PanGesture
66 * Stores the velocity, displacement and position.
77 Info( const Info& rhs )
78 : velocity( rhs.velocity ),
79 displacement( rhs.displacement ),
80 position( rhs.position )
87 Info& operator=( const Info& rhs )
89 velocity = rhs.velocity;
90 displacement = rhs.displacement;
91 position = rhs.position;
108 state( Gesture::Clear ),
116 PanInfo( const PanInfo& rhs )
120 screen( rhs.screen ),
126 * Assignment operator
128 PanInfo& operator=( const PanInfo& rhs )
139 * Assignment operator
140 * @param[in] gesture A Dali::Gesture
142 PanInfo& operator=( const Dali::PanGesture& rhs )
147 local.velocity = rhs.velocity;
148 local.displacement = rhs.displacement;
149 local.position = rhs.position;
151 screen.velocity = rhs.screenVelocity;
152 screen.displacement = rhs.screenDisplacement;
153 screen.position = rhs.screenPosition;
160 Gesture::State state;
166 typedef std::vector<PanInfo> PanInfoHistory;
167 typedef PanInfoHistory::iterator PanInfoHistoryIter;
168 typedef PanInfoHistory::const_iterator PanInfoHistoryConstIter;
171 static const unsigned int PAN_GESTURE_HISTORY = 10u;
176 * Create a new PanGesture
178 static PanGesture* New();
183 virtual ~PanGesture();
186 * Adds a PanGesture to the internal circular-buffer waiting to be handled by UpdateProperties.
187 * @param[in] gesture The latest pan gesture.
189 void AddGesture( const Dali::PanGesture& gesture );
192 * @brief Removes pan events from the history that are older than maxAge, leaving at least minEvents
194 * @param[in] panHistory The pan event history container
195 * @param[in] currentTime The current frame time
196 * @param[in] maxAge Maximum age of an event before removing (in millis)
197 * @param[in] minEvents The minimum number of events to leave in history, oldest events are removed before newest
199 void RemoveOldHistory(PanInfoHistory& panHistory, uint currentTime, uint maxAge, uint minEvents);
202 * USes last two gestures
204 * @param[out] gestureOut Output gesture using average values from last two gestures
206 void SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut);
209 * Uses elapsed time and time stamps
211 void PredictiveAlgorithm1(int eventsThisFrame, PanInfo& gestureOut, PanInfoHistory& panHistory, unsigned int lastVSyncTime, unsigned int nextVSyncTime);
214 * Uses elapsed time, time stamps and future render time
216 void PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut, PanInfoHistory& panHistory, unsigned int lastVSyncTime, unsigned int nextVSyncTime);
219 * Called by the update manager so that we can update the value of our properties.
220 * @param[in] nextRenderTime The estimated time of the next render (in milliseconds).
221 * @return true, if properties were updated.
223 virtual bool UpdateProperties( unsigned int lastRenderTime, unsigned int nextRenderTime );
226 * Retrieves a reference to the panning flag property.
227 * @return The panning flag property.
229 const GesturePropertyBool& GetPanningProperty() const;
232 * Retrieves a reference to the screen position property.
233 * @return The screen position property.
235 const GesturePropertyVector2& GetScreenPositionProperty() const;
238 * Retrieves a reference to the screen displacement property.
239 * @return The screen displacement property.
241 const GesturePropertyVector2& GetScreenDisplacementProperty() const;
244 * Retrieves a reference to the local position property.
245 * @return The local position property.
247 const GesturePropertyVector2& GetLocalPositionProperty() const;
250 * Retrieves a reference to the local displacement property.
251 * @return The local displacement property.
253 const GesturePropertyVector2& GetLocalDisplacementProperty() const;
256 * @brief Sets the prediction mode of the pan gesture
258 * @param[in] mode The prediction mode
260 void SetPredictionMode(PredictionMode mode);
263 * @brief Sets the prediction amount of the pan gesture
265 * @param[in] amount The prediction amount in milliseconds
267 void SetPredictionAmount(unsigned int amount);
270 * Called to provide pan-gesture profiling information.
272 void EnableProfiling();
277 * Protected constructor.
282 PanGesture(const PanGesture&);
285 PanGesture& operator=(const PanGesture&);
288 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
293 GesturePropertyBool mPanning; ///< panning flag
294 GesturePropertyVector2 mScreenPosition; ///< screen-position
295 GesturePropertyVector2 mScreenDisplacement; ///< screen-displacement
296 GesturePropertyVector2 mLocalPosition; ///< local-position
297 GesturePropertyVector2 mLocalDisplacement; ///< local-displacement
299 PanInfo mGestures[PAN_GESTURE_HISTORY]; ///< Circular buffer storing the 4 most recent gestures.
300 PanInfoHistory mPanHistory;
301 unsigned int mWritePosition; ///< The next PanInfo buffer to write to. (starts at 0)
302 unsigned int mReadPosition; ///< The next PanInfo buffer to read. (starts at 0)
304 PanInfo mEventGesture; ///< Result of all pan events received this frame
305 PanInfo mLastEventGesture; ///< The last frame's event gesture.
306 PanInfo mLatestGesture; ///< The latest gesture. (this update frame)
307 bool mInGesture; ///< True if the gesture is currently being handled i.e. between Started <-> Finished/Cancelled
309 PredictionMode mPredictionMode; ///< The pan gesture prediction mode
310 unsigned int mPredictionAmount; ///< how far into future to predict in milliseconds
311 PanGestureProfiling* mProfiling; ///< NULL unless pan-gesture profiling information is required.
314 } // namespace SceneGraph
316 } // namespace Internal
320 #endif // __DALI_INTERNAL_SCENE_GRAPH_PAN_GESTURE_H__