feat: add controller support for pause menu and update ImGuiLayer functionality

This commit is contained in:
moonpower
2026-02-02 03:08:01 +03:00
parent cb9d09aca0
commit 8299059dd4
4 changed files with 37 additions and 0 deletions

View File

@@ -317,6 +317,9 @@ void FrontendSDL::run() {
#ifdef IMGUI_FRONTEND
int lastDrawableW = -1;
int lastDrawableH = -1;
controllerStartHeld = false;
controllerSelectHeld = false;
controllerPauseComboArmed = true;
#endif
while (programRunning) {
@@ -523,6 +526,24 @@ void FrontendSDL::run() {
case SDL_CONTROLLER_BUTTON_START: key = Keys::Start; break;
}
#ifdef IMGUI_FRONTEND
if (event.cbutton.button == SDL_CONTROLLER_BUTTON_START) {
controllerStartHeld = event.cbutton.state == SDL_PRESSED;
}
if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) {
controllerSelectHeld = event.cbutton.state == SDL_PRESSED;
}
if (event.cbutton.state == SDL_PRESSED && controllerStartHeld && controllerSelectHeld && controllerPauseComboArmed) {
controllerPauseComboArmed = false;
if (imgui) {
imgui->showPauseMenuFromController();
}
}
if (event.cbutton.state == SDL_RELEASED && (!controllerStartHeld && !controllerSelectHeld)) {
controllerPauseComboArmed = true;
}
#endif
if (key != 0) {
if (event.cbutton.state == SDL_PRESSED) {
hid.pressKey(key);

View File

@@ -236,6 +236,16 @@ void ImGuiLayer::handleHotkey(const SDL_Event& event) {
}
}
void ImGuiLayer::showPauseMenuFromController() {
if (!showPauseMenu) {
showPauseMenu = true;
if (onPauseChange) {
isPaused = true;
onPauseChange(true);
}
}
}
std::optional<std::filesystem::path> ImGuiLayer::runGameSelector() {
std::vector<InstalledGame> games = scanAllGames();
bool showNoRom = games.empty();