Update ScreenRecoveryUI::Draw* function signatures.

Move away from taking int* for the Y-offset. Change it to int and return
the offset instead.

Test: Check the recovery menu and 'Wipe data' menu.
Change-Id: Ib15e070a0d576a0f8f66f35605cb8479e7071f26
This commit is contained in:
Tao Bao 2017-06-28 14:52:17 -07:00
parent 344778c4ef
commit ea78d86b44
5 changed files with 38 additions and 37 deletions

View file

@ -177,9 +177,8 @@ void ScreenRecoveryUI::draw_background_locked() {
} }
} }
// Draws the animation and progress bar (if any) on the screen. // Draws the animation and progress bar (if any) on the screen. Does not flip pages. Should only be
// Does not flip pages. // called with updateMutex locked.
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::draw_foreground_locked() { void ScreenRecoveryUI::draw_foreground_locked() {
if (currentIcon != NONE) { if (currentIcon != NONE) {
GRSurface* frame = GetCurrentFrame(); GRSurface* frame = GetCurrentFrame();
@ -257,26 +256,26 @@ void ScreenRecoveryUI::SetColor(UIElement e) const {
} }
} }
void ScreenRecoveryUI::DrawHorizontalRule(int* y) const { int ScreenRecoveryUI::DrawHorizontalRule(int y) const {
SetColor(MENU); gr_fill(0, y + 4, gr_fb_width(), y + 6);
*y += 4; return 8;
gr_fill(0, *y, gr_fb_width(), *y + 2);
*y += 4;
} }
void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const { void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
gr_fill(x, y, x + width, y + height); gr_fill(x, y, x + width, y + height);
} }
void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const { int ScreenRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
gr_text(gr_sys_font(), x, *y, line, bold); gr_text(gr_sys_font(), x, y, line, bold);
*y += char_height_ + 4; return char_height_ + 4;
} }
void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) const { int ScreenRecoveryUI::DrawTextLines(int x, int y, const char* const* lines) const {
int offset = 0;
for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) { for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
DrawTextLine(x, y, lines[i], false); offset += DrawTextLine(x, y + offset, lines[i], false);
} }
return offset;
} }
static const char* REGULAR_HELP[] = { static const char* REGULAR_HELP[] = {
@ -310,18 +309,17 @@ void ScreenRecoveryUI::draw_screen_locked() {
android::base::GetProperty("ro.bootimage.build.fingerprint", ""); android::base::GetProperty("ro.bootimage.build.fingerprint", "");
SetColor(INFO); SetColor(INFO);
DrawTextLine(x, &y, "Android Recovery", true); y += DrawTextLine(x, y, "Android Recovery", true);
for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) { for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
DrawTextLine(x, &y, chunk.c_str(), false); y += DrawTextLine(x, y, chunk.c_str(), false);
} }
DrawTextLines(x, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
SetColor(HEADER); SetColor(HEADER);
DrawTextLines(x, &y, menu_headers_); y += DrawTextLines(x, y, menu_headers_);
SetColor(MENU); SetColor(MENU);
DrawHorizontalRule(&y); y += DrawHorizontalRule(y) + 4;
y += 4;
for (int i = 0; i < menu_items; ++i) { for (int i = 0; i < menu_items; ++i) {
if (i == menu_sel) { if (i == menu_sel) {
// Draw the highlight bar. // Draw the highlight bar.
@ -329,13 +327,13 @@ void ScreenRecoveryUI::draw_screen_locked() {
DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4); DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
// Bold white text for the selected item. // Bold white text for the selected item.
SetColor(MENU_SEL_FG); SetColor(MENU_SEL_FG);
DrawTextLine(x, &y, menu_[i], true); y += DrawTextLine(x, y, menu_[i], true);
SetColor(MENU); SetColor(MENU);
} else { } else {
DrawTextLine(x, &y, menu_[i], false); y += DrawTextLine(x, y, menu_[i], false);
} }
} }
DrawHorizontalRule(&y); y += DrawHorizontalRule(y);
} }
// Display from the bottom up, until we hit the top of the screen, the bottom of the menu, or // Display from the bottom up, until we hit the top of the screen, the bottom of the menu, or
@ -345,8 +343,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
size_t count = 0; size_t count = 0;
for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_; for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
ty -= char_height_, ++count) { ty -= char_height_, ++count) {
int temp_y = ty; DrawTextLine(x, ty, text_[row], false);
DrawTextLine(x, &temp_y, text_[row], false);
--row; --row;
if (row < 0) row = text_rows_ - 1; if (row < 0) row = text_rows_ - 1;
} }

View file

@ -179,10 +179,14 @@ class ScreenRecoveryUI : public RecoveryUI {
virtual int GetProgressBaseline() const; virtual int GetProgressBaseline() const;
virtual int GetTextBaseline() const; virtual int GetTextBaseline() const;
virtual void DrawHorizontalRule(int* y) const; // Draws a highlight bar at (x, y) - (x + width, y + height).
virtual void DrawHighlightBar(int x, int y, int width, int height) const; virtual void DrawHighlightBar(int x, int y, int width, int height) const;
virtual void DrawTextLine(int x, int* y, const char* line, bool bold) const; // Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
void DrawTextLines(int x, int* y, const char* const* lines) const; virtual int DrawHorizontalRule(int y) const;
// Draws a line of text. Returns the offset it should be moving along Y-axis.
virtual int DrawTextLine(int x, int y, const char* line, bool bold) const;
// Draws multiple text lines. Returns the offset it should be moving along Y-axis.
int DrawTextLines(int x, int y, const char* const* lines) const;
}; };
#endif // RECOVERY_UI_H #endif // RECOVERY_UI_H

View file

@ -27,9 +27,9 @@ bool VrRecoveryUI::InitTextParams() {
return true; return true;
} }
void VrRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const { int VrRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
int mid_divide = gr_fb_width() / 2; int mid_divide = gr_fb_width() / 2;
gr_text(gr_sys_font(), x + kStereoOffset, *y, line, bold); gr_text(gr_sys_font(), x + kStereoOffset, y, line, bold);
gr_text(gr_sys_font(), x - kStereoOffset + mid_divide, *y, line, bold); gr_text(gr_sys_font(), x - kStereoOffset + mid_divide, y, line, bold);
*y += char_height_ + 4; return char_height_ + 4;
} }

View file

@ -30,7 +30,7 @@ class VrRecoveryUI : public ScreenRecoveryUI {
bool InitTextParams() override; bool InitTextParams() override;
void DrawTextLine(int x, int* y, const char* line, bool bold) const override; int DrawTextLine(int x, int y, const char* line, bool bold) const override;
}; };
#endif // RECOVERY_VR_UI_H #endif // RECOVERY_VR_UI_H

View file

@ -95,7 +95,7 @@ void WearRecoveryUI::draw_background_locked() {
} }
} }
static const char* HEADERS[] = { static const char* SWIPE_HELP[] = {
"Swipe up/down to move.", "Swipe up/down to move.",
"Swipe left/right to select.", "Swipe left/right to select.",
"", "",
@ -119,15 +119,15 @@ void WearRecoveryUI::draw_screen_locked() {
std::string recovery_fingerprint = std::string recovery_fingerprint =
android::base::GetProperty("ro.bootimage.build.fingerprint", ""); android::base::GetProperty("ro.bootimage.build.fingerprint", "");
SetColor(HEADER); SetColor(HEADER);
DrawTextLine(x + 4, &y, "Android Recovery", true); y += DrawTextLine(x + 4, y, "Android Recovery", true);
for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) { for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
DrawTextLine(x + 4, &y, chunk.c_str(), false); y += DrawTextLine(x + 4, y, chunk.c_str(), false);
} }
// This is actually the help strings. // This is actually the help strings.
DrawTextLines(x + 4, &y, HEADERS); y += DrawTextLines(x + 4, y, SWIPE_HELP);
SetColor(HEADER); SetColor(HEADER);
DrawTextLines(x + 4, &y, menu_headers_); y += DrawTextLines(x + 4, y, menu_headers_);
// Show the current menu item number in relation to total number if // Show the current menu item number in relation to total number if
// items don't fit on the screen. // items don't fit on the screen.