Index: ash/common/system/chromeos/palette/tools/laser_pointer_points.h |
diff --git a/ash/common/system/chromeos/palette/tools/laser_pointer_points.h b/ash/common/system/chromeos/palette/tools/laser_pointer_points.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cf646a70df80527d57af4fa5c290e878dae2e3b2 |
--- /dev/null |
+++ b/ash/common/system/chromeos/palette/tools/laser_pointer_points.h |
@@ -0,0 +1,73 @@ |
+// Copyright 2016 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 ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_TOOLS_LASER_POINTER_POINTS_H_ |
+#define ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_TOOLS_LASER_POINTER_POINTS_H_ |
+ |
+#include <deque> |
+#include <memory> |
+#include <vector> |
jdufault
2016/08/17 21:41:08
Do you need the vector include?
sammiequon
2016/08/18 00:52:08
Done.
|
+ |
+#include "base/time/time.h" |
+#include "ui/gfx/geometry/point.h" |
+#include "ui/gfx/geometry/rect.h" |
+ |
+namespace ash { |
+ |
+// LaserPointerPoints is a helper class used for displaying the palette tool |
+// laser pointer. It keeps track of the points needed to render the laser |
+// pointer and its tail. |
+class LaserPointerPoints { |
+ public: |
+ // Struct to describe each point. |
+ struct LaserPoint { |
+ gfx::Point location; |
+ base::Time creation_time; |
+ }; |
+ |
+ // Constructor with a parameter to choose the fade out time of the points in |
+ // the collection. |
+ explicit LaserPointerPoints(base::TimeDelta life_duration); |
+ ~LaserPointerPoints(); |
+ |
+ // Adds a point. Automatically clears points that are too old. |
+ void AddPoint(const gfx::Point& point); |
+ // Removes all points. |
+ void Clear(); |
+ // Gets the bounding box of the points. |
+ gfx::Rect GetBoundingBox() const; |
+ // Returns the oldest point in the collection. |
+ LaserPoint GetOldest() const; |
+ // Returns the newest point in the collection. |
+ LaserPoint GetMostRecent() const; |
+ // Returns the number of points in the collection. |
+ int GetNumberOfPoints() const; |
+ // Whether there are any points or not. |
+ bool IsEmpty() const; |
+ |
+ // Expose the iterator so callers can work with the points. |
+ std::deque<LaserPoint>::const_iterator PointsStart() const; |
+ std::deque<LaserPoint>::const_iterator PointsEnd() const; |
+ |
+ private: |
+ // Generates extra points in an attempt to make the tail look smoother. |
+ void GenerateCurvePoints(const LaserPoint& new_point, |
+ std::vector<LaserPoint>& generated_points); |
+ // Computes the new cumulative bounding box of the points, after a new point |
+ // |point| is added. |
+ void CalculateBounds(const gfx::Point& point); |
+ void ClearOldPoints(); |
+ void RecalculateBounds(); |
+ |
+ base::TimeDelta life_duration_; |
+ gfx::Rect bounds_; |
+ // The collection of points. |
jdufault
2016/08/17 21:41:08
I'd remove this comment.
sammiequon
2016/08/18 00:52:08
Done.
|
+ std::deque<LaserPoint> points_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LaserPointerPoints); |
+}; |
+ |
+} // namespace ash |
+ |
+#endif // ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_TOOLS_LASER_POINTER_POINTS_H_ |