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

Unified Diff: ash/laser/laser_pointer_view.cc

Issue 2362063002: cros: Laser pointer fades out on release, do not cover palette. (Closed)
Patch Set: Fixed patch set 3 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
« ash/laser/laser_pointer_points.cc ('K') | « ash/laser/laser_pointer_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/laser/laser_pointer_view.cc
diff --git a/ash/laser/laser_pointer_view.cc b/ash/laser/laser_pointer_view.cc
index 2bfe8dafb8d353d8d600fee69bbd1360383744ad..ae719a09b514ea2fa2300bcecb68f0f7f147f643 100644
--- a/ash/laser/laser_pointer_view.cc
+++ b/ash/laser/laser_pointer_view.cc
@@ -85,8 +85,14 @@ void LaserPointerView::ReparentWidget(aura::Window* new_root_window) {
}
}
-void LaserPointerView::AddNewPoint(const gfx::Point& new_point) {
- laser_points_.AddPoint(new_point);
+void LaserPointerView::AddNewPoint(const gfx::Point& new_point,
jdufault 2016/10/05 18:08:51 Instead of calling AddNewPoint(dummy, true) what a
sammiequon 2016/10/05 21:15:22 Done.
+ bool fading_away) {
+ // Do not add the point but advance the time if the view is in process of
+ // fading away.
+ if (fading_away)
+ laser_points_.MoveForwardToCurrentTime();
+ else
+ laser_points_.AddPoint(new_point);
// The bounding box should be relative to the screen.
gfx::Point screen_offset =
@@ -113,29 +119,25 @@ void LaserPointerView::OnPaint(gfx::Canvas* canvas) {
paint.setAntiAlias(true);
paint.setStrokeJoin(SkPaint::kBevel_Join);
- base::Time oldest = laser_points_.GetOldest().creation_time;
- base::Time newest = laser_points_.GetNewest().creation_time;
- gfx::Point previous_point = laser_points_.GetOldest().location;
- gfx::Point current_point;
-
// Compute the offset of the current widget.
gfx::Point widget_offset =
widget_->GetNativeView()->GetBoundsInRootWindow().origin();
+
+ gfx::Point previous_point =
jdufault 2016/10/05 18:08:51 gfx::Point previous_point(..., ...);
sammiequon 2016/10/05 21:15:22 Done.
+ gfx::Point((laser_points_.GetOldest().location - widget_offset).x(),
+ (laser_points_.GetOldest().location - widget_offset).y());
+ gfx::Point current_point;
+
int num_points_ = laser_points_.GetNumberOfPoints();
int point_count = 0;
+ int current_opacity = 0;
for (const LaserPointerPoints::LaserPoint& point :
laser_points_.laser_points()) {
- // relative_time is a value between [0,1] where 0 means the point is about
- // to be removed and 1 means that the point was just added.
- double relative_time = 1.0;
- if (oldest != newest) {
- relative_time = 1.0 - ((point.creation_time - oldest).InMillisecondsF() /
- (newest - oldest).InMillisecondsF());
- }
-
// Set the radius and opacity based on the distance.
- double radius = LinearInterpolate(kPointInitialRadius, kPointFinalRadius,
- relative_time);
+ double current_radius =
+ LinearInterpolate(kPointInitialRadius, kPointFinalRadius, point.age);
+ current_opacity = int{LinearInterpolate(
+ double{kPointInitialOpacity}, double{kPointFinalOpacity}, point.age)};
gfx::Vector2d center = point.location - widget_offset;
current_point = gfx::Point(center.x(), center.y());
@@ -144,23 +146,20 @@ void LaserPointerView::OnPaint(gfx::Canvas* canvas) {
// the result will be very jagged, unless we are on the last point, then we
// draw regardless.
point_count++;
- float distance_threshold = float{radius * 2};
+ float distance_threshold = float{current_radius * 2};
if (DistanceBetweenPoints(previous_point, current_point) <=
distance_threshold &&
point_count != num_points_) {
continue;
}
- int opacity =
- int{LinearInterpolate(double{kPointInitialOpacity},
- double{kPointFinalOpacity}, relative_time)};
- paint.setColor(SkColorSetA(kPointColor, opacity));
- paint.setStrokeWidth(radius * 2);
+ paint.setColor(SkColorSetA(kPointColor, current_opacity));
+ paint.setStrokeWidth(current_radius * 2);
canvas->DrawLine(previous_point, current_point, paint);
previous_point = current_point;
}
// Draw the last point as a circle.
- paint.setColor(SkColorSetA(kPointColor, kPointInitialOpacity));
+ paint.setColor(SkColorSetA(kPointColor, current_opacity));
paint.setStyle(SkPaint::kFill_Style);
canvas->DrawCircle(current_point, kPointInitialRadius, paint);
}
« ash/laser/laser_pointer_points.cc ('K') | « ash/laser/laser_pointer_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698