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

Unified Diff: ash/laser/laser_pointer_points.cc

Issue 2362063002: cros: Laser pointer fades out on release, do not cover palette. (Closed)
Patch Set: Nit. 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
« no previous file with comments | « ash/laser/laser_pointer_points.h ('k') | ash/laser/laser_pointer_points_test_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7ca20966ebb61200b233c618dc72d62ea612c9c3 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();
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.
+ 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(),
+ [](const LaserPoint& p) { return p.age < 1.0; });
+ 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
« no previous file with comments | « ash/laser/laser_pointer_points.h ('k') | ash/laser/laser_pointer_points_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698