aboutsummaryrefslogtreecommitdiffstats
path: root/screen_ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r--screen_ui.cpp80
1 files changed, 79 insertions, 1 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index f23affa..a64bad6 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -68,6 +68,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
text_top_(0),
show_text(false),
show_text_ever(false),
+ dialog_icon(NONE),
+ dialog_text(nullptr),
menu_(nullptr),
show_menu(false),
menu_items(0),
@@ -80,7 +82,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
rainbow(false),
wrap_count(0) {
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < NR_ICONS; i++) {
backgroundIcon[i] = nullptr;
}
pthread_mutex_init(&updateMutex, nullptr);
@@ -202,6 +204,9 @@ void ScreenRecoveryUI::SetColor(UIElement e) {
case TEXT_FILL:
gr_color(0, 0, 0, 160);
break;
+ case ERROR_TEXT:
+ gr_color(255, 0, 0, 255);
+ break;
default:
gr_color(255, 255, 255, 255);
break;
@@ -237,6 +242,43 @@ static const char* LONG_PRESS_HELP[] = {
NULL
};
+void ScreenRecoveryUI::draw_dialog()
+{
+ int x, y, w, h;
+
+ draw_background_locked(dialog_icon);
+
+ int iconHeight = gr_get_height(backgroundIcon[dialog_icon]);
+
+ x = (gr_fb_width()/2 - (char_width*strlen(dialog_text))/2);
+ y = (gr_fb_height()/2 + iconHeight/2);
+
+ SetColor(ERROR_TEXT);
+ gr_text(x, y, dialog_text, 0);
+
+ if (dialog_icon == ERROR) {
+ /*
+ * This could be improved...
+ *
+ * Draw rect around text "Okay".
+ * Text is centered horizontally.
+ * Bottom of text is 4 lines from bottom of screen.
+ * Rect width 4px
+ * Rect padding 8px
+ */
+ w = char_width*4;
+ h = char_height;
+ x = gr_fb_width()/2 - w/2;
+ y = gr_fb_height() - h - 4*char_height;
+ SetColor(HEADER);
+ gr_fill(x-(4+8), y-(4+8), x+w+(4+8), y+h+(4+8));
+ SetColor(MENU_SEL_BG);
+ gr_fill(x-8, y-8, x+w+8, y+h+8);
+ SetColor(MENU_SEL_FG);
+ gr_text(x, y, "Okay", 0);
+ }
+}
+
// Redraw everything on the screen. Does not flip pages.
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::draw_screen_locked() {
@@ -244,6 +286,12 @@ void ScreenRecoveryUI::draw_screen_locked() {
draw_background_locked(currentIcon);
draw_progress_locked();
} else {
+
+ if (DialogShowing()) {
+ draw_dialog();
+ return;
+ }
+
gr_color(0, 0, 0, 255);
gr_clear();
@@ -416,6 +464,7 @@ void ScreenRecoveryUI::Init() {
LoadBitmapArray("icon_installing", &installing_frames, &installation);
backgroundIcon[INSTALLING_UPDATE] = installing_frames ? installation[0] : nullptr;
backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE];
+ LoadBitmap("icon_info", &backgroundIcon[INFO]);
LoadBitmap("icon_error", &backgroundIcon[ERROR]);
backgroundIcon[NO_COMMAND] = backgroundIcon[ERROR];
@@ -653,6 +702,35 @@ void ScreenRecoveryUI::ShowFile(const char* filename) {
text_top_ = old_text_top;
}
+void ScreenRecoveryUI::DialogShowInfo(const char* text)
+{
+ pthread_mutex_lock(&updateMutex);
+ free(dialog_text);
+ dialog_text = strdup(text);
+ dialog_icon = INFO;
+ update_screen_locked();
+ pthread_mutex_unlock(&updateMutex);
+}
+
+void ScreenRecoveryUI::DialogShowError(const char* text)
+{
+ pthread_mutex_lock(&updateMutex);
+ free(dialog_text);
+ dialog_text = strdup(text);
+ dialog_icon = ERROR;
+ update_screen_locked();
+ pthread_mutex_unlock(&updateMutex);
+}
+
+void ScreenRecoveryUI::DialogDismiss()
+{
+ pthread_mutex_lock(&updateMutex);
+ free(dialog_text);
+ dialog_text = NULL;
+ update_screen_locked();
+ pthread_mutex_unlock(&updateMutex);
+}
+
void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
int initial_selection) {
pthread_mutex_lock(&updateMutex);