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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/gl_cursor_feedback.cc
diff --git a/remoting/client/gl_cursor_feedback.cc b/remoting/client/gl_cursor_feedback.cc
index 8306933013e18f2919a50b45db7ba4c878fe731a..ff4c9a9713af6c751a1d9563265df363500ff989 100644
--- a/remoting/client/gl_cursor_feedback.cc
+++ b/remoting/client/gl_cursor_feedback.cc
@@ -5,6 +5,7 @@
#include "remoting/client/gl_cursor_feedback.h"
#include <math.h>
+
#include <array>
#include "base/logging.h"
@@ -15,7 +16,29 @@
#include "remoting/client/gl_texture_ids.h"
namespace {
-const float kAnimationDurationMs = 220.f;
+
+const float kAnimationDurationMs = 300.f;
+
+// This function is for calculating the size of the feedback animation circle at
+// the moment when the animation progress is |progress|.
+// |progress|: [0, 1], indicating the progress of the animation.
+// Returns a coefficient in [0, 1]. It will be multiplied with the maximum
+// diameter of the feedback circle to get the current diameter of the feedback
+// circle.
+float GetExpansionCoefficient(float progress) {
+ DCHECK(progress >= 0 && progress <= 1);
+
+ // Decelerating expansion. This is conforming to the material design spec.
+ // More time will be spent showing the larger circle and the animation will
+ // look more rapid given the same time duration.
+ auto get_unnormalized_coeff = [](float progress) {
+ static const float kExpansionBase = 400.f;
+ return 1.f - pow(kExpansionBase, -progress);
+ };
+ static const float kExpansionNormalization = get_unnormalized_coeff(1);
+ return get_unnormalized_coeff(progress) / kExpansionNormalization;
+}
+
} // namespace
namespace remoting {
@@ -54,13 +77,13 @@ bool GlCursorFeedback::Draw() {
animation_start_time_ = base::TimeTicks();
return false;
}
- float diameter = progress * max_diameter_;
+ float diameter = GetExpansionCoefficient(progress) * max_diameter_;
std::array<float, 8> positions;
FillRectangleVertexPositions(cursor_x_ - diameter / 2,
cursor_y_ - diameter / 2,
diameter, diameter, &positions);
layer_->SetVertexPositions(positions);
- layer_->Draw(1.f - progress);
+ layer_->Draw(1.f - progress); // linear fade-out.
joedow 2016/08/23 01:58:42 nit: move comment above the code.
Yuwei 2016/08/23 04:02:52 Done.
return true;
}
« 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