From 6c20b00105e405823aa3ec12479e52cc30c0df9c Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Mon, 15 Feb 2016 15:36:06 -0800 Subject: recovery: Implement sysbar Add a system bar (navigation bar) similar to the main Android system with back and home buttons. This makes it easier for users to figure out how to go back on devices that lack hardware buttons, and also provides a quick way to get back to the main menu. Note only buttons that do not have a hardware equivalent are shown, in order to prevent redundancy and confusion. Change-Id: I7538749978837571a8c250c3c8e54ac127b39d84 --- screen_ui.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 11 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index 8e6c733..849f6d1 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -77,6 +77,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() : show_menu(false), menu_items(0), menu_sel(0), + sysbar_state(0), file_viewer_text_(nullptr), animation_fps(20), installing_frames(-1), @@ -86,6 +87,10 @@ ScreenRecoveryUI::ScreenRecoveryUI() : wrap_count(0) { headerIcon = nullptr; + sysbarBackIcon = nullptr; + sysbarBackHighlightIcon = nullptr; + sysbarHomeIcon = nullptr; + sysbarHomeHighlightIcon = nullptr; for (int i = 0; i < NR_ICONS; i++) { backgroundIcon[i] = nullptr; } @@ -281,6 +286,45 @@ void ScreenRecoveryUI::draw_menu_item(int textrow, const char *text, int selecte } } +void ScreenRecoveryUI::draw_sysbar() +{ + GRSurface* surface; + int sw = gr_fb_width(); + int sh = gr_fb_height(); + int iw; + int ih; + SetColor(TEXT_FILL); + gr_fill(0, sh - sysbar_height_, sw, sh); + + // Left third is back button + if (!HasBackKey()) { + if (sysbar_state & SYSBAR_BACK) { + surface = sysbarBackHighlightIcon; + } + else { + surface = sysbarBackIcon; + } + iw = gr_get_width(surface); + ih = gr_get_height(surface); + gr_blit(surface, 0, 0, iw, ih, + 1 * (sw / 6) - (iw / 2), sh - ih); + } + + // Middle third is home button + if (!HasHomeKey()) { + if (sysbar_state & SYSBAR_HOME) { + surface = sysbarHomeHighlightIcon; + } + else { + surface = sysbarHomeIcon; + } + iw = gr_get_width(surface); + ih = gr_get_height(surface); + gr_blit(surface, 0, 0, iw, ih, + 3 * (sw / 6) - (iw / 2), sh - ih); + } +} + void ScreenRecoveryUI::draw_dialog() { int x, y, w, h; @@ -289,6 +333,7 @@ void ScreenRecoveryUI::draw_dialog() return; } draw_header_icon(); + draw_sysbar(); int iconHeight = gr_get_height(backgroundIcon[dialog_icon]); @@ -374,9 +419,9 @@ void ScreenRecoveryUI::draw_screen_locked() { } if (show_menu) { - int i; + int i, y; draw_header_icon(); - int y; + draw_sysbar(); // Divider y = text_first_row_ * char_height_; @@ -519,23 +564,31 @@ void ScreenRecoveryUI::Init() { gr_font_size(&log_char_width_, &log_char_height_); gr_set_font("menu"); gr_font_size(&char_width_, &char_height_); - text_rows_ = gr_fb_height() / char_height_; - text_cols_ = gr_fb_width() / char_width_; - - log_text_rows_ = gr_fb_height() / log_char_height_; - log_text_cols_ = gr_fb_width() / log_char_width_; - - text_ = Alloc2d(log_text_rows_, log_text_cols_ + 1); - file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1); - menu_ = Alloc2d(text_rows_, text_cols_ + 1); text_col_ = text_row_ = 0; text_top_ = 1; LoadBitmap("icon_header", &headerIcon); + LoadBitmap("icon_sysbar_back", &sysbarBackIcon); + LoadBitmap("icon_sysbar_back_highlight", &sysbarBackHighlightIcon); + LoadBitmap("icon_sysbar_home", &sysbarHomeIcon); + LoadBitmap("icon_sysbar_home_highlight", &sysbarHomeHighlightIcon); + header_height_ = gr_get_height(headerIcon); header_width_ = gr_get_width(headerIcon); + sysbar_height_ = gr_get_height(sysbarBackIcon); + + text_rows_ = (gr_fb_height() - sysbar_height_) / char_height_; + text_cols_ = gr_fb_width() / char_width_; + + log_text_rows_ = (gr_fb_height() - sysbar_height_) / log_char_height_; + log_text_cols_ = gr_fb_width() / log_char_width_; + + text_ = Alloc2d(log_text_rows_, log_text_cols_ + 1); + file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1); + menu_ = Alloc2d(text_rows_, text_cols_ + 1); + text_first_row_ = (header_height_ / char_height_) + 1; menu_item_start_ = text_first_row_ * char_height_; max_menu_rows_ = (text_rows_ - text_first_row_) / 3; -- cgit v1.1