Index: remoting/client/fling_tracker.h |
diff --git a/remoting/client/fling_tracker.h b/remoting/client/fling_tracker.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2bc36afb74568d15a1499288e2191387415fb0e9 |
--- /dev/null |
+++ b/remoting/client/fling_tracker.h |
@@ -0,0 +1,48 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_CLIENT_FLING_TRACKER_H_ |
+#define REMOTING_CLIENT_FLING_TRACKER_H_ |
+ |
+#include "base/time/time.h" |
+ |
+namespace remoting { |
+ |
+// A class for tracking the positions of an object moving through a viscous |
+// liquid. |
+class FlingTracker { |
+ public: |
+ // time_constant: The larger the number the longer it takes to fling. |
+ FlingTracker(float time_constant); |
+ |
+ ~FlingTracker(); |
+ |
+ // Sets the position of the object and start fling. This will reset the |
+ // existing fling. |
+ void StartFling(float velocity_x, float velocity_y); |
+ |
+ void StopFling(); |
+ |
+ bool IsFlingInProgress() const; |
+ |
+ // Moves forward the object and catch up with |time|. The new positions will |
+ // be writen to |x| and |y|. |
+ // Returns true if the fling is still in progress at |time|, false otherwise, |
+ // in which case |x| and |y| will not be touched. |
+ bool TrackPositions(base::TimeTicks time, float* x, float* y); |
nicholss
2017/05/10 19:34:05
Might be simpler if you just return deltaX, deltaY
Yuwei
2017/05/10 23:28:24
Done.
I was looking at the Android Scroller, whic
|
+ |
+ private: |
+ float time_constant_; |
+ float initial_speed_rate_ = 0.f; |
+ float velocity_ratio_x_ = 0.f; |
+ float velocity_ratio_y_ = 0.f; |
+ base::TimeTicks start_time_; |
+ |
+ // FlingTracker is neither copyable nor movable. |
+ FlingTracker(const FlingTracker&) = delete; |
+ FlingTracker& operator=(const FlingTracker&) = delete; |
+}; |
+ |
+} // namespace remoting |
+#endif // REMOTING_CLIENT_FLING_TRACKER_H_ |