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

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 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 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..581c6465c899e8d5e73fe64160e4ec37b8da3e8f 100644
--- a/ash/laser/laser_pointer_points.cc
+++ b/ash/laser/laser_pointer_points.cc
@@ -7,6 +7,8 @@
#include <algorithm>
#include <limits>
+#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.
+
namespace ash {
LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration)
@@ -15,11 +17,30 @@ 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()) {
+ // 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.
+ 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; });
+ points_.erase(points_.begin(), first_alive_point);
+ }
+ collection_latest_time_ = latest_time;
}
void LaserPointerPoints::Clear() {
@@ -61,14 +82,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