X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Fmenu.c;h=be1ed3a07372b9fcb655398a9093928d2db7bf07;hb=82abf46f3db8ade517881c03327bdbc0de848eb2;hp=2f29e87be8ffdca2459d1f56de24ba391f3ee778;hpb=3ffee69c504e786d66bff58e109534025701d86e;p=libpicofe.git diff --git a/common/menu.c b/common/menu.c index 2f29e87..be1ed3a 100644 --- a/common/menu.c +++ b/common/menu.c @@ -12,7 +12,6 @@ #include "fonts.h" #include "readpng.h" #include "lprintf.h" -#include "common.h" #include "input.h" #include "emu.h" #include "plat.h" @@ -33,10 +32,14 @@ static int menu_error_time = 0; static unsigned char *menu_font_data = NULL; static int menu_text_color = 0xffff; // default to white static int menu_sel_color = -1; // disabled + +/* note: these might become non-constant in future */ #if MENU_X2 static const int me_mfont_w = 16, me_mfont_h = 20; +static const int me_sfont_w = 12, me_sfont_h = 20; #else static const int me_mfont_w = 8, me_mfont_h = 10; +static const int me_sfont_w = 6, me_sfont_h = 10; #endif // draws text to current bbp16 screen @@ -113,35 +116,41 @@ void text_out16(int x, int y, const char *texto, ...) text_out16_(x,y,buffer,menu_text_color); } - +/* draws in 6x8 font, might multiply size by integer */ static void smalltext_out16_(int x, int y, const char *texto, int color) { - int i; unsigned char *src; unsigned short *dst; + int multiplier = me_sfont_w / 6; + int i; - for (i = 0;; i++, x += 6) + for (i = 0;; i++, x += me_sfont_w) { unsigned char c = (unsigned char) texto[i]; int h = 8; - if (!c) break; + if (!c || c == '\n') + break; src = fontdata6x8[c]; dst = (unsigned short *)g_screen_ptr + x + y * g_screen_width; while (h--) { - int w = 0x20; - while (w) + int m, w2, h2; + for (h2 = multiplier; h2 > 0; h2--) { - if( *src & w ) *dst = color; - dst++; - w>>=1; + for (m = 0x20; m; m >>= 1) { + if (*src & m) + for (w2 = multiplier; w2 > 0; w2--) + *dst++ = color; + else + dst += multiplier; + } + + dst += g_screen_width - me_sfont_w; } src++; - - dst += g_screen_width - 6; } } } @@ -176,7 +185,7 @@ static void menu_draw_selection(int x, int y, int w) for (h = me_mfont_h + 1; h > 0; h--) { dst = dest; - for (i = w; i > 0; i--) + for (i = w - 14; i > 0; i--) *dst++ = menu_sel_color; dest += g_screen_width; } @@ -472,7 +481,7 @@ static void me_loop(menu_entry *menu, int *menu_sel) return; } - while (!menu[sel].enabled && sel < menu_sel_max) + while ((!menu[sel].enabled || !menu[sel].selectable) && sel < menu_sel_max) sel++; /* make sure action buttons are not pressed on entering menu */ @@ -585,15 +594,15 @@ static void cdload_progress_cb(int percent) int ln, len = percent * g_screen_width / 100; unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2; - memset(dst, 0xff, g_screen_width * (10 - 2) * 2); + memset(dst, 0xff, g_screen_width * (me_sfont_h - 2) * 2); - smalltext_out16(1, 3 * 10, "Processing CD image / MP3s", 0xffff); - smalltext_out16(1, 4 * 10, rom_fname_loaded, 0xffff); - dst += g_screen_width * 30; + smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff); + smalltext_out16(1, 4 * me_sfont_h, rom_fname_loaded, 0xffff); + dst += g_screen_width * me_sfont_h * 3; if (len > g_screen_width) len = g_screen_width; - for (ln = (10 - 2); ln > 0; ln--, dst += g_screen_width) + for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_screen_width) memset(dst, 0xff, len * 2); plat_video_menu_end(); @@ -604,18 +613,18 @@ void menu_romload_prepare(const char *rom_name) { const char *p = rom_name + strlen(rom_name); - plat_video_menu_begin(); - while (p > rom_name && *p != '/') p--; /* fill both buffers, callbacks won't update in full */ + plat_video_menu_begin(); smalltext_out16(1, 1, "Loading", 0xffff); - smalltext_out16(1, 10, p, 0xffff); + smalltext_out16(1, me_sfont_h, p, 0xffff); plat_video_menu_end(); + plat_video_menu_begin(); smalltext_out16(1, 1, "Loading", 0xffff); - smalltext_out16(1, 10, p, 0xffff); + smalltext_out16(1, me_sfont_h, p, 0xffff); plat_video_menu_end(); PicoCartLoadProgressCB = load_progress_cb; @@ -626,11 +635,49 @@ void menu_romload_prepare(const char *rom_name) void menu_romload_end(void) { PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL; - smalltext_out16(1, (cdload_called ? 6 : 3) * 10, + smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h, "Starting emulation...", 0xffff); plat_video_menu_end(); } +// -------------- del confirm --------------- + +static void do_delete(const char *fpath, const char *fname) +{ + int len, mid, inp; + const char *nm; + char tmp[64]; + + plat_video_menu_begin(); + + if (!rom_loaded) + menu_darken_bg(g_screen_ptr, g_screen_width * g_screen_height, 0); + + len = strlen(fname); + if (len > g_screen_width/6) + len = g_screen_width/6; + + mid = g_screen_width / 2; + text_out16(mid - me_mfont_w * 15 / 2, 8 * me_mfont_h, "About to delete"); + smalltext_out16(mid - len * me_sfont_w / 2, 9 * me_mfont_h + 5, fname, 0xbdff); + text_out16(mid - me_mfont_w * 13 / 2, 11 * me_mfont_h, "Are you sure?"); + + nm = in_get_key_name(-1, -PBTN_MA3); + snprintf(tmp, sizeof(tmp), "(%s - confirm, ", nm); + len = strlen(tmp); + nm = in_get_key_name(-1, -PBTN_MBACK); + snprintf(tmp + len, sizeof(tmp) - len, "%s - cancel)", nm); + len = strlen(tmp); + + text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, tmp); + plat_video_menu_end(); + + while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MA2)); + inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, 100); + if (inp & PBTN_MA3) + remove(fpath); +} + // -------------- ROM selector -------------- // rrrr rggg gggb bbbb @@ -651,9 +698,9 @@ static unsigned short file2color(const char *fname) static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) { - int max_cnt, start, i, pos; + int max_cnt, start, i, x, pos; - max_cnt = g_screen_height / 10; + max_cnt = g_screen_height / me_sfont_h; start = max_cnt / 2 - sel; n--; // exclude current dir (".") @@ -664,21 +711,22 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) menu_darken_bg((short *)g_screen_ptr + g_screen_width * max_cnt/2 * 10, g_screen_width * 8, 0); + x = 5 + me_mfont_w + 1; if (start - 2 >= 0) - smalltext_out16(14, (start - 2)*10, curdir, 0xffff); + smalltext_out16(14, (start - 2) * me_sfont_h, curdir, 0xffff); for (i = 0; i < n; i++) { pos = start + i; if (pos < 0) continue; if (pos >= max_cnt) break; if (namelist[i+1]->d_type == DT_DIR) { - smalltext_out16(14, pos*10, "/", 0xfff6); - smalltext_out16(14+6, pos*10, namelist[i+1]->d_name, 0xfff6); + smalltext_out16(x, pos * me_sfont_h, "/", 0xfff6); + smalltext_out16(x + me_sfont_w, pos * me_sfont_h, namelist[i+1]->d_name, 0xfff6); } else { unsigned short color = file2color(namelist[i+1]->d_name); - smalltext_out16(14, pos*10, namelist[i+1]->d_name, color); + smalltext_out16(x, pos * me_sfont_h, namelist[i+1]->d_name, color); } } - smalltext_out16(5, max_cnt/2 * 10, ">", 0xffff); + smalltext_out16(5, max_cnt/2 * me_sfont_h, ">", 0xffff); plat_video_menu_end(); } @@ -777,7 +825,7 @@ rescan: ret = rom_fname_reload; break; } -// do_delete(rom_fname_reload, namelist[sel+1]->d_name); // TODO + do_delete(rom_fname_reload, namelist[sel+1]->d_name); if (n > 0) { while (n--) free(namelist[n]); free(namelist); @@ -855,14 +903,14 @@ static void draw_patchlist(int sel) if (pos < 0) continue; if (pos >= max_cnt) break; active = PicoPatches[i].active; - smalltext_out16(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff); - smalltext_out16(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff); + smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff); + smalltext_out16(14+6*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff); } pos = start + i; if (pos < max_cnt) - smalltext_out16(14, pos * 10, "done", 0xffff); + smalltext_out16(14, pos * me_sfont_h, "done", 0xffff); - text_out16(5, max_cnt / 2 * 10, ">"); + text_out16(5, max_cnt / 2 * me_sfont_h, ">"); plat_video_menu_end(); } @@ -965,7 +1013,7 @@ static void draw_savestate_menu(int menu_sel, int is_loading) if (state_slot_flags & (1 << menu_sel)) draw_savestate_bg(menu_sel); - w = 13 * me_mfont_w + me_mfont_w * 2; + w = (13 + 2) * me_mfont_w; h = (1+2+10+1) * me_mfont_h; x = g_screen_width / 2 - w / 2; if (x < 0) x = 0; @@ -977,7 +1025,7 @@ static void draw_savestate_menu(int menu_sel, int is_loading) text_out16(x, y, is_loading ? "Load state" : "Save state"); y += 3 * me_mfont_h; - menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, 13 * me_mfont_w + 4); + menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (13 + 2) * me_mfont_w + 4); /* draw all 10 slots */ for (i = 0; i < 10; i++, y += me_mfont_h) @@ -1044,10 +1092,11 @@ static char *action_binds(int player_idx, int action_mask, int dev_id) if (binds == NULL) return static_buff; - count = in_get_dev_bind_count(dev_id); + count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT); for (k = 0; k < count; k++) { const char *xname; + int len; if (!(binds[k] & action_mask)) continue; @@ -1055,9 +1104,12 @@ static char *action_binds(int player_idx, int action_mask, int dev_id) continue; xname = in_get_key_name(dev_id, k); - if (static_buff[0]) - strncat(static_buff, " + ", sizeof(static_buff)); - strncat(static_buff, xname, sizeof(static_buff)); + len = strlen(static_buff); + if (len) { + strncat(static_buff, " + ", sizeof(static_buff) - len - 1); + len += 3; + } + strncat(static_buff, xname, sizeof(static_buff) - len - 1); } return static_buff; @@ -1073,7 +1125,7 @@ static int count_bound_keys(int dev_id, int action_mask, int player_idx) if (binds == NULL) return 0; - count = in_get_dev_bind_count(dev_id); + count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT); for (k = 0; k < count; k++) { if (!(binds[k] & action_mask)) @@ -1091,10 +1143,11 @@ static int count_bound_keys(int dev_id, int action_mask, int player_idx) static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel, int dev_id, int dev_count, int is_bind) { - int x, y, w, i; const char *dev_name; + int x, y, w, i; - x = g_screen_width / 2 - 20 * me_mfont_w / 2; + w = ((player_idx >= 0) ? 20 : 30) * me_mfont_w; + x = g_screen_width / 2 - w / 2; y = (g_screen_height - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2; if (x < me_mfont_w * 2) x = me_mfont_w * 2; @@ -1106,7 +1159,7 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ text_out16(x, y, "Emulator controls"); y += 2 * me_mfont_h; - menu_draw_selection(x - me_mfont_w * 2, y + sel * me_mfont_h, me_mfont_w); // FIXME last arg + menu_draw_selection(x - me_mfont_w * 2, y + sel * me_mfont_h, w + 2 * me_mfont_w); for (i = 0; i < opt_cnt; i++, y += me_mfont_h) text_out16(x, y, "%s : %s", opts[i].name, @@ -1190,7 +1243,12 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ for (is_down = 1; is_down; ) kc = in_update_keycode(&dev_id, &is_down, -1); - unbind = count_bound_keys(dev_id, opts[sel].mask, player_idx) >= 2; + i = count_bound_keys(dev_id, opts[sel].mask, player_idx); + unbind = (i > 0); + + /* allow combos if device supports them */ + if (i == 1 && in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS)) + unbind = 0; in_bind_key(dev_id, kc, opts[sel].mask, unbind); if (player_idx >= 0) { @@ -1676,9 +1734,6 @@ static int menu_loop_options(menu_id id, int keys) // ------------ debug menu ------------ -#include -#include - #include extern void SekStepM68k(void); @@ -1706,17 +1761,21 @@ static void draw_text_debug(const char *str, int skip, int from) p = str; while (skip-- > 0) { - while (*p && *p != '\n') p++; - if (*p == 0 || p[1] == 0) return; + while (*p && *p != '\n') + p++; + if (*p == 0 || p[1] == 0) + return; p++; } str = p; - for (line = from; line < g_screen_height / 10; line++) + for (line = from; line < g_screen_height / me_sfont_h; line++) { - while (*p && *p != '\n') p++; - smalltext_out16(1, line*10, str, 0xffff); - if (*p == 0) break; + smalltext_out16(1, line * me_sfont_h, str, 0xffff); + while (*p && *p != '\n') + p++; + if (*p == 0) + break; p++; str = p; } } @@ -1731,7 +1790,7 @@ static void draw_frame_debug(void) memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); emu_forcedFrame(0); - smalltext_out16(4, g_screen_height - 8, layer_str, 0xffff); + smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff); } static void debug_menu_loop(void) @@ -1749,7 +1808,7 @@ static void debug_menu_loop(void) emu_platformDebugCat(tmp); draw_text_debug(tmp, 0, 0); if (dumped) { - smalltext_out16(g_screen_width - 6 * me_mfont_h, + smalltext_out16(g_screen_width - 6 * me_sfont_h, g_screen_height - me_mfont_h, "dumped", 0xffff); dumped = 0; } @@ -1885,6 +1944,10 @@ static int main_menu_handler(menu_id id, int keys) static menu_entry e_menu_main[] = { + mee_label ("PicoDrive " VERSION), + mee_label (""), + mee_label (""), + mee_label (""), mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler), mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler), mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler), @@ -1911,13 +1974,15 @@ void menu_loop(void) plat_video_menu_enter(rom_loaded); in_set_blocking(1); me_loop(e_menu_main, &sel); - in_set_blocking(0); - if (rom_loaded && engineState == PGS_Menu) { + if (rom_loaded) { + if (engineState == PGS_Menu) + engineState = PGS_Running; /* wait until menu, ok, back is released */ while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK)); - engineState = PGS_Running; } + + in_set_blocking(0); } // --------- CD tray close menu ---------- @@ -1967,7 +2032,6 @@ int menu_loop_tray(void) in_set_blocking(1); me_loop(e_menu_tray, &sel); - in_set_blocking(0); if (engineState != PGS_RestartRun) { engineState = PGS_RestartRun; @@ -1975,6 +2039,7 @@ int menu_loop_tray(void) } while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK)); + in_set_blocking(0); return ret; }