示例#1
0
int ScreenRecoveryUI::SelectMenu(int sel) {
    int wrapped = 0;
    pthread_mutex_lock(&updateMutex);
    if (show_menu) {
        int old_sel = menu_sel;
        menu_sel = sel;

        // Wrap at top and bottom.
        if (rainbow) {
            if (menu_sel > old_sel) {
                move_rainbow(1);
            } else if (menu_sel < old_sel) {
                move_rainbow(-1);
            }
        }
        if (menu_sel < 0) {
            wrapped = -1;
            menu_sel = menu_items - 1;
        }
        if (menu_sel >= menu_items) {
            wrapped = 1;
            menu_sel = 0;
        }
        sel = menu_sel;
        if (wrapped != 0) {
            if (wrap_count / wrapped > 0) {
                wrap_count += wrapped;
            } else {
                wrap_count = wrapped;
            }
            if (wrap_count / wrapped >= 5) {
                wrap_count = 0;
                OMGRainbows();
            }
        }
        if (menu_sel != old_sel) update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
    return sel;
}
int ScreenRecoveryUI::SelectMenu(int sel, bool abs) {
    int old_sel;
    pthread_mutex_lock(&updateMutex);
    if (abs) {
        sel += menu_show_start;
    }
    if (show_menu > 0) {
        old_sel = menu_sel;
        menu_sel = sel;
        if (rainbow) {
            if (menu_sel > old_sel) {
                move_rainbow(1);
            } else if (menu_sel < old_sel) {
                move_rainbow(-1);
            }
        }
        if (menu_sel < 0) {
            // Wraparound from top to bottom
            menu_sel = menu_items + menu_sel;
        }
        if (menu_sel >= menu_items) {
            // Wraparound back up from the bottom
            menu_sel = menu_sel - menu_items;
        }
        if (menu_sel < menu_show_start && menu_show_start > 0) {
            // We scrolled up
            menu_show_start = menu_sel;
        }
        if (menu_sel - menu_show_start >= max_menu_rows) {
            // We scrolled down
            menu_show_start = menu_sel - max_menu_rows + 1;
        }
        sel = menu_sel;
        if (menu_sel != old_sel) {
            update_screen_locked();
        }
    }
    pthread_mutex_unlock(&updateMutex);
    return sel;
}