| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/textures/loading_indicator_texture.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "cc/paint/skia_paint_canvas.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" |
| 11 |
| 12 namespace vr_shell { |
| 13 |
| 14 namespace { |
| 15 |
| 16 static constexpr SkColor kBackground = 0xCCAAAAAA; |
| 17 static constexpr SkColor kForeground = 0xCC444444; |
| 18 static constexpr float kWidth = 0.268; |
| 19 static constexpr float kHeight = 0.008; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 LoadingIndicatorTexture::LoadingIndicatorTexture() = default; |
| 24 |
| 25 LoadingIndicatorTexture::~LoadingIndicatorTexture() = default; |
| 26 |
| 27 gfx::Size LoadingIndicatorTexture::GetPreferredTextureSize( |
| 28 int maximum_width) const { |
| 29 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 30 } |
| 31 |
| 32 gfx::SizeF LoadingIndicatorTexture::GetDrawnSize() const { |
| 33 return size_; |
| 34 } |
| 35 |
| 36 void LoadingIndicatorTexture::SetLoading(bool loading) { |
| 37 if (loading_ != loading) { |
| 38 loading_ = loading; |
| 39 set_dirty(); |
| 40 } |
| 41 } |
| 42 |
| 43 void LoadingIndicatorTexture::SetLoadProgress(float progress) { |
| 44 DCHECK_GE(progress, 0.0f); |
| 45 DCHECK_LE(progress, 1.0f); |
| 46 if (progress_ != progress) { |
| 47 progress_ = progress; |
| 48 set_dirty(); |
| 49 } |
| 50 } |
| 51 |
| 52 void LoadingIndicatorTexture::Draw(SkCanvas* canvas, |
| 53 const gfx::Size& texture_size) { |
| 54 size_.set_height(texture_size.height()); |
| 55 size_.set_width(texture_size.width()); |
| 56 |
| 57 canvas->save(); |
| 58 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); |
| 59 |
| 60 SkPaint paint; |
| 61 paint.setColor(kBackground); |
| 62 canvas->drawRoundRect({0, 0, kWidth, kHeight}, kHeight / 2, kHeight / 2, |
| 63 paint); |
| 64 |
| 65 if (loading_) { |
| 66 paint.setColor(kForeground); |
| 67 float progress_width = kHeight + (kWidth - kHeight) * progress_; |
| 68 canvas->drawRoundRect({0, 0, progress_width, kHeight}, kHeight / 2, |
| 69 kHeight / 2, paint); |
| 70 } |
| 71 |
| 72 canvas->restore(); |
| 73 } |
| 74 |
| 75 } // namespace vr_shell |
| OLD | NEW |