X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=frontend%2Fcommon%2Fmenu.c;h=cf31610705a9d9468a06f65a4b70187da60dc1f3;hp=d9717d46fdbb306b31bfcdd80c45993a5597aacb;hb=51f77282d6cb4bc06248395cc1e712ee298910af;hpb=bd6267e616cc4966fadf971019fe15db2469e97d diff --git a/frontend/common/menu.c b/frontend/common/menu.c index d9717d46..cf316107 100644 --- a/frontend/common/menu.c +++ b/frontend/common/menu.c @@ -1,7 +1,12 @@ -// (c) Copyright 2006-2010 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. +/* + * (C) Gražvydas "notaz" Ignotas, 2006-2010 + * + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. + * See the COPYING file in the top-level directory. + */ #include #include @@ -341,26 +346,6 @@ static void menu_darken_bg(void *dst, void *src, int pixels, int darker) } } -static void menu_enter(int is_rom_loaded) -{ - if (is_rom_loaded) - { - // darken the active framebuffer - menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1); - } - else - { - char buff[256]; - - // should really only happen once, on startup.. - emu_make_path(buff, "skin/background.png", sizeof(buff)); - if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0) - memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); - } - - plat_video_menu_enter(is_rom_loaded); -} - static int me_id2offset(const menu_entry *ent, menu_id id) { int i; @@ -575,11 +560,11 @@ static int me_process(menu_entry *entry, int is_next, int is_lr) names = (const char **)entry->data; for (c = 0; names[c] != NULL; c++) ; - *(int *)entry->var += is_next ? 1 : -1; - if (*(int *)entry->var < 0) - *(int *)entry->var = 0; - if (*(int *)entry->var >= c) - *(int *)entry->var = c - 1; + *(signed char *)entry->var += is_next ? 1 : -1; + if (*(signed char *)entry->var < 0) + *(signed char *)entry->var = 0; + if (*(signed char *)entry->var >= c) + *(signed char *)entry->var = c - 1; return 1; default: return 0; @@ -588,14 +573,14 @@ static int me_process(menu_entry *entry, int is_next, int is_lr) static void debug_menu_loop(void); -static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) +static int me_loop_d(menu_entry *menu, int *menu_sel, void (*draw_prep)(void), void (*draw_more)(void)) { - int ret, inp, sel = *menu_sel, menu_sel_max; + int ret = 0, inp, sel = *menu_sel, menu_sel_max; menu_sel_max = me_count(menu) - 1; if (menu_sel_max < 0) { lprintf("no enabled menu entries\n"); - return; + return 0; } while ((!menu[sel].enabled || !menu[sel].selectable) && sel < menu_sel_max) @@ -607,6 +592,9 @@ static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) for (;;) { + if (draw_prep != NULL) + draw_prep(); + me_draw(menu, sel, draw_more); inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT| PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70); @@ -651,17 +639,23 @@ static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) } } *menu_sel = sel; + + return ret; +} + +static int me_loop(menu_entry *menu, int *menu_sel) +{ + return me_loop_d(menu, menu_sel, NULL, NULL); } /* ***************************************** */ -static void draw_menu_credits(void (*draw_more)(void)) +static void draw_menu_message(const char *msg, void (*draw_more)(void)) { - const char *creds, *p; int x, y, h, w, wt; + const char *p; - p = creds = plat_get_credits(); - + p = msg; for (h = 1, w = 0; *p != 0; h++) { for (wt = 0; *p != 0 && *p != '\n'; p++) wt++; @@ -673,14 +667,14 @@ static void draw_menu_credits(void (*draw_more)(void)) p++; } - x = g_menuscreen_w / 2 - w * me_mfont_w / 2; + x = g_menuscreen_w / 2 - w * me_mfont_w / 2; y = g_menuscreen_h / 2 - h * me_mfont_h / 2; if (x < 0) x = 0; if (y < 0) y = 0; menu_draw_begin(1); - for (p = creds; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) { + for (p = msg; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) { text_out16(x, y, p); for (; *p != 0 && *p != '\n'; p++) @@ -782,11 +776,6 @@ static int scandir_cmp(const void *p1, const void *p2) return alphasort(d1, d2); } -static const char *filter_exts[] = { - ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html", - ".jpg", ".gpe" -}; - static int scandir_filter(const struct dirent *ent) { const char *p; @@ -887,9 +876,12 @@ rescan: { int newlen; char *p, *newdir; - if (!(inp & PBTN_MOK)) continue; + if (!(inp & PBTN_MOK)) + continue; newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; newdir = malloc(newlen); + if (newdir == NULL) + break; if (strcmp(namelist[sel+1]->d_name, "..") == 0) { char *start = curr_path; p = start + strlen(start) - 1; @@ -935,6 +927,13 @@ rescan: free(namelist); } + // restore curr_path + if (fname != NULL) { + n = strlen(curr_path); + if (curr_path + n + 1 == fname) + curr_path[n] = '/'; + } + return ret; } @@ -969,6 +968,10 @@ static void draw_savestate_menu(int menu_sel, int is_loading) if (x < 0) x = 0; y = g_menuscreen_h / 2 - h / 2; if (y < 0) y = 0; +#ifdef MENU_ALIGN_LEFT + if (x > 12 + me_mfont_w * 2) + x = 12 + me_mfont_w * 2; +#endif menu_draw_begin(1); @@ -1040,18 +1043,11 @@ static int menu_loop_savestate(int is_loading) static char *action_binds(int player_idx, int action_mask, int dev_id) { - int k, count = 0, can_combo = 0, type; - const int *binds; + int dev = 0, dev_last = IN_MAX_DEVS - 1; + int can_combo = 1, type; static_buff[0] = 0; - binds = in_get_dev_binds(dev_id); - if (binds == NULL) - return static_buff; - - in_get_config(dev_id, IN_CFG_BIND_COUNT, &count); - in_get_config(dev_id, IN_CFG_DOES_COMBOS, &can_combo); - type = IN_BINDTYPE_EMU; if (player_idx >= 0) { can_combo = 0; @@ -1060,22 +1056,37 @@ static char *action_binds(int player_idx, int action_mask, int dev_id) if (player_idx == 1) action_mask <<= 16; - for (k = 0; k < count; k++) - { - const char *xname; - int len; + if (dev_id >= 0) + dev = dev_last = dev_id; + + for (; dev <= dev_last; dev++) { + int k, count = 0, combo = 0; + const int *binds; - if (!(binds[IN_BIND_OFFS(k, type)] & action_mask)) + binds = in_get_dev_binds(dev); + if (binds == NULL) continue; - xname = in_get_key_name(dev_id, k); - len = strlen(static_buff); - if (len) { - strncat(static_buff, can_combo ? " + " : ", ", - sizeof(static_buff) - len - 1); - len += can_combo ? 3 : 2; + in_get_config(dev, IN_CFG_BIND_COUNT, &count); + in_get_config(dev, IN_CFG_DOES_COMBOS, &combo); + combo = combo && can_combo; + + for (k = 0; k < count; k++) { + const char *xname; + int len; + + if (!(binds[IN_BIND_OFFS(k, type)] & action_mask)) + continue; + + xname = in_get_key_name(dev, k); + len = strlen(static_buff); + if (len) { + strncat(static_buff, combo ? " + " : ", ", + sizeof(static_buff) - len - 1); + len += combo ? 3 : 2; + } + strncat(static_buff, xname, sizeof(static_buff) - len - 1); } - strncat(static_buff, xname, sizeof(static_buff) - len - 1); } return static_buff; @@ -1127,7 +1138,10 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask, dev_id)); - dev_name = in_get_dev_name(dev_id, 1, 1); + if (dev_id < 0) + dev_name = "(all devices)"; + else + dev_name = in_get_dev_name(dev_id, 1, 1); w = strlen(dev_name) * me_mfont_w; if (w < 30 * me_mfont_w) w = 30 * me_mfont_w; @@ -1156,7 +1170,7 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx) { int i, sel = 0, menu_sel_max = opt_cnt - 1, does_combos = 0; - int dev_id, dev_count, kc, is_down, mkey; + int dev_id, bind_dev_id, dev_count, kc, is_down, mkey; int unbind, bindtype, mask_shift; for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) { @@ -1172,6 +1186,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ return; } + dev_id = -1; // show all mask_shift = 0; if (player_idx == 1) mask_shift = 16; @@ -1185,18 +1200,18 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue; case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue; case PBTN_LEFT: - for (i = 0, dev_id--; i < IN_MAX_DEVS; i++, dev_id--) { - if (dev_id < 0) + for (i = 0, dev_id--; i < IN_MAX_DEVS + 1; i++, dev_id--) { + if (dev_id < -1) dev_id = IN_MAX_DEVS - 1; - if (in_get_dev_name(dev_id, 1, 0) != NULL) + if (dev_id == -1 || in_get_dev_name(dev_id, 1, 0) != NULL) break; } continue; case PBTN_RIGHT: for (i = 0, dev_id++; i < IN_MAX_DEVS; i++, dev_id++) { if (dev_id >= IN_MAX_DEVS) - dev_id = 0; - if (in_get_dev_name(dev_id, 1, 0) != NULL) + dev_id = -1; + if (dev_id == -1 || in_get_dev_name(dev_id, 1, 0) != NULL) break; } continue; @@ -1218,20 +1233,20 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ /* wait for some up event */ for (is_down = 1; is_down; ) - kc = in_update_keycode(&dev_id, &is_down, -1); + kc = in_update_keycode(&bind_dev_id, &is_down, -1); - i = count_bound_keys(dev_id, opts[sel].mask << mask_shift, bindtype); + i = count_bound_keys(bind_dev_id, opts[sel].mask << mask_shift, bindtype); unbind = (i > 0); /* allow combos if device supports them */ - in_get_config(dev_id, IN_CFG_DOES_COMBOS, &does_combos); + in_get_config(bind_dev_id, IN_CFG_DOES_COMBOS, &does_combos); if (i == 1 && bindtype == IN_BINDTYPE_EMU && does_combos) unbind = 0; if (unbind) - in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype); + in_unbind_all(bind_dev_id, opts[sel].mask << mask_shift, bindtype); - in_bind_key(dev_id, kc, opts[sel].mask << mask_shift, bindtype, 0); + in_bind_key(bind_dev_id, kc, opts[sel].mask << mask_shift, bindtype, 0); } }