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

Side by Side Diff: remoting/client/gl_cursor_feedback.cc

Issue 2265053005: [Remoting Android] Use Material Design's Ripple Expansion Function for Touch Feedback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/gl_cursor_feedback.h" 5 #include "remoting/client/gl_cursor_feedback.h"
6 6
7 #include <math.h> 7 #include <math.h>
8
8 #include <array> 9 #include <array>
9 10
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "remoting/client/gl_canvas.h" 12 #include "remoting/client/gl_canvas.h"
12 #include "remoting/client/gl_cursor_feedback_texture.h" 13 #include "remoting/client/gl_cursor_feedback_texture.h"
13 #include "remoting/client/gl_math.h" 14 #include "remoting/client/gl_math.h"
14 #include "remoting/client/gl_render_layer.h" 15 #include "remoting/client/gl_render_layer.h"
15 #include "remoting/client/gl_texture_ids.h" 16 #include "remoting/client/gl_texture_ids.h"
16 17
17 namespace { 18 namespace {
18 const float kAnimationDurationMs = 220.f; 19
20 const float kAnimationDurationMs = 300.f;
21
22 // This function is for calculating the size of the feedback animation circle at
23 // the moment when the animation progress is |progress|.
24 // |progress|: [0, 1], indicating the progress of the animation.
25 // Returns a coefficient in [0, 1]. It will be multiplied with the maximum
26 // diameter of the feedback circle to get the current diameter of the feedback
27 // circle.
28 float GetExpansionCoefficient(float progress) {
29 DCHECK(progress >= 0 && progress <= 1);
30
31 // Decelerating expansion. This is conforming to the material design spec.
32 // More time will be spent showing the larger circle and the animation will
33 // look more rapid given the same time duration.
34 auto get_unnormalized_coeff = [](float progress) {
35 static const float kExpansionBase = 400.f;
36 return 1.f - pow(kExpansionBase, -progress);
37 };
38 static const float kExpansionNormalization = get_unnormalized_coeff(1);
39 return get_unnormalized_coeff(progress) / kExpansionNormalization;
40 }
41
19 } // namespace 42 } // namespace
20 43
21 namespace remoting { 44 namespace remoting {
22 45
23 GlCursorFeedback::GlCursorFeedback() {} 46 GlCursorFeedback::GlCursorFeedback() {}
24 47
25 GlCursorFeedback::~GlCursorFeedback() {} 48 GlCursorFeedback::~GlCursorFeedback() {}
26 49
27 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) { 50 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) {
28 if (!canvas) { 51 if (!canvas) {
(...skipping 18 matching lines...) Expand all
47 if (!layer_ || animation_start_time_.is_null()) { 70 if (!layer_ || animation_start_time_.is_null()) {
48 return false; 71 return false;
49 } 72 }
50 float progress = 73 float progress =
51 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / 74 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() /
52 kAnimationDurationMs; 75 kAnimationDurationMs;
53 if (progress > 1) { 76 if (progress > 1) {
54 animation_start_time_ = base::TimeTicks(); 77 animation_start_time_ = base::TimeTicks();
55 return false; 78 return false;
56 } 79 }
57 float diameter = progress * max_diameter_; 80 float diameter = GetExpansionCoefficient(progress) * max_diameter_;
58 std::array<float, 8> positions; 81 std::array<float, 8> positions;
59 FillRectangleVertexPositions(cursor_x_ - diameter / 2, 82 FillRectangleVertexPositions(cursor_x_ - diameter / 2,
60 cursor_y_ - diameter / 2, 83 cursor_y_ - diameter / 2,
61 diameter, diameter, &positions); 84 diameter, diameter, &positions);
62 layer_->SetVertexPositions(positions); 85 layer_->SetVertexPositions(positions);
86
87 // Linear fade-out.
63 layer_->Draw(1.f - progress); 88 layer_->Draw(1.f - progress);
64 return true; 89 return true;
65 } 90 }
66 91
67 } // namespace remoting 92 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698