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

Unified Diff: ash/laser/laser_pointer_view.cc

Issue 2362063002: cros: Laser pointer fades out on release, do not cover palette. (Closed)
Patch Set: Created 4 years, 3 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_view.h ('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..0f422e881ac0566639d3c00224cc5bf01ad88b28 100644
--- a/ash/laser/laser_pointer_view.cc
+++ b/ash/laser/laser_pointer_view.cc
@@ -86,7 +86,12 @@ void LaserPointerView::ReparentWidget(aura::Window* new_root_window) {
}
void LaserPointerView::AddNewPoint(const gfx::Point& new_point) {
- laser_points_.AddPoint(new_point);
+ // Do not add the point but advance the time if the view is in process of
+ // fading away.
+ if (is_fading_away_)
+ laser_points_.MoveForwardInTime();
+ else
+ laser_points_.AddPoint(new_point);
// The bounding box should be relative to the screen.
gfx::Point screen_offset =
@@ -104,6 +109,14 @@ void LaserPointerView::AddNewPoint(const gfx::Point& new_point) {
SchedulePaint();
}
+void LaserPointerView::SetIsFadingAway(bool is_fading) {
+ is_fading_away_ = is_fading;
+}
+
+bool LaserPointerView::GetIsFadingAway() const {
+ return is_fading_away_;
+}
+
void LaserPointerView::OnPaint(gfx::Canvas* canvas) {
if (laser_points_.IsEmpty())
return;
@@ -113,29 +126,37 @@ 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();
+
+ base::Time oldest = laser_points_.GetCollectionEarliestTime();
+ base::Time newest = laser_points_.GetCollectionLatestTime();
+ gfx::Vector2d previous_point_vector =
+ laser_points_.GetOldest().location - widget_offset;
+ gfx::Point previous_point =
+ gfx::Point(previous_point_vector.x(), previous_point_vector.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;
+ double relative_time = 0.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, relative_time);
+ current_opacity =
+ int{LinearInterpolate(double{kPointInitialOpacity},
+ double{kPointFinalOpacity}, relative_time)};
gfx::Vector2d center = point.location - widget_offset;
current_point = gfx::Point(center.x(), center.y());
@@ -144,23 +165,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_view.h ('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