Luke Song | e2bd876 | 2017-06-12 16:08:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tianjie Xu | b5108c3 | 2018-08-20 13:40:47 -0700 | [diff] [blame] | 17 | #include "recovery_ui/vr_ui.h" |
Luke Song | e2bd876 | 2017-06-12 16:08:33 -0700 | [diff] [blame] | 18 | |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 19 | #include <android-base/properties.h> |
Luke Song | e2bd876 | 2017-06-12 16:08:33 -0700 | [diff] [blame] | 20 | |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 21 | #include "minui/minui.h" |
| 22 | |
| 23 | constexpr int kDefaultStereoOffset = 0; |
| 24 | |
| 25 | VrRecoveryUI::VrRecoveryUI() |
| 26 | : stereo_offset_( |
| 27 | android::base::GetIntProperty("ro.recovery.ui.stereo_offset", kDefaultStereoOffset)) {} |
Luke Song | e2bd876 | 2017-06-12 16:08:33 -0700 | [diff] [blame] | 28 | |
Luke Song | 92eda4d | 2017-09-19 10:51:35 -0700 | [diff] [blame] | 29 | int VrRecoveryUI::ScreenWidth() const { |
| 30 | return gr_fb_width() / 2; |
| 31 | } |
| 32 | |
| 33 | int VrRecoveryUI::ScreenHeight() const { |
| 34 | return gr_fb_height(); |
| 35 | } |
| 36 | |
Tao Bao | 65815b6 | 2018-10-23 10:54:02 -0700 | [diff] [blame] | 37 | void VrRecoveryUI::DrawSurface(const GRSurface* surface, int sx, int sy, int w, int h, int dx, |
Luke Song | 92eda4d | 2017-09-19 10:51:35 -0700 | [diff] [blame] | 38 | int dy) const { |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 39 | gr_blit(surface, sx, sy, w, h, dx + stereo_offset_, dy); |
| 40 | gr_blit(surface, sx, sy, w, h, dx - stereo_offset_ + ScreenWidth(), dy); |
Luke Song | 92eda4d | 2017-09-19 10:51:35 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Tao Bao | 65815b6 | 2018-10-23 10:54:02 -0700 | [diff] [blame] | 43 | void VrRecoveryUI::DrawTextIcon(int x, int y, const GRSurface* surface) const { |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 44 | gr_texticon(x + stereo_offset_, y, surface); |
| 45 | gr_texticon(x - stereo_offset_ + ScreenWidth(), y, surface); |
Luke Song | e2bd876 | 2017-06-12 16:08:33 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Tao Bao | 93e46ad | 2018-05-02 14:57:21 -0700 | [diff] [blame] | 48 | int VrRecoveryUI::DrawTextLine(int x, int y, const std::string& line, bool bold) const { |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 49 | gr_text(gr_sys_font(), x + stereo_offset_, y, line.c_str(), bold); |
| 50 | gr_text(gr_sys_font(), x - stereo_offset_ + ScreenWidth(), y, line.c_str(), bold); |
Tao Bao | ea78d86 | 2017-06-28 14:52:17 -0700 | [diff] [blame] | 51 | return char_height_ + 4; |
Luke Song | e2bd876 | 2017-06-12 16:08:33 -0700 | [diff] [blame] | 52 | } |
Luke Song | 92eda4d | 2017-09-19 10:51:35 -0700 | [diff] [blame] | 53 | |
| 54 | int VrRecoveryUI::DrawHorizontalRule(int y) const { |
| 55 | y += 4; |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 56 | gr_fill(margin_width_ + stereo_offset_, y, ScreenWidth() - margin_width_ + stereo_offset_, y + 2); |
| 57 | gr_fill(ScreenWidth() + margin_width_ - stereo_offset_, y, |
| 58 | gr_fb_width() - margin_width_ - stereo_offset_, y + 2); |
Luke Song | 92eda4d | 2017-09-19 10:51:35 -0700 | [diff] [blame] | 59 | return y + 4; |
| 60 | } |
| 61 | |
Tao Bao | 99f0d9e | 2016-10-13 12:46:38 -0700 | [diff] [blame] | 62 | void VrRecoveryUI::DrawHighlightBar(int /* x */, int y, int /* width */, int height) const { |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 63 | gr_fill(margin_width_ + stereo_offset_, y, ScreenWidth() - margin_width_ + stereo_offset_, |
| 64 | y + height); |
| 65 | gr_fill(ScreenWidth() + margin_width_ - stereo_offset_, y, |
| 66 | gr_fb_width() - margin_width_ - stereo_offset_, y + height); |
Luke Song | 92eda4d | 2017-09-19 10:51:35 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void VrRecoveryUI::DrawFill(int x, int y, int w, int h) const { |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 70 | gr_fill(x + stereo_offset_, y, w, h); |
| 71 | gr_fill(x - stereo_offset_ + ScreenWidth(), y, w, h); |
Luke Song | 92eda4d | 2017-09-19 10:51:35 -0700 | [diff] [blame] | 72 | } |