static void tab_misc_init(multirom_theme_data *t, tab_data_misc *d, int color_scheme) { int x = HEADER_WIDTH + ((fb_width - HEADER_WIDTH)/2 - MISCBTN_W/2); int y = 10; button *b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->clicked = &multirom_ui_tab_misc_copy_log; button_init_ui(b, "Copy log to /sdcard", SIZE_BIG); list_add(b, &d->buttons); y += MISCBTN_H+50; static const char *texts[] = { "Reboot", // 0 "Reboot to recovery", // 1 "Reboot to bootloader", // 2 "Shutdown", // 3 NULL }; static const int exit_codes[] = { UI_EXIT_REBOOT, UI_EXIT_REBOOT_RECOVERY, UI_EXIT_REBOOT_BOOTLOADER, UI_EXIT_SHUTDOWN }; int i; for(i = 0; texts[i]; ++i) { b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->action = exit_codes[i]; b->clicked = &multirom_ui_reboot_btn; button_init_ui(b, texts[i], SIZE_BIG); list_add(b, &d->buttons); y += MISCBTN_H+20; if(i == 2) y += 30; } fb_text *text = fb_add_text(HEADER_WIDTH+5, fb_height-16, WHITE, SIZE_SMALL, "MultiROM v%d"VERSION_DEV_FIX" with trampoline v%d.", VERSION_MULTIROM, multirom_get_trampoline_ver()); list_add(text, &d->ui_elements); char bat_text[16]; sprintf(bat_text, "Battery: %d%%", multirom_get_battery()); text = fb_add_text_long(fb_width-strlen(bat_text)*8, fb_height-16, WHITE, SIZE_SMALL, bat_text); list_add(text, &d->ui_elements); x = HEADER_WIDTH + ((fb_width - HEADER_WIDTH)/2 - (CLRS_MAX*CLRBTN_TOTAL)/2); uint32_t p, s; fb_rect *r; for(i = 0; i < CLRS_MAX; ++i) { multirom_ui_setup_colors(i, &p, &s); if(i == color_scheme) { r = fb_add_rect(x, CLRBTN_Y, CLRBTN_TOTAL, CLRBTN_TOTAL, WHITE); list_add(r, &d->ui_elements); } r = fb_add_rect(x+CLRBTN_B/2, CLRBTN_Y+CLRBTN_B/2, CLRBTN_W, CLRBTN_W, p); list_add(r, &d->ui_elements); b = mzalloc(sizeof(button)); b->x = x; b->y = CLRBTN_Y; b->w = CLRBTN_TOTAL; b->h = CLRBTN_TOTAL; b->action = i; b->clicked = &multirom_ui_tab_misc_change_clr; button_init_ui(b, NULL, 0); list_add(b, &d->buttons); x += CLRBTN_TOTAL; } }
int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot) { if(multirom_init_fb(s->rotation) < 0) return UI_EXIT_BOOT_ROM; fb_freeze(1); mrom_status = s; exit_ui_code = -1; selected_rom = NULL; active_msgbox = NULL; multirom_ui_setup_colors(s->colors, &CLR_PRIMARY, &CLR_SECONDARY); themes_info = multirom_ui_init_themes(); if((cur_theme = multirom_ui_select_theme(themes_info, fb_width, fb_height)) == NULL) { fb_freeze(0); ERROR("Couldn't find theme for resolution %dx%d!\n", fb_width, fb_height); fb_add_text(0, 0, WHITE, SIZE_SMALL, "Couldn't find theme for resolution %dx%d!\nPress POWER to reboot.", fb_width, fb_height); fb_draw(); fb_clear(); fb_close(); start_input_thread(); while(wait_for_key() != KEY_POWER); stop_input_thread(); return UI_EXIT_REBOOT; } workers_start(); multirom_ui_init_header(); multirom_ui_switch(TAB_INTERNAL); add_touch_handler(&multirom_ui_touch_handler, NULL); start_input_thread(); keyaction_enable(1); keyaction_set_destroy_msgbox_handle(multirom_ui_destroy_msgbox); multirom_set_brightness(s->brightness); fb_freeze(0); if(s->auto_boot_rom && s->auto_boot_seconds > 0) multirom_ui_auto_boot(); else fb_draw(); while(1) { pthread_mutex_lock(&exit_code_mutex); if(exit_ui_code != -1) { pthread_mutex_unlock(&exit_code_mutex); break; } if(loop_act & LOOP_UPDATE_USB) { multirom_find_usb_roms(mrom_status); if(themes_info->data->selected_tab == TAB_USB) multirom_ui_tab_rom_update_usb(themes_info->data->tab_data); loop_act &= ~(LOOP_UPDATE_USB); } if(loop_act & LOOP_START_PONG) { loop_act &= ~(LOOP_START_PONG); keyaction_enable(0); input_push_context(); fb_push_context(); pong(); fb_pop_context(); input_pop_context(); keyaction_enable(1); } if(loop_act & LOOP_CHANGE_CLR) { fb_freeze(1); multirom_ui_setup_colors(s->colors, &CLR_PRIMARY, &CLR_SECONDARY); // force redraw tab int tab = themes_info->data->selected_tab; themes_info->data->selected_tab = -1; multirom_ui_destroy_tab(tab); multirom_ui_switch(tab); fb_freeze(0); fb_draw(); loop_act &= ~(LOOP_CHANGE_CLR); } pthread_mutex_unlock(&exit_code_mutex); usleep(100000); } keyaction_enable(0); keyaction_clear(); rm_touch_handler(&multirom_ui_touch_handler, NULL); fb_create_msgbox(500*DPI_MUL, 250*DPI_MUL, CLR_PRIMARY); switch(exit_ui_code) { case UI_EXIT_BOOT_ROM: *to_boot = selected_rom; fb_msgbox_add_text(-1, 40*DPI_MUL, SIZE_BIG, "Booting ROM..."); fb_msgbox_add_text(-1, -1, SIZE_NORMAL, selected_rom->name); break; case UI_EXIT_REBOOT: case UI_EXIT_REBOOT_RECOVERY: case UI_EXIT_REBOOT_BOOTLOADER: fb_msgbox_add_text(-1, -1, SIZE_BIG, "Rebooting..."); break; case UI_EXIT_SHUTDOWN: fb_msgbox_add_text(-1, -1, SIZE_BIG, "Shutting down..."); break; } fb_draw(); fb_freeze(1); cur_theme->destroy(themes_info->data); int i; for(i = 0; i < TAB_COUNT; ++i) { button_destroy(themes_info->data->tab_btns[i]); themes_info->data->tab_btns[i] = NULL; } stop_input_thread(); multirom_ui_destroy_tab(themes_info->data->selected_tab); multirom_ui_free_themes(themes_info); themes_info = NULL; workers_stop(); fb_clear(); #if MR_DEVICE_HOOKS >= 2 mrom_hook_before_fb_close(); #endif fb_close(); return exit_ui_code; }