X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=frontend%2Fcommon%2Fmenu.c;h=d76eda43b4bdb74a5854ebb27ce6902a3af1beee;hp=ae1ff57d0da05dd06bc821957a5a2b9b66bcf9ee;hb=3b349afa0c00ef0cbcb3de75ab6f70747bb890b2;hpb=61363062a18cd8382932310e8072fc06f5c8eeb5 diff --git a/frontend/common/menu.c b/frontend/common/menu.c index ae1ff57d..d76eda43 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-2011 + * + * 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 @@ -367,6 +372,28 @@ static int me_count(const menu_entry *ent) return ret; } +static unsigned int me_read_onoff(const menu_entry *ent) +{ + // guess var size based on mask to avoid reading too much + if (ent->mask & 0xffff0000) + return *(unsigned int *)ent->var & ent->mask; + else if (ent->mask & 0xff00) + return *(unsigned short *)ent->var & ent->mask; + else + return *(unsigned char *)ent->var & ent->mask; +} + +static void me_toggle_onoff(menu_entry *ent) +{ + // guess var size based on mask to avoid reading too much + if (ent->mask & 0xffff0000) + *(unsigned int *)ent->var ^= ent->mask; + else if (ent->mask & 0xff00) + *(unsigned short *)ent->var ^= ent->mask; + else + *(unsigned char *)ent->var ^= ent->mask; +} + static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) { const menu_entry *ent, *ent_sel = entries; @@ -455,7 +482,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) for (ent = entries; ent->name; ent++) { const char **names; - int len; + int len, leftname_end = 0; if (!ent->enabled) continue; @@ -465,14 +492,16 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) if (ent->generate_name) name = ent->generate_name(ent->id, &offs); } - if (name != NULL) + if (name != NULL) { text_out16(x, y, name); + leftname_end = x + (strlen(name) + 1) * me_mfont_w; + } switch (ent->beh) { case MB_NONE: break; case MB_OPT_ONOFF: - text_out16(x + col2_offs, y, (*(int *)ent->var & ent->mask) ? "ON" : "OFF"); + text_out16(x + col2_offs, y, me_read_onoff(ent) ? "ON" : "OFF"); break; case MB_OPT_RANGE: text_out16(x + col2_offs, y, "%i", *(int *)ent->var); @@ -489,13 +518,15 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) break; case MB_OPT_ENUM: names = (const char **)ent->data; - offs = 0; for (i = 0; names[i] != NULL; i++) { + offs = x + col2_offs; len = strlen(names[i]); if (len > 10) - offs = 10 - len - 2; + offs += (10 - len - 2) * me_mfont_w; + if (offs < leftname_end) + offs = leftname_end; if (i == *(unsigned char *)ent->var) { - text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", names[i]); + text_out16(offs, y, "%s", names[i]); break; } } @@ -540,7 +571,7 @@ static int me_process(menu_entry *entry, int is_next, int is_lr) { case MB_OPT_ONOFF: case MB_OPT_CUSTONOFF: - *(int *)entry->var ^= entry->mask; + me_toggle_onoff(entry); return 1; case MB_OPT_RANGE: case MB_OPT_CUSTRANGE: @@ -555,11 +586,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; @@ -568,14 +599,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) @@ -587,6 +618,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); @@ -631,17 +665,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++; @@ -660,7 +700,7 @@ static void draw_menu_credits(void (*draw_more)(void)) 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++) @@ -762,11 +802,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; @@ -867,9 +902,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; @@ -915,6 +953,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; } @@ -1024,18 +1069,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; @@ -1044,22 +1082,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; - if (!(binds[IN_BIND_OFFS(k, type)] & action_mask)) + for (; dev <= dev_last; dev++) { + int k, count = 0, combo = 0; + const int *binds; + + 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; @@ -1111,7 +1164,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; @@ -1140,7 +1196,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++) { @@ -1156,6 +1212,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; @@ -1169,18 +1226,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; @@ -1202,20 +1259,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); } }