OLD | NEW |
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 #include <array> | 8 #include <array> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 layer_.reset(); | 29 layer_.reset(); |
30 return; | 30 return; |
31 } | 31 } |
32 layer_.reset(new GlRenderLayer(kGlCursorFeedbackTextureId, canvas)); | 32 layer_.reset(new GlRenderLayer(kGlCursorFeedbackTextureId, canvas)); |
33 GlCursorFeedbackTexture* texture = GlCursorFeedbackTexture::GetInstance(); | 33 GlCursorFeedbackTexture* texture = GlCursorFeedbackTexture::GetInstance(); |
34 layer_->SetTexture(texture->GetTexture().data(), | 34 layer_->SetTexture(texture->GetTexture().data(), |
35 GlCursorFeedbackTexture::kTextureWidth, | 35 GlCursorFeedbackTexture::kTextureWidth, |
36 GlCursorFeedbackTexture::kTextureWidth, 0); | 36 GlCursorFeedbackTexture::kTextureWidth, 0); |
37 } | 37 } |
38 | 38 |
39 void GlCursorFeedback::StartAnimation(int x, int y, float diameter) { | 39 void GlCursorFeedback::StartAnimation(float x, float y, float diameter) { |
40 cursor_x_ = x; | 40 cursor_x_ = x; |
41 cursor_y_ = y; | 41 cursor_y_ = y; |
42 max_diameter_ = diameter; | 42 max_diameter_ = diameter; |
43 animation_start_time_ = base::TimeTicks::Now(); | 43 animation_start_time_ = base::TimeTicks::Now(); |
44 } | 44 } |
45 | 45 |
46 bool GlCursorFeedback::Draw() { | 46 bool GlCursorFeedback::Draw() { |
47 if (!layer_ || animation_start_time_.is_null()) { | 47 if (!layer_ || animation_start_time_.is_null()) { |
48 return false; | 48 return false; |
49 } | 49 } |
50 float progress = | 50 float progress = |
51 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / | 51 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / |
52 kAnimationDurationMs; | 52 kAnimationDurationMs; |
53 if (progress > 1) { | 53 if (progress > 1) { |
54 animation_start_time_ = base::TimeTicks(); | 54 animation_start_time_ = base::TimeTicks(); |
55 return false; | 55 return false; |
56 } | 56 } |
57 float diameter = progress * max_diameter_; | 57 float diameter = progress * max_diameter_; |
58 std::array<float, 8> positions; | 58 std::array<float, 8> positions; |
59 FillRectangleVertexPositions(cursor_x_ - diameter / 2, | 59 FillRectangleVertexPositions(cursor_x_ - diameter / 2, |
60 cursor_y_ - diameter / 2, | 60 cursor_y_ - diameter / 2, |
61 diameter, diameter, &positions); | 61 diameter, diameter, &positions); |
62 layer_->SetVertexPositions(positions); | 62 layer_->SetVertexPositions(positions); |
63 layer_->Draw(1.f - progress); | 63 layer_->Draw(1.f - progress); |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 } // namespace remoting | 67 } // namespace remoting |
OLD | NEW |