X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=frontend%2Fcommon%2Fmenu.c;h=b05c755c1baec8a94eb5a32876990d18c5f348f3;hp=1cb41c5734b03c8c9837ef6149ceba3814586331;hb=4f5a1b2a86d077d32086de91f487a2ee5270714d;hpb=698517be481301b4525c29873134a67b8343af3c diff --git a/frontend/common/menu.c b/frontend/common/menu.c index 1cb41c57..b05c755c 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; @@ -461,8 +446,11 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) h = g_menuscreen_h; } - x = g_menuscreen_w / 2 - w / 2; + x = g_menuscreen_w / 2 - w / 2; y = g_menuscreen_h / 2 - h / 2; +#ifdef MENU_ALIGN_LEFT + if (x > 12) x = 12; +#endif /* draw */ menu_draw_begin(1); @@ -511,7 +499,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) len = strlen(names[i]); if (len > 10) offs = 10 - len - 2; - if (i == *(int *)ent->var) { + if (i == *(unsigned char *)ent->var) { text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", names[i]); break; } @@ -652,13 +640,12 @@ static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) /* ***************************************** */ -static void draw_menu_credits(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++; @@ -670,14 +657,14 @@ static void draw_menu_credits(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++) @@ -686,6 +673,9 @@ static void draw_menu_credits(void) p++; } + if (draw_more != NULL) + draw_more(); + menu_draw_end(); } @@ -726,22 +716,6 @@ static void do_delete(const char *fpath, const char *fname) // -------------- ROM selector -------------- -// rrrr rggg gggb bbbb -static unsigned short file2color(const char *fname) -{ - const char *ext = fname + strlen(fname) - 3; - static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" }; - static const char *other_exts[] = { "gmv", "pat" }; - int i; - - if (ext < fname) ext = fname; - for (i = 0; i < array_size(rom_exts); i++) - if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines - for (i = 0; i < array_size(other_exts); i++) - if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5; - return 0xffff; -} - static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) { int max_cnt, start, i, x, pos; @@ -770,7 +744,7 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) 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); + unsigned short color = fname2color(namelist[i+1]->d_name); smalltext_out16(x, pos * me_sfont_h, namelist[i+1]->d_name, color); } } @@ -897,9 +871,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; @@ -945,6 +922,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; } @@ -979,6 +963,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); @@ -1050,18 +1038,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; @@ -1070,22 +1051,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; @@ -1137,7 +1133,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; @@ -1166,7 +1165,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++) { @@ -1182,6 +1181,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; @@ -1195,18 +1195,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; @@ -1228,20 +1228,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); } }