X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=frontend%2Fcommon%2Fmenu.c;h=d76eda43b4bdb74a5854ebb27ce6902a3af1beee;hb=3b349afa0c00ef0cbcb3de75ab6f70747bb890b2;hp=7890df4bf5dfbd527bce8c30d4fb026a626d5b43;hpb=4feed8d3c6c867a45cae54fa7399041c3b5dd2c1;p=pcsx_rearmed.git diff --git a/frontend/common/menu.c b/frontend/common/menu.c index 7890df4b..d76eda43 100644 --- a/frontend/common/menu.c +++ b/frontend/common/menu.c @@ -1,5 +1,5 @@ /* - * (C) Gražvydas "notaz" Ignotas, 2006-2010 + * (C) Gražvydas "notaz" Ignotas, 2006-2011 * * This work is licensed under the terms of any of these licenses * (at your option): @@ -372,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; @@ -460,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; @@ -470,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); @@ -494,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; } } @@ -545,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: @@ -573,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) @@ -592,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); @@ -636,6 +665,13 @@ 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); } /* ***************************************** */