| 1731 | // ========================================================== |
| 1732 | |
| 1733 | static void ProcessMenuNavigation() |
| 1734 | { |
| 1735 | if (IsInTransitionPeriod()) |
| 1736 | { |
| 1737 | ClearMenuButtonStates(); |
| 1738 | return; |
| 1739 | } |
| 1740 | |
| 1741 | const ULONGLONG currentTime = GetTickCount64(); |
| 1742 | |
| 1743 | SDL_GamepadButton confirmButton = SDL_GAMEPAD_BUTTON_SOUTH; |
| 1744 | SDL_GamepadButton cancelButton = SDL_GAMEPAD_BUTTON_EAST; |
| 1745 | |
| 1746 | if (s_capabilities.style == GamepadStyle::Nintendo) |
| 1747 | { |
| 1748 | confirmButton = SDL_GAMEPAD_BUTTON_EAST; |
| 1749 | cancelButton = SDL_GAMEPAD_BUTTON_SOUTH; |
| 1750 | } |
| 1751 | |
| 1752 | const struct { SDL_GamepadButton button; int vkey; } menuNavigation[] = |
| 1753 | { |
| 1754 | { SDL_GAMEPAD_BUTTON_DPAD_UP, VK_UP }, |
| 1755 | { SDL_GAMEPAD_BUTTON_DPAD_DOWN, VK_DOWN }, |
| 1756 | { SDL_GAMEPAD_BUTTON_DPAD_LEFT, VK_LEFT }, |
| 1757 | { SDL_GAMEPAD_BUTTON_DPAD_RIGHT, VK_RIGHT }, |
| 1758 | { confirmButton, VK_RETURN }, |
| 1759 | { cancelButton, VK_ESCAPE }, |
| 1760 | }; |
| 1761 | |
| 1762 | for (int i = 0; i < 6; i++) |
| 1763 | { |
| 1764 | auto& btnState = g_Controller.menuButtons[i]; |
| 1765 | bool pressed = false; |
| 1766 | |
| 1767 | if (i < 4) // D-Pad directions |
| 1768 | { |
| 1769 | bool dpadPressed = SDL_GetGamepadButton(s_pGamepad, menuNavigation[i].button); |
| 1770 | bool stickPressed = IsStickDirectionPressed(i); |
| 1771 | pressed = dpadPressed || stickPressed; |
| 1772 | |
| 1773 | // Repeat while held |
| 1774 | if (pressed && btnState.isPressed) |
| 1775 | { |
| 1776 | ULONGLONG elapsed = currentTime - btnState.pressStartTime; |
| 1777 | ULONGLONG sinceLast = currentTime - btnState.lastRepeatTime; |
| 1778 | |
| 1779 | if (elapsed > MENU_REPEAT_DELAY && sinceLast > MENU_REPEAT_RATE) |
| 1780 | { |
| 1781 | g_Controller.simulatedKeyPressCount++; |
| 1782 | PostMessage(g_State.hWnd, WM_KEYDOWN, menuNavigation[i].vkey, 0); |
| 1783 | btnState.lastRepeatTime = currentTime; |
| 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | else // Confirm/Cancel buttons |
| 1788 | { |
| 1789 | pressed = SDL_GetGamepadButton(s_pGamepad, menuNavigation[i].button); |
| 1790 | } |
no test coverage detected