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/timer/timer.h" |
| 13 #include "ui/gfx/geometry/point.h" |
| 14 #include "ui/gfx/geometry/rect.h" |
| 15 |
| 16 namespace ash { |
| 17 // LaserPointerPoints is a helper class used for displaying the palette tool |
| 18 // laser pointer. It keeps track of the points needed to render the laser |
| 19 // pointer and its trailing tail. |
| 20 class LaserPointerPoints { |
| 21 public: |
| 22 // Struct to describe each point. |
| 23 struct LaserPointerPoint { |
| 24 gfx::Point location_; |
| 25 base::Time creationTime_; |
| 26 }; |
| 27 |
| 28 // Constructor with a parameter to choose the fade out time off the points in |
| 29 // the collection. |
| 30 LaserPointerPoints(base::TimeDelta life_duration); |
| 31 LaserPointerPoints(const LaserPointerPoints& old); |
| 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 LaserPointerPoint GetOldest() const; |
| 42 // Returns the newest point in the collection. |
| 43 LaserPointerPoint 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<LaserPointerPoint>::const_iterator PointsStart() const; |
| 51 std::deque<LaserPointerPoint>::const_iterator PointsEnd() const; |
| 52 private: |
| 53 // Determines the distance of the points. |
| 54 float DistanceMousePoints(const LaserPointerPoint& point1, |
| 55 const LaserPointerPoint& point2); |
| 56 // Generates extra points in an attempt to make the tail look smoother. |
| 57 void GenerateCurvePoints(const LaserPointerPoint& newPoint, |
| 58 std::vector<LaserPointerPoint>& generatedPoints); |
| 59 // Computes the new cummulative bounding box of the points. |
| 60 void CalculateBounds(const gfx::Point& point); |
| 61 void ClearOldPoints(); |
| 62 // Computes the bounding box of the points from scratch. Iterates over the |
| 63 // entire collection. |
| 64 void RecalculateBounds(); |
| 65 |
| 66 base::TimeDelta life_duration_; |
| 67 gfx::Rect bounds_; |
| 68 // The collection of points. |
| 69 std::deque<LaserPointerPoint> points_; |
| 70 }; |
| 71 |
| 72 } // namespace ash |
| 73 |
| 74 #endif // ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_TOOLS_LASER_POINTER_POINTS_H_ |
OLD | NEW |