Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1351)

Side by Side Diff: ash/laser/laser_pointer_points.cc

Issue 2362063002: cros: Laser pointer fades out on release, do not cover palette. (Closed)
Patch Set: Fixed patch set 6 errors. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/laser/laser_pointer_points.h" 5 #include "ash/laser/laser_pointer_points.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/macros.h"
jdufault 2016/10/13 00:12:30 Include this in the header file since you're using
sammiequon 2016/10/14 18:48:50 Done.
11
10 namespace ash { 12 namespace ash {
11 13
12 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) 14 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration)
13 : life_duration_(life_duration) {} 15 : life_duration_(life_duration) {}
14 16
15 LaserPointerPoints::~LaserPointerPoints() {} 17 LaserPointerPoints::~LaserPointerPoints() {}
16 18
17 void LaserPointerPoints::AddPoint(const gfx::Point& point) { 19 void LaserPointerPoints::AddPoint(const gfx::Point& point) {
20 MoveForwardToTime(base::Time::Now());
21
18 LaserPoint new_point; 22 LaserPoint new_point;
19 new_point.location = point; 23 new_point.location = point;
20 new_point.creation_time = base::Time::Now(); 24 new_point.age = 0.0;
21 points_.push_back(new_point); 25 points_.push_back(new_point);
22 ClearOldPoints(); 26 }
27
28 void LaserPointerPoints::MoveForwardToTime(const base::Time& latest_time) {
29 if (!points_.empty()) {
30 // Update the ages of the points based on the change in new latest time.
jdufault 2016/10/13 00:12:30 What about // Increase the age of points based on
jdufault 2016/10/13 00:12:30 DCHECK(!collection_latest_time_.is_null());
sammiequon 2016/10/14 18:48:50 Done.
sammiequon 2016/10/14 18:48:50 Done.
31 base::TimeDelta delta = latest_time - collection_latest_time_;
32 double lifespan_change =
33 delta.InMillisecondsF() / life_duration_.InMillisecondsF();
34 for (LaserPoint& point : points_)
35 point.age += lifespan_change;
36
37 // Remove points that are too old (points age older than 1.0).
38 auto first_alive_point =
39 std::find_if(points_.begin(), points_.end(),
40 [](LaserPoint& p) { return p.age < 1.0; });
41 points_.erase(points_.begin(), first_alive_point);
42 }
43 collection_latest_time_ = latest_time;
23 } 44 }
24 45
25 void LaserPointerPoints::Clear() { 46 void LaserPointerPoints::Clear() {
26 points_.clear(); 47 points_.clear();
27 } 48 }
28 49
29 gfx::Rect LaserPointerPoints::GetBoundingBox() { 50 gfx::Rect LaserPointerPoints::GetBoundingBox() {
30 if (IsEmpty()) 51 if (IsEmpty())
31 return gfx::Rect(); 52 return gfx::Rect();
32 53
(...skipping 21 matching lines...) Expand all
54 } 75 }
55 76
56 int LaserPointerPoints::GetNumberOfPoints() const { 77 int LaserPointerPoints::GetNumberOfPoints() const {
57 return points_.size(); 78 return points_.size();
58 } 79 }
59 80
60 const std::deque<LaserPointerPoints::LaserPoint>& 81 const std::deque<LaserPointerPoints::LaserPoint>&
61 LaserPointerPoints::laser_points() { 82 LaserPointerPoints::laser_points() {
62 return points_; 83 return points_;
63 } 84 }
64
65 void LaserPointerPoints::ClearOldPoints() {
66 DCHECK(!IsEmpty());
67 auto first_alive_point =
68 std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) {
69 return GetNewest().creation_time - p.creation_time < life_duration_;
70 });
71 points_.erase(points_.begin(), first_alive_point);
72 }
73
74 } // namespace ash 85 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698