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

Unified 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 7 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 side-by-side diff with in-line comments
Download patch
Index: ash/laser/laser_pointer_points.cc
diff --git a/ash/laser/laser_pointer_points.cc b/ash/laser/laser_pointer_points.cc
index 8f2176ed8dbdfe42a5a5d5d2e78c3425e5797c5b..28af4f6c7f6ad0849509007da1983c134cb5a49f 100644
--- a/ash/laser/laser_pointer_points.cc
+++ b/ash/laser/laser_pointer_points.cc
@@ -15,11 +15,31 @@ LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration)
LaserPointerPoints::~LaserPointerPoints() {}
void LaserPointerPoints::AddPoint(const gfx::Point& point) {
+ MoveForwardToTime(base::Time::Now());
+
LaserPoint new_point;
new_point.location = point;
- new_point.creation_time = base::Time::Now();
+ new_point.age = 0.0;
points_.push_back(new_point);
- ClearOldPoints();
+}
+
+void LaserPointerPoints::MoveForwardToTime(const base::Time& latest_time) {
+ if (!points_.empty()) {
+ DCHECK(!collection_latest_time_.is_null());
+ // Increase the age of points based on how much time has elapsed.
jdufault 2016/10/14 19:13:09 Newline between the DCHECK and the comment.
sammiequon 2016/10/14 21:29:32 Done.
+ base::TimeDelta delta = latest_time - collection_latest_time_;
+ double lifespan_change =
+ delta.InMillisecondsF() / life_duration_.InMillisecondsF();
+ for (LaserPoint& point : points_)
+ point.age += lifespan_change;
+
+ // Remove points that are too old (points age older than 1.0).
+ auto first_alive_point =
+ std::find_if(points_.begin(), points_.end(),
+ [](LaserPoint& p) { return p.age < 1.0; });
jdufault 2016/10/14 19:13:09 const LaserPoint& p
sammiequon 2016/10/14 21:29:32 Done.
+ points_.erase(points_.begin(), first_alive_point);
+ }
+ collection_latest_time_ = latest_time;
}
void LaserPointerPoints::Clear() {
@@ -61,14 +81,4 @@ const std::deque<LaserPointerPoints::LaserPoint>&
LaserPointerPoints::laser_points() {
return points_;
}
-
-void LaserPointerPoints::ClearOldPoints() {
- DCHECK(!IsEmpty());
- auto first_alive_point =
- std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) {
- return GetNewest().creation_time - p.creation_time < life_duration_;
- });
- points_.erase(points_.begin(), first_alive_point);
-}
-
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698