Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_TOOLS_LASER_POINTER_POINTS_H_ | |
| 6 #define ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_TOOLS_LASER_POINTER_POINTS_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include <memory> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/time/time.h" | |
| 13 #include "ui/gfx/geometry/point.h" | |
| 14 #include "ui/gfx/geometry/rect.h" | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 // LaserPointerPoints is a helper class used for displaying the palette tool | |
| 19 // laser pointer. It keeps track of the points needed to render the laser | |
| 20 // pointer and its tail. | |
| 21 class LaserPointerPoints { | |
| 22 public: | |
| 23 // Struct to describe each point. | |
| 24 struct LaserPoint { | |
| 25 gfx::Point location; | |
| 26 base::Time creation_time; | |
| 27 }; | |
| 28 | |
| 29 // Constructor with a parameter to choose the fade out time off the points in | |
|
jdufault
2016/08/16 19:33:56
off => of
sammiequon
2016/08/16 23:18:54
Done.
| |
| 30 // the collection. | |
| 31 explicit LaserPointerPoints(base::TimeDelta life_duration); | |
| 32 ~LaserPointerPoints(); | |
| 33 | |
| 34 // Adds a point. Automatically clears points that are too old. | |
| 35 void AddPoint(const gfx::Point& point); | |
| 36 // Removes all points. | |
| 37 void Clear(); | |
| 38 // Gets the bounding box of the points. | |
| 39 gfx::Rect GetBoundingBox() const; | |
| 40 // Returns the oldest point in the collection. | |
| 41 LaserPoint GetOldest() const; | |
| 42 // Returns the newest point in the collection. | |
| 43 LaserPoint GetMostRecent() const; | |
| 44 // Returns the number of points in the collection. | |
| 45 int GetNumberOfPoints() const; | |
| 46 // Whether there are any points or not. | |
| 47 bool IsEmpty() const; | |
| 48 | |
| 49 // Expose the iterator so callers can work with the points. | |
| 50 std::deque<LaserPoint>::const_iterator PointsStart() const; | |
| 51 std::deque<LaserPoint>::const_iterator PointsEnd() const; | |
| 52 | |
| 53 private: | |
| 54 // Generates extra points in an attempt to make the tail look smoother. | |
| 55 void GenerateCurvePoints(const LaserPoint& new_point, | |
| 56 std::vector<LaserPoint>& generated_points); | |
| 57 // Computes the new cumulative bounding box of the points, after a new point | |
| 58 // |point| is added. | |
| 59 void CalculateBounds(const gfx::Point& point); | |
| 60 void ClearOldPoints(); | |
| 61 | |
| 62 base::TimeDelta life_duration_; | |
| 63 gfx::Rect bounds_; | |
| 64 // The collection of points. | |
| 65 std::deque<LaserPoint> points_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(LaserPointerPoints); | |
| 68 }; | |
| 69 | |
| 70 } // namespace ash | |
| 71 | |
| 72 #endif // ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_TOOLS_LASER_POINTER_POINTS_H_ | |
| OLD | NEW |