From b9c6fa585c7ce9747e12df4928013f02aadab00d Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Sun, 27 Nov 2016 11:25:29 -0500 Subject: [PATCH] reverse variable names for clarity, add separate latch for OK button to solve looping of menu ok/cancel swap toggle --- menu/menu_event.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/menu/menu_event.c b/menu/menu_event.c index a8e7b501da..e1de58f7bb 100644 --- a/menu/menu_event.c +++ b/menu/menu_event.c @@ -199,11 +199,18 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input) size_t new_scroll_accel = 0; menu_input_t *menu_input = NULL; settings_t *settings = config_get_ptr(); + bool ok_current = false; + static bool ok_old = false; + bool ok_trigger = false; - menu_ok_btn = settings->input.menu_swap_ok_cancel_buttons ? - RETRO_DEVICE_ID_JOYPAD_A: RETRO_DEVICE_ID_JOYPAD_B; - menu_cancel_btn = settings->input.menu_swap_ok_cancel_buttons ? - RETRO_DEVICE_ID_JOYPAD_B: RETRO_DEVICE_ID_JOYPAD_A; + menu_ok_btn = settings->input.menu_swap_ok_cancel_buttons ? + RETRO_DEVICE_ID_JOYPAD_B : RETRO_DEVICE_ID_JOYPAD_A; + menu_cancel_btn = settings->input.menu_swap_ok_cancel_buttons ? + RETRO_DEVICE_ID_JOYPAD_A : RETRO_DEVICE_ID_JOYPAD_B; + + ok_current = input & UINT64_C(1) << menu_ok_btn; + ok_trigger = ok_current & ~ok_old; + ok_old = ok_current; if (input) { @@ -334,7 +341,7 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input) osk_idx = (enum osk_type)(OSK_TYPE_UNKNOWN + 1); } - if (trigger_input & (UINT64_C(1) << menu_cancel_btn)) + if (trigger_input & (UINT64_C(1) << menu_ok_btn)) { if (osk_ptr >= 0) { @@ -342,7 +349,7 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input) } } - if (trigger_input & (UINT64_C(1) << menu_ok_btn)) + if (trigger_input & (UINT64_C(1) << menu_cancel_btn)) { input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); } @@ -366,10 +373,10 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input) ret = MENU_ACTION_SCROLL_UP; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R)) ret = MENU_ACTION_SCROLL_DOWN; - else if (trigger_input & (UINT64_C(1) << menu_ok_btn)) - ret = MENU_ACTION_CANCEL; - else if (trigger_input & (UINT64_C(1) << menu_cancel_btn)) + else if (ok_trigger) ret = MENU_ACTION_OK; + else if (trigger_input & (UINT64_C(1) << menu_cancel_btn)) + ret = MENU_ACTION_CANCEL; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X)) ret = MENU_ACTION_SEARCH; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y))