X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=menu.c;h=f1b19579c7589aa8646f8d385d01ac598354fc59;hb=448ec62f85a90e8a27368ddc05057a5a714944b8;hp=503107f20933182c61a52aa4d666c796f4da8b4b;hpb=20b143089cc395dbcd51cac516a9e36f4ab6f5ac;p=libpicofe.git diff --git a/menu.c b/menu.c index 503107f..f1b1957 100644 --- a/menu.c +++ b/menu.c @@ -31,10 +31,10 @@ void *g_menuscreen_ptr; void *g_menubg_src_ptr; void *g_menubg_ptr; -#if !MSCREEN_SIZE_FIXED int g_menuscreen_w; int g_menuscreen_h; -#endif + +int g_autostateld_opt; static unsigned char *menu_font_data = NULL; static int menu_text_color = 0xfffe; // default to white @@ -239,7 +239,7 @@ static char tolower_simple(char c) void menu_init_base(void) { - int i, c, l; + int i, c, l, pos; unsigned char *fd, *fds; char buff[256]; FILE *f; @@ -252,7 +252,7 @@ void menu_init_base(void) return; // generate default 8x10 font from fontdata8x8 - for (c = 0, fd = menu_font_data; c < 256; c++) + for (c = 0, fd = menu_font_data; c < 128; c++) { for (l = 0; l < 8; l++) { @@ -294,17 +294,18 @@ void menu_init_base(void) } // load custom font and selector (stored as 1st symbol in font table) - emu_make_path(buff, "skin/font.png", sizeof(buff)); + pos = plat_get_skin_dir(buff, sizeof(buff)); + strcpy(buff + pos, "font.png"); readpng(menu_font_data, buff, READPNG_FONT, MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160); // default selector symbol is '>' memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2, me_mfont_w * me_mfont_h / 2); - emu_make_path(buff, "skin/selector.png", sizeof(buff)); + strcpy(buff + pos, "selector.png"); readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h); // load custom colors - emu_make_path(buff, "skin/skin.txt", sizeof(buff)); + strcpy(buff + pos, "skin.txt"); f = fopen(buff, "r"); if (f != NULL) { @@ -898,10 +899,16 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, snprintf(buff, sizeof(buff), "%s - select, %s - back", in_get_key_name(-1, -PBTN_MOK), in_get_key_name(-1, -PBTN_MBACK)); - smalltext_out16(x, g_menuscreen_h - me_sfont_h * 2 - 2, buff, 0xe78c); + smalltext_out16(x, g_menuscreen_h - me_sfont_h * 3 - 2, buff, 0xe78c); + snprintf(buff, sizeof(buff), g_menu_filter_off ? "%s - hide unknown files" : "%s - show all files", in_get_key_name(-1, -PBTN_MA3)); + smalltext_out16(x, g_menuscreen_h - me_sfont_h * 2 - 2, buff, 0xe78c); + + snprintf(buff, sizeof(buff), g_autostateld_opt ? + "%s - autoload save is ON" : "%s - autoload save is OFF", + in_get_key_name(-1, -PBTN_MA2)); smalltext_out16(x, g_menuscreen_h - me_sfont_h * 1 - 2, buff, 0xe78c); } @@ -933,8 +940,14 @@ static int scandir_filter(const struct dirent *ent) if (ent == NULL || ent->d_name == NULL) return 0; - if (ent->d_type == DT_DIR) + switch (ent->d_type) { + case DT_DIR: return 1; + case DT_LNK: + case DT_UNKNOWN: + // could be a dir, deal with it later.. + return 1; + } ext = strrchr(ent->d_name, '.'); if (ext == NULL) @@ -953,9 +966,11 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c) int i; sel++; - for (i = sel + 1; i != sel; i++) { + for (i = sel + 1; ; i++) { if (i >= len) i = 1; + if (i == sel) + break; if (tolower_simple(namelist[i]->d_name[0]) == c) break; @@ -969,14 +984,16 @@ static const char *menu_loop_romsel(char *curr_path, int len, int (*extra_filter)(struct dirent **namelist, int count, const char *basedir)) { - static char rom_fname_reload[256]; // used for return + static char rom_fname_reload[256]; // used for scratch and return char sel_fname[256]; int (*filter)(const struct dirent *); struct dirent **namelist = NULL; int n = 0, inp = 0, sel = 0, show_help = 0; char *curr_path_restore = NULL; const char *ret = NULL; + int changed; char cinp; + int r, i; filter_exts_internal = filter_exts; sel_fname[0] = 0; @@ -1023,14 +1040,40 @@ rescan: } } + // try to resolve DT_UNKNOWN and symlinks + changed = 0; + for (i = 0; i < n; i++) { + struct stat st; + + if (namelist[i]->d_type == DT_REG || namelist[i]->d_type == DT_DIR) + continue; + + snprintf(rom_fname_reload, sizeof(rom_fname_reload), + "%s/%s", curr_path, namelist[i]->d_name); + r = stat(rom_fname_reload, &st); + if (r == 0) + { + if (S_ISREG(st.st_mode)) { + namelist[i]->d_type = DT_REG; + changed = 1; + } + else if (S_ISDIR(st.st_mode)) { + namelist[i]->d_type = DT_DIR; + changed = 1; + } + } + } + if (!g_menu_filter_off && extra_filter != NULL) n = extra_filter(namelist, n, curr_path); + if (n > 1 && changed) + qsort(namelist, n, sizeof(namelist[0]), scandir_cmp); + // try to find selected file // note: we don't show '.' so sel is namelist index - 1 sel = 0; if (sel_fname[0] != 0) { - int i; for (i = 1; i < n; i++) { char *dname = namelist[i]->d_name; if (dname[0] == sel_fname[0] && strcmp(dname, sel_fname) == 0) { @@ -1051,22 +1094,21 @@ rescan: inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT | PBTN_L|PBTN_R|PBTN_MA2|PBTN_MA3|PBTN_MOK|PBTN_MBACK | PBTN_MENU|PBTN_CHAR, &cinp, 33); - if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; } - if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; } - if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } - if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } - if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } - if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; } - if (inp & PBTN_CHAR) sel = dirent_seek_char(namelist, n, sel, cinp); if (inp & PBTN_MA3) { g_menu_filter_off = !g_menu_filter_off; snprintf(sel_fname, sizeof(sel_fname), "%s", namelist[sel+1]->d_name); goto rescan; } + if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; } + if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; } + if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } + if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } + if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } + if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; } + if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2)) { - again: if (namelist[sel+1]->d_type == DT_REG) { snprintf(rom_fname_reload, sizeof(rom_fname_reload), @@ -1106,23 +1148,16 @@ rescan: free(newdir); break; } - else - { - // unknown file type, happens on NTFS mounts. Try to guess. - FILE *tstf; int tmp; - snprintf(rom_fname_reload, sizeof(rom_fname_reload), - "%s/%s", curr_path, namelist[sel+1]->d_name); - tstf = fopen(rom_fname_reload, "rb"); - if (tstf != NULL) - { - if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0) - namelist[sel+1]->d_type = DT_REG; - else namelist[sel+1]->d_type = DT_DIR; - fclose(tstf); - goto again; - } - } } + else if (inp & PBTN_MA2) { + g_autostateld_opt = !g_autostateld_opt; + show_help = 3; + } + else if (inp & PBTN_CHAR) { + // must be last + sel = dirent_seek_char(namelist, n, sel, cinp); + } + if (inp & PBTN_MBACK) break; @@ -1346,7 +1381,8 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ y = (g_menuscreen_h - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2; if (x < me_mfont_w * 2) x = me_mfont_w * 2; - + if (y < 0) + y = 0; menu_draw_begin(1, 0); if (player_idx >= 0) text_out16(x, y, "Player %i controls", player_idx + 1); @@ -1472,6 +1508,10 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ in_unbind_all(bind_dev_id, opts[sel].mask << mask_shift, bindtype); in_bind_key(bind_dev_id, kc, opts[sel].mask << mask_shift, bindtype, 0); + + // make sure bind change is displayed + if (dev_id != -1) + dev_id = bind_dev_id; } }