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

Side by Side Diff: chrome/browser/android/vr_shell/textures/system_indicator_texture.cc

Issue 2884453002: VR: audio and video capture indicators. (Closed)
Patch Set: rebase 2 Created 3 years, 7 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
OLDNEW
(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/system_indicator_texture.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "cc/paint/skia_paint_canvas.h"
9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/font_list.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/vector2d.h"
14 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/gfx/render_text.h"
16 #include "ui/gfx/vector_icon_types.h"
17
18 namespace vr_shell {
19
20 namespace {
21
22 const SkColor kBackgroundColor = SK_ColorWHITE;
23 const SkColor kForegroundColor = 0xFF444444;
24 constexpr float kBorderFactor = 0.1;
25 constexpr float kIconSizeFactor = 0.7;
26 constexpr float kFontSizeFactor = 0.40;
27 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor;
28 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor;
29
30 } // namespace
31
32 SystemIndicatorTexture::SystemIndicatorTexture(const gfx::VectorIcon& icon,
33 int message_id)
34 : icon_(icon), message_id_(message_id) {}
35
36 SystemIndicatorTexture::~SystemIndicatorTexture() = default;
37
38 void SystemIndicatorTexture::Draw(SkCanvas* sk_canvas,
39 const gfx::Size& texture_size) {
40 cc::SkiaPaintCanvas paint_canvas(sk_canvas);
41 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
42 gfx::Canvas* canvas = &gfx_canvas;
43
44 DCHECK(texture_size.height() * 4 == texture_size.width());
45 size_.set_height(texture_size.height());
46 SkPaint paint;
47 paint.setColor(kBackgroundColor);
48
49 base::string16 text;
50
51 // TODO(acondor): Set proper strings in resources files.
52 if (message_id_)
53 text = l10n_util::GetStringUTF16(message_id_);
54 else
55 text = base::UTF8ToUTF16("<message>");
56
57 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text);
58 gfx::Rect text_size(0, kTextHeightFactor * size_.height());
59
60 std::vector<std::unique_ptr<gfx::RenderText>> lines =
61 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 0);
62
63 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height());
64 // Setting background size giving some extra lateral padding to the text.
65 size_.set_width((5 * kBorderFactor + kIconSizeFactor) * size_.height() +
66 text_size.width());
67 float radius = size_.height() * kBorderFactor;
68 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()),
69 radius, radius, paint);
70
71 canvas->Save();
72 canvas->Translate(gfx::Vector2d(
73 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width()
74 : size_.height() * kBorderFactor,
75 size_.height() * (1.0 - kIconSizeFactor) / 2.0));
76 PaintVectorIcon(canvas, icon_, size_.height() * kIconSizeFactor,
77 kForegroundColor);
78 canvas->Restore();
79
80 canvas->Save();
81 canvas->Translate(gfx::Vector2d(
82 size_.height() *
83 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor),
84 size_.height() * kBorderFactor));
85 for (auto& render_text : lines)
86 render_text->Draw(canvas);
87 canvas->Restore();
88 }
89
90 gfx::Size SystemIndicatorTexture::GetPreferredTextureSize(
91 int maximum_width) const {
92 // Ensuring height is a quarter of the width.
93 int height = maximum_width / 4;
94 return gfx::Size(height * 4, height);
95 }
96
97 gfx::SizeF SystemIndicatorTexture::GetDrawnSize() const {
98 return size_;
99 }
100
101 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698