OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/client/gl_cursor_feedback.h" |
| 6 |
| 7 #include <math.h> |
| 8 #include <array> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "remoting/client/gl_canvas.h" |
| 12 #include "remoting/client/gl_cursor_feedback_texture.h" |
| 13 #include "remoting/client/gl_math.h" |
| 14 #include "remoting/client/gl_render_layer.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 const int kTextureId = 2; |
| 19 const float kAnimationDurationMs = 220.f; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 namespace remoting { |
| 24 |
| 25 GlCursorFeedback::GlCursorFeedback() {} |
| 26 |
| 27 GlCursorFeedback::~GlCursorFeedback() {} |
| 28 |
| 29 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) { |
| 30 if (!canvas) { |
| 31 layer_.reset(); |
| 32 return; |
| 33 } |
| 34 layer_.reset(new GlRenderLayer(kTextureId, canvas)); |
| 35 GlCursorFeedbackTexture* texture = GlCursorFeedbackTexture::GetInstance(); |
| 36 layer_->SetTexture(texture->GetTexture().data(), |
| 37 GlCursorFeedbackTexture::kTextureWidth, |
| 38 GlCursorFeedbackTexture::kTextureWidth); |
| 39 } |
| 40 |
| 41 void GlCursorFeedback::StartAnimation(float normalized_x, |
| 42 float normalized_y, |
| 43 float normalized_width, |
| 44 float normalized_height) { |
| 45 max_width_ = normalized_width; |
| 46 max_height_ = normalized_height; |
| 47 cursor_x_ = normalized_x; |
| 48 cursor_y_ = normalized_y; |
| 49 animation_start_time_ = base::TimeTicks::Now(); |
| 50 } |
| 51 |
| 52 bool GlCursorFeedback::Draw() { |
| 53 if (!layer_ || animation_start_time_.is_null()) { |
| 54 return false; |
| 55 } |
| 56 float progress = |
| 57 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / |
| 58 kAnimationDurationMs; |
| 59 if (progress > 1) { |
| 60 animation_start_time_ = base::TimeTicks(); |
| 61 return false; |
| 62 } |
| 63 float width = progress * max_width_; |
| 64 float height = progress * max_height_; |
| 65 std::array<float, 8> positions; |
| 66 FillRectangleVertexPositions(cursor_x_ - width / 2, cursor_y_ - height / 2, |
| 67 width, height, &positions); |
| 68 layer_->SetVertexPositions(positions); |
| 69 layer_->Draw(1.f - progress); |
| 70 return true; |
| 71 } |
| 72 |
| 73 } // namespace remoting |
OLD | NEW |