static int zarch_zui_render_lay_root(zui_t *zui) { char item[PATH_MAX_LENGTH]; static struct zui_tabbed tabbed = {~0U}; zarch_zui_tabbed_begin(zui, &tabbed, 0, 0); tabbed.width = zui->width - 290 - 40; zui->next_selection_set = false; if (zarch_zui_render_lay_root_recent(zui, &tabbed)) return 0; if (zarch_zui_render_lay_root_load (zui, &tabbed)) return 0; if (zarch_zui_render_lay_root_collections(zui, &tabbed)) return 0; if (zarch_zui_render_lay_root_downloads(zui, &tabbed)) return 0; #ifdef ZARCH_DEBUG item[0] = '\0'; snprintf(item, sizeof(item), "item id: %d\n", zui->active_id); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 1600 +12, 300 + 41, item); snprintf(item, sizeof(item), "tab idx: %d\n", tabbed.active_id); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 1600 +12, 300 + 81, item); snprintf(item, sizeof(item), "item hot idx: %d\n", zui->item.hot); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 1600 +12, 300 + 111, item); #endif menu_display_push_quad(zui->width, zui->height, zui_bg_hilite, 0, 60, zui->width - 290 - 40, 60+4); return 0; }
static bool zarch_zui_list_item(zui_t *zui, zui_tabbed_t *tab, int x1, int y1, const char *label, unsigned item_id, const char *entry) { char title_buf[PATH_MAX_LENGTH]; unsigned ticker_size; bool set_active_id = false; unsigned id = zarch_zui_hash(zui, label); int x2 = x1 + zui->width - 290 - 40; int y2 = y1 + 50; bool active = zarch_zui_check_button_up(zui, id, x1, y1, x2, y2); const float *bg = ZUI_BG_PANEL; uint64_t *frame_count = video_driver_get_frame_count(); if (tab->active_id != tab->prev_id) { set_active_id = true; tab->prev_id = tab->active_id; } if (zui->pending_selection == -1) { if (item_id < zui->active_id) zui->prev_id = item_id; if (item_id > zui->active_id && !zui->next_selection_set) { zui->next_id = item_id; zui->next_selection_set = true; } } else { if (zui->active_id != item_id && zui->pending_selection == item_id) set_active_id = true; } if (set_active_id) zui->active_id = item_id; if (zui->item.active == id || zui->item.hot == id) bg = ZUI_BG_HILITE; else if (zui->active_id == item_id) bg = ZUI_BG_PAD_HILITE; ticker_size = x2 / 14; menu_animation_ticker_str(title_buf, ticker_size, *frame_count / 50, label, (bg == ZUI_BG_HILITE || bg == ZUI_BG_PAD_HILITE)); zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 12, y1 + 35, title_buf); if (entry) zarch_zui_draw_text(zui, ZUI_FG_NORMAL, x2 - 200, y1 + 35, entry); return active; }
static int zarch_zui_render_lay_root(zui_t *zui) { char item[PATH_MAX_LENGTH]; static zui_tabbed_t tabbed = {~0}; zarch_zui_tabbed_begin(zui, &tabbed, 0, 0); tabbed.width = zui->width - 290 - 40; zui->next_selection_set = false; if (zarch_zui_render_lay_root_recent(zui, &tabbed)) return 0; if (zarch_zui_render_lay_root_load (zui, &tabbed)) return 0; if (zarch_zui_render_lay_root_collections(zui, &tabbed)) return 0; if (zarch_zui_render_lay_root_downloads(zui, &tabbed)) return 0; (void)item; #ifdef ZARCH_DEBUG snprintf(item, sizeof(item), "item id: %d\n", zui->active_id); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 1600 +12, 300 + 41, item); snprintf(item, sizeof(item), "tab idx: %d\n", tabbed.active_id); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 1600 +12, 300 + 81, item); snprintf(item, sizeof(item), "item hot idx: %d\n", zui->item.hot); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 1600 +12, 300 + 111, item); #endif if (zui->pending_selection == -1) { switch (zui->action) { case MENU_ACTION_UP: if (zui->prev_id != -1 && zui->prev_id != zui->active_id) { if (zui->prev_id < zui->active_id) zui->pending_selection = zui->prev_id; } break; case MENU_ACTION_DOWN: if (zui->next_id != -1 && zui->next_id != zui->active_id) { if (zui->next_id > zui->active_id) zui->pending_selection = zui->next_id; } break; default: break; } } else zui->pending_selection = -1; zarch_zui_push_quad(zui->width, zui->height, ZUI_BG_HILITE, &zui->ca, 0, 60, zui->width - 290 - 40, 60+4); return 0; }
static bool zarch_zui_list_item(zui_t *zui, struct zui_tabbed *tab, int x1, int y1, const char *label, unsigned item_id, const char *entry, bool selected) { menu_animation_ctx_ticker_t ticker; char title_buf[PATH_MAX_LENGTH]; unsigned ticker_size; uint64_t *frame_count = NULL; unsigned id = zarch_zui_hash(zui, label); int x2 = x1 + zui->width - 290 - 40; int y2 = y1 + 50; bool active = zarch_zui_check_button_up(zui, id, x1, y1, x2, y2); const float *bg = zui_bg_panel; video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count); if (tab->active_id != tab->prev_id) { tab->prev_id = tab->active_id; } if (selected) { zui->next_id = item_id; zui->next_selection_set = true; } /* Set background color */ if (zui->item.active == id || zui->item.hot == id) bg = zui_bg_hilite; else if (selected) bg = zui_bg_pad_hilite; ticker_size = x2 / 14; ticker.s = title_buf; ticker.len = ticker_size; ticker.idx = *frame_count / 50; ticker.str = label; ticker.selected = (bg == zui_bg_hilite || bg == zui_bg_pad_hilite); menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker); zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 12, y1 + 35, title_buf); if (entry) zarch_zui_draw_text(zui, ZUI_FG_NORMAL, x2 - 200, y1 + 35, entry); return active; }
static int zarch_zui_render_pick_core(zui_t *zui) { static struct zui_tabbed tabbed = {~0U}; unsigned i, j = 0; if (zui->pick_supported == 1) { int ret = zarch_zui_load_content(zui, 0); (void)ret; zarch_layout = LAY_HOME; menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUIT, NULL); return 1; } zarch_zui_draw_text(zui, ~0, 8, 18, "Select a core: "); if (zarch_zui_button(zui, 0, 18 + zui->font_size, "<- Back")) zarch_layout = LAY_HOME; if (!zui->pick_supported) { zarch_zui_list_item(zui, &tabbed, 0, ZUI_ITEM_SIZE_PX, "Content unsupported", 0, NULL, false /* TODO/FIXME */); return 1; } zui->pick_first += zui->mouse.wheel; zui->pick_first = MIN(MAX(zui->pick_first, 0), zui->pick_supported - 5); for (i = zui->pick_first; i < zui->pick_supported; ++i) { if (j > 10) break; if (zarch_zui_list_item(zui, &tabbed, 0, ZUI_ITEM_SIZE_PX + j * ZUI_ITEM_SIZE_PX, zui->pick_cores[i].display_name, i, NULL, false)) { int ret = zarch_zui_load_content(zui, i); (void)ret; zarch_layout = LAY_HOME; menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUIT, NULL); break; } j++; } return 0; }
static bool zarch_zui_tab(zui_t *zui, struct zui_tabbed *tab, const char *label, unsigned tab_id) { bool active; int x1, y1, x2, y2; unsigned id = zarch_zui_hash(zui, label); int width = tab->tab_width; const float *bg = zui_bg_panel; bool selected = tab->tab_selection == tab_id; /* TODO/FIXME */ if (!zui || !tab ) return false; if (!width) { if (!zui->fb_buf) return false; width = zarch_zui_strwidth(zui->fb_buf, label, 1.0) + 24; } x1 = tab->x; y1 = tab->y; x2 = x1 + width; y2 = y1 + 60; active = zarch_zui_check_button_up(zui, id, x1, y1, x2, y2); tab->prev_id = tab->active_id; if (zui->item.active == id || tab->active_id == ~0U || !tab->inited) tab->active_id = id; else if (id > tab->active_id) { tab->next_id = id; } if (!tab->inited) tab->inited = true; if (tab->active_id == id || zui->item.active == id || zui->item.hot == id) bg = zui_bg_hilite; else if (selected) bg = zui_bg_pad_hilite; zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1+0, y1+0, x2, y2); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, x1+12, y1 + 41, label); if (tab->vertical) tab->y += y2 - y1; else tab->x = x2; return active || (tab->active_id == id); }
static int zarch_zui_render_pick_core(zui_t *zui) { static zui_tabbed_t tabbed = {~0}; unsigned i, j = 0; if (zui->pick_supported == 1) { int ret = zarch_zui_load_content(zui, 0); (void)ret; layout = LAY_HOME; zui->time_to_exit = true; return 1; } zarch_zui_draw_text(zui, ~0, 8, 18, "Select a core: "); if (zarch_zui_button(zui, 0, 18 + zui->font_size, "<- Back")) layout = LAY_HOME; if (!zui->pick_supported) { zarch_zui_list_item(zui, &tabbed, 0, 54, "Content unsupported", 0, NULL /* TODO/FIXME */); zui->active_id = 0; return 1; } zui->pick_first += zui->mouse.wheel; zui->pick_first = min(max(zui->pick_first, 0), zui->pick_supported - 5); for (i = zui->pick_first; i < zui->pick_supported; ++i) { if (j > 10) break; if (zarch_zui_list_item(zui, &tabbed, 0, 54 + j * 54, zui->pick_cores[i].display_name, i, NULL)) { int ret = zarch_zui_load_content(zui, i); (void)ret; layout = LAY_HOME; zui->time_to_exit = true; break; } j++; } return 0; }
static bool zarch_zui_button_full(zui_t *zui, int x1, int y1, int x2, int y2, const char *label) { unsigned id = zarch_zui_hash(zui, label); bool active = zarch_zui_check_button_up(zui, id, x1, y1, x2, y2); const float *bg = ZUI_BG_PANEL; if (zui->item.active == id || zui->item.hot == id) bg = ZUI_BG_HILITE; zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, x1+12, y1 + 41, label); return active; }
static bool zarch_zui_button_full(zui_t *zui, int x1, int y1, int x2, int y2, const char *label) { unsigned id = zarch_zui_hash(zui, label); bool active = zarch_zui_check_button_up(zui, id, x1, y1, x2, y2); const float *bg = zui_bg_panel; if (zui->item.active == id || zui->item.hot == id) bg = zui_bg_hilite; menu_display_push_quad(zui->width, zui->height, bg, x1, y1, x2, y2); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, x1+12, y1 + 41, label); return active; }
static int zarch_zui_render_lay_root_load(zui_t *zui, struct zui_tabbed *tabbed) { char parent_dir[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); core_info_list_t *list = NULL; parent_dir[0] = '\0'; if (zarch_zui_tab(zui, tabbed, "Load", 1)) { unsigned cwd_offset; if (!zui->load_cwd) zui->load_cwd = strdup(settings->directory.menu_content); if (!zui->load_dlist) { core_info_t *core_info = NULL; core_info_get_current_core(&core_info); zui->load_dlist = dir_list_new(zui->load_cwd, core_info->supported_extensions, true, true, false, true); dir_list_sort(zui->load_dlist, true); zui->load_dlist_first = 0; } cwd_offset = MIN(strlen(zui->load_cwd), 60); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 15, tabbed->tabline_size + 5 + 41, &zui->load_cwd[strlen(zui->load_cwd) - cwd_offset]); if (zarch_zui_button(zui, zui->width - 290 - 129, tabbed->tabline_size + 5, "Home")) zarch_zui_render_lay_root_load_free(zui); if (zui->load_dlist) { fill_pathname_parent_dir(parent_dir, zui->load_cwd, sizeof(parent_dir)); if (!string_is_empty(parent_dir) && zarch_zui_list_item(zui, tabbed, 0, tabbed->tabline_size + 73, " ..", 0, NULL, false /* TODO/FIXME */)) { zarch_zui_render_lay_root_load_set_new_path(zui, parent_dir); } else { static int gamepad_index = 0; unsigned size = zui->load_dlist->size; unsigned i, j = 1; unsigned skip = 0; for (i = 0; i < size; ++i) { const char *basename = path_basename(zui->load_dlist->elems[i].data); if (basename[0] != '.') break; skip++; } if (zarch_zui_gamepad_input(zui, &gamepad_index, &zui->load_dlist_first, skip)) zui->load_dlist_first = gamepad_index; for (i = skip + zui->load_dlist_first; i < size; ++i) { char label[PATH_MAX_LENGTH]; const char *path = NULL; const char *basename = NULL; if (j > 10) break; label[0] = '\0'; path = zui->load_dlist->elems[i].data; basename = path_basename(path); *label = 0; strncat(label, " ", sizeof(label)-1); strncat(label, basename, sizeof(label)-1); if (path_is_directory(path)) strncat(label, "/", sizeof(label)-1); if (zarch_zui_list_item(zui, tabbed, 0, tabbed->tabline_size + 73 + j * ZUI_ITEM_SIZE_PX, label, i, NULL, gamepad_index == (signed)(i-skip))) { if (path_is_directory(path)) { zarch_zui_render_lay_root_load_set_new_path(zui, path); break; } zui->pick_cores = NULL; zui->pick_supported = 0; strlcpy(zui->pick_content, path, sizeof(zui->pick_content)); core_info_get_list(&list); core_info_list_get_supported_cores(list, path, &zui->pick_cores, &zui->pick_supported); zarch_layout = LAY_PICK_CORE; break; } j++; } } } } else if (zui->load_dlist) { dir_list_free(zui->load_dlist); zui->load_dlist = NULL; } return 0; }
static int zarch_zui_render_lay_root_load(zui_t *zui, zui_tabbed_t *tabbed) { char parent_dir[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); if (zarch_zui_tab(zui, tabbed, "Load", 1)) { unsigned cwd_offset; if (!zui->load_cwd) zui->load_cwd = strdup(settings->menu_content_directory); if (!zui->load_dlist) { zui->load_dlist = dir_list_new(zui->load_cwd, global->core_info.current->supported_extensions, true, true); dir_list_sort(zui->load_dlist, true); zui->load_dlist_first = 0; } cwd_offset = min(strlen(zui->load_cwd), 60); zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 15, tabbed->tabline_size + 5 + 41, &zui->load_cwd[strlen(zui->load_cwd) - cwd_offset]); if (zarch_zui_button(zui, zui->width - 290 - 129, tabbed->tabline_size + 5, "Home")) zarch_zui_render_lay_root_load_free(zui); if (zui->load_dlist) { fill_pathname_parent_dir(parent_dir, zui->load_cwd, sizeof(parent_dir)); if (parent_dir[0] != '\0' && zarch_zui_list_item(zui, tabbed, 0, tabbed->tabline_size + 73, " ..", 0, NULL /* TODO/FIXME */)) { zarch_zui_render_lay_root_load_set_new_path(zui, parent_dir); } else { unsigned size = zui->load_dlist->size; unsigned i, j = 1; unsigned skip = 0; for (i = 0; i < size; ++i) { const char *basename = path_basename(zui->load_dlist->elems[i].data); if (basename[0] != '.') break; skip++; } zui->load_dlist_first += zui->mouse.wheel; if (zui->load_dlist_first < 0) zui->load_dlist_first = 0; else if (zui->load_dlist_first > size - 5) zui->load_dlist_first = size - 5; zui->load_dlist_first = min(max(zui->load_dlist_first, 0), size - 5 - skip); for (i = skip + zui->load_dlist_first; i < size; ++i) { char label[PATH_MAX_LENGTH]; const char *path = NULL; const char *basename = NULL; if (j > 10) break; path = zui->load_dlist->elems[i].data; basename = path_basename(path); *label = 0; strncat(label, " ", sizeof(label)-1); strncat(label, basename, sizeof(label)-1); if (path_is_directory(path)) strncat(label, "/", sizeof(label)-1); if (zarch_zui_list_item(zui, tabbed, 0, tabbed->tabline_size + 73 + j * 54, label, i, NULL)) { if (path_is_directory(path)) { zarch_zui_render_lay_root_load_set_new_path(zui, path); break; } zui->pick_cores = NULL; zui->pick_supported = 0; strncpy(zui->pick_content, path, sizeof(zui->pick_content)-1); core_info_list_get_supported_cores(global->core_info.list, path, &zui->pick_cores, &zui->pick_supported); layout = LAY_PICK_CORE; break; } j++; } } } } else if (zui->load_dlist) { dir_list_free(zui->load_dlist); zui->load_dlist = NULL; } return 0; }