Merge "screen_ui: Use std::string in DrawTextLine() and siblings."
This commit is contained in:
committed by
Gerrit Code Review
commit
b4ded4a6ce
+44
-33
@@ -372,19 +372,22 @@ void ScreenRecoveryUI::SelectAndShowBackgroundText(const std::vector<std::string
|
|||||||
// Write the header and descriptive texts.
|
// Write the header and descriptive texts.
|
||||||
SetColor(INFO);
|
SetColor(INFO);
|
||||||
std::string header = "Show background text image";
|
std::string header = "Show background text image";
|
||||||
text_y += DrawTextLine(text_x, text_y, header.c_str(), true);
|
text_y += DrawTextLine(text_x, text_y, header, true);
|
||||||
std::string locale_selection = android::base::StringPrintf(
|
std::string locale_selection = android::base::StringPrintf(
|
||||||
"Current locale: %s, %zu/%zu", locales_entries[sel].c_str(), sel, locales_entries.size());
|
"Current locale: %s, %zu/%zu", locales_entries[sel].c_str(), sel, locales_entries.size());
|
||||||
const char* instruction[] = { locale_selection.c_str(),
|
// clang-format off
|
||||||
"Use volume up/down to switch locales and power to exit.",
|
std::vector<std::string> instruction = {
|
||||||
nullptr };
|
locale_selection,
|
||||||
|
"Use volume up/down to switch locales and power to exit."
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
text_y += DrawWrappedTextLines(text_x, text_y, instruction);
|
text_y += DrawWrappedTextLines(text_x, text_y, instruction);
|
||||||
|
|
||||||
// Iterate through the text images and display them in order for the current locale.
|
// Iterate through the text images and display them in order for the current locale.
|
||||||
for (const auto& p : surfaces) {
|
for (const auto& p : surfaces) {
|
||||||
text_y += line_spacing;
|
text_y += line_spacing;
|
||||||
SetColor(LOG);
|
SetColor(LOG);
|
||||||
text_y += DrawTextLine(text_x, text_y, p.first.c_str(), false);
|
text_y += DrawTextLine(text_x, text_y, p.first, false);
|
||||||
gr_color(255, 255, 255, 255);
|
gr_color(255, 255, 255, 255);
|
||||||
gr_texticon(text_x, text_y, p.second.get());
|
gr_texticon(text_x, text_y, p.second.get());
|
||||||
text_y += gr_get_height(p.second.get());
|
text_y += gr_get_height(p.second.get());
|
||||||
@@ -451,24 +454,23 @@ void ScreenRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
|
|||||||
gr_texticon(x, y, surface);
|
gr_texticon(x, y, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
|
int ScreenRecoveryUI::DrawTextLine(int x, int y, const std::string& line, bool bold) const {
|
||||||
gr_text(gr_sys_font(), x, y, line, bold);
|
gr_text(gr_sys_font(), x, y, line.c_str(), bold);
|
||||||
return char_height_ + 4;
|
return char_height_ + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenRecoveryUI::DrawTextLines(int x, int y, const char* const* lines) const {
|
int ScreenRecoveryUI::DrawTextLines(int x, int y, const std::vector<std::string>& lines) const {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
|
for (const auto& line : lines) {
|
||||||
offset += DrawTextLine(x, y + offset, lines[i], false);
|
offset += DrawTextLine(x, y + offset, line, false);
|
||||||
}
|
}
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, const char* const* lines) const {
|
int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y,
|
||||||
|
const std::vector<std::string>& lines) const {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
|
for (const auto& line : lines) {
|
||||||
// The line will be wrapped if it exceeds text_cols_.
|
|
||||||
std::string line(lines[i]);
|
|
||||||
size_t next_start = 0;
|
size_t next_start = 0;
|
||||||
while (next_start < line.size()) {
|
while (next_start < line.size()) {
|
||||||
std::string sub = line.substr(next_start, text_cols_ + 1);
|
std::string sub = line.substr(next_start, text_cols_ + 1);
|
||||||
@@ -478,7 +480,7 @@ int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, const char* const* line
|
|||||||
// Line too long and must be wrapped to text_cols_ columns.
|
// Line too long and must be wrapped to text_cols_ columns.
|
||||||
size_t last_space = sub.find_last_of(" \t\n");
|
size_t last_space = sub.find_last_of(" \t\n");
|
||||||
if (last_space == std::string::npos) {
|
if (last_space == std::string::npos) {
|
||||||
// No space found, just draw as much as we can
|
// No space found, just draw as much as we can.
|
||||||
sub.resize(text_cols_);
|
sub.resize(text_cols_);
|
||||||
next_start += text_cols_;
|
next_start += text_cols_;
|
||||||
} else {
|
} else {
|
||||||
@@ -486,23 +488,12 @@ int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, const char* const* line
|
|||||||
next_start += last_space + 1;
|
next_start += last_space + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
offset += DrawTextLine(x, y + offset, sub.c_str(), false);
|
offset += DrawTextLine(x, y + offset, sub, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* REGULAR_HELP[] = {
|
|
||||||
"Use volume up/down and power.",
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char* LONG_PRESS_HELP[] = {
|
|
||||||
"Any button cycles highlight.",
|
|
||||||
"Long-press activates.",
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
|
// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
|
||||||
// locked.
|
// locked.
|
||||||
void ScreenRecoveryUI::draw_screen_locked() {
|
void ScreenRecoveryUI::draw_screen_locked() {
|
||||||
@@ -515,11 +506,21 @@ void ScreenRecoveryUI::draw_screen_locked() {
|
|||||||
gr_color(0, 0, 0, 255);
|
gr_color(0, 0, 0, 255);
|
||||||
gr_clear();
|
gr_clear();
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
static std::vector<std::string> REGULAR_HELP = {
|
||||||
|
"Use volume up/down and power.",
|
||||||
|
};
|
||||||
|
static std::vector<std::string> LONG_PRESS_HELP = {
|
||||||
|
"Any button cycles highlight.",
|
||||||
|
"Long-press activates.",
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
draw_menu_and_text_buffer_locked(HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
|
draw_menu_and_text_buffer_locked(HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draws the menu and text buffer on the screen. Should only be called with updateMutex locked.
|
// Draws the menu and text buffer on the screen. Should only be called with updateMutex locked.
|
||||||
void ScreenRecoveryUI::draw_menu_and_text_buffer_locked(const char* const* help_message) {
|
void ScreenRecoveryUI::draw_menu_and_text_buffer_locked(
|
||||||
|
const std::vector<std::string>& help_message) {
|
||||||
int y = kMarginHeight;
|
int y = kMarginHeight;
|
||||||
if (menu_) {
|
if (menu_) {
|
||||||
static constexpr int kMenuIndent = 4;
|
static constexpr int kMenuIndent = 4;
|
||||||
@@ -530,22 +531,32 @@ void ScreenRecoveryUI::draw_menu_and_text_buffer_locked(const char* const* help_
|
|||||||
std::string recovery_fingerprint =
|
std::string recovery_fingerprint =
|
||||||
android::base::GetProperty("ro.bootimage.build.fingerprint", "");
|
android::base::GetProperty("ro.bootimage.build.fingerprint", "");
|
||||||
for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
|
for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
|
||||||
y += DrawTextLine(x, y, chunk.c_str(), false);
|
y += DrawTextLine(x, y, chunk, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
y += DrawTextLines(x, y, help_message);
|
y += DrawTextLines(x, y, help_message);
|
||||||
|
|
||||||
|
auto convert_to_vector = [](const char* const* items) -> std::vector<std::string> {
|
||||||
|
if (items == nullptr) return {};
|
||||||
|
|
||||||
|
std::vector<std::string> result;
|
||||||
|
for (size_t i = 0; items[i] != nullptr; ++i) {
|
||||||
|
result.emplace_back(items[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
// Draw menu header.
|
// Draw menu header.
|
||||||
SetColor(HEADER);
|
SetColor(HEADER);
|
||||||
if (!menu_->scrollable()) {
|
if (!menu_->scrollable()) {
|
||||||
y += DrawWrappedTextLines(x, y, menu_->text_headers());
|
y += DrawWrappedTextLines(x, y, convert_to_vector(menu_->text_headers()));
|
||||||
} else {
|
} else {
|
||||||
y += DrawTextLines(x, y, menu_->text_headers());
|
y += DrawTextLines(x, y, convert_to_vector(menu_->text_headers()));
|
||||||
// Show the current menu item number in relation to total number if items don't fit on the
|
// Show the current menu item number in relation to total number if items don't fit on the
|
||||||
// screen.
|
// screen.
|
||||||
std::string cur_selection_str;
|
std::string cur_selection_str;
|
||||||
if (menu_->ItemsOverflow(&cur_selection_str)) {
|
if (menu_->ItemsOverflow(&cur_selection_str)) {
|
||||||
y += DrawTextLine(x, y, cur_selection_str.c_str(), true);
|
y += DrawTextLine(x, y, cur_selection_str, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,7 +580,7 @@ void ScreenRecoveryUI::draw_menu_and_text_buffer_locked(const char* const* help_
|
|||||||
bold = true;
|
bold = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
y += DrawTextLine(x, y, menu_->TextItem(i).c_str(), bold);
|
y += DrawTextLine(x, y, menu_->TextItem(i), bold);
|
||||||
|
|
||||||
SetColor(MENU);
|
SetColor(MENU);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -178,7 +178,7 @@ class ScreenRecoveryUI : public RecoveryUI {
|
|||||||
virtual void draw_background_locked();
|
virtual void draw_background_locked();
|
||||||
virtual void draw_foreground_locked();
|
virtual void draw_foreground_locked();
|
||||||
virtual void draw_screen_locked();
|
virtual void draw_screen_locked();
|
||||||
virtual void draw_menu_and_text_buffer_locked(const char* const* help_message);
|
virtual void draw_menu_and_text_buffer_locked(const std::vector<std::string>& help_message);
|
||||||
virtual void update_screen_locked();
|
virtual void update_screen_locked();
|
||||||
virtual void update_progress_locked();
|
virtual void update_progress_locked();
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ class ScreenRecoveryUI : public RecoveryUI {
|
|||||||
// Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
|
// Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
|
||||||
virtual int DrawHorizontalRule(int y) const;
|
virtual int DrawHorizontalRule(int y) const;
|
||||||
// Draws a line of text. Returns the offset it should be moving along Y-axis.
|
// 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;
|
virtual int DrawTextLine(int x, int y, const std::string& line, bool bold) const;
|
||||||
// Draws surface portion (sx, sy, w, h) at screen location (dx, dy).
|
// Draws surface portion (sx, sy, w, h) at screen location (dx, dy).
|
||||||
virtual void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const;
|
virtual void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const;
|
||||||
// Draws rectangle at (x, y) - (x + w, y + h).
|
// Draws rectangle at (x, y) - (x + w, y + h).
|
||||||
@@ -220,10 +220,10 @@ class ScreenRecoveryUI : public RecoveryUI {
|
|||||||
// Draws given surface (surface->pixel_bytes = 1) as text at (x, y).
|
// Draws given surface (surface->pixel_bytes = 1) as text at (x, y).
|
||||||
virtual void DrawTextIcon(int x, int y, GRSurface* surface) const;
|
virtual void DrawTextIcon(int x, int y, GRSurface* surface) const;
|
||||||
// Draws multiple text lines. Returns the offset it should be moving along Y-axis.
|
// 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;
|
int DrawTextLines(int x, int y, const std::vector<std::string>& lines) const;
|
||||||
// Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines.
|
// Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines.
|
||||||
// Returns the offset it should be moving along Y-axis.
|
// Returns the offset it should be moving along Y-axis.
|
||||||
int DrawWrappedTextLines(int x, int y, const char* const* lines) const;
|
int DrawWrappedTextLines(int x, int y, const std::vector<std::string>& lines) const;
|
||||||
|
|
||||||
Icon currentIcon;
|
Icon currentIcon;
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ void VrRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
|
|||||||
gr_texticon(x - kStereoOffset + ScreenWidth(), y, surface);
|
gr_texticon(x - kStereoOffset + ScreenWidth(), y, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
int VrRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
|
int VrRecoveryUI::DrawTextLine(int x, int y, const std::string& line, bool bold) const {
|
||||||
gr_text(gr_sys_font(), x + kStereoOffset, y, line, bold);
|
gr_text(gr_sys_font(), x + kStereoOffset, y, line.c_str(), bold);
|
||||||
gr_text(gr_sys_font(), x - kStereoOffset + ScreenWidth(), y, line, bold);
|
gr_text(gr_sys_font(), x - kStereoOffset + ScreenWidth(), y, line.c_str(), bold);
|
||||||
return char_height_ + 4;
|
return char_height_ + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#ifndef RECOVERY_VR_UI_H
|
#ifndef RECOVERY_VR_UI_H
|
||||||
#define RECOVERY_VR_UI_H
|
#define RECOVERY_VR_UI_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "screen_ui.h"
|
#include "screen_ui.h"
|
||||||
|
|
||||||
class VrRecoveryUI : public ScreenRecoveryUI {
|
class VrRecoveryUI : public ScreenRecoveryUI {
|
||||||
@@ -36,7 +38,7 @@ class VrRecoveryUI : public ScreenRecoveryUI {
|
|||||||
void DrawHighlightBar(int x, int y, int width, int height) const override;
|
void DrawHighlightBar(int x, int y, int width, int height) const override;
|
||||||
void DrawFill(int x, int y, int w, int h) const override;
|
void DrawFill(int x, int y, int w, int h) const override;
|
||||||
void DrawTextIcon(int x, int y, GRSurface* surface) const override;
|
void DrawTextIcon(int x, int y, GRSurface* surface) const override;
|
||||||
int DrawTextLine(int x, int y, const char* line, bool bold) const override;
|
int DrawTextLine(int x, int y, const std::string& line, bool bold) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECOVERY_VR_UI_H
|
#endif // RECOVERY_VR_UI_H
|
||||||
|
|||||||
+7
-7
@@ -61,13 +61,6 @@ void WearRecoveryUI::draw_background_locked() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* SWIPE_HELP[] = {
|
|
||||||
"Swipe up/down to move.",
|
|
||||||
"Swipe left/right to select.",
|
|
||||||
"",
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
void WearRecoveryUI::draw_screen_locked() {
|
void WearRecoveryUI::draw_screen_locked() {
|
||||||
draw_background_locked();
|
draw_background_locked();
|
||||||
if (!show_text) {
|
if (!show_text) {
|
||||||
@@ -76,6 +69,13 @@ void WearRecoveryUI::draw_screen_locked() {
|
|||||||
SetColor(TEXT_FILL);
|
SetColor(TEXT_FILL);
|
||||||
gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
static std::vector<std::string> SWIPE_HELP = {
|
||||||
|
"Swipe up/down to move.",
|
||||||
|
"Swipe left/right to select.",
|
||||||
|
"",
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
draw_menu_and_text_buffer_locked(SWIPE_HELP);
|
draw_menu_and_text_buffer_locked(SWIPE_HELP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user