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

@@ -64,6 +64,11 @@ class FrontendSDL {
bool keyboardAnalogY = false;
bool emuPaused = false;
bool returnToSelector = false;
#ifdef IMGUI_FRONTEND
bool controllerStartHeld = false;
bool controllerSelectHeld = false;
bool controllerPauseComboArmed = true;
#endif
private:
void setupControllerSensors(SDL_GameController* controller);

View File

@@ -27,6 +27,7 @@ class ImGuiLayer {
void setPauseCallback(std::function<void(bool)> callback) { onPauseChange = std::move(callback); }
void setVsyncCallback(std::function<void(bool)> callback) { onVsyncChange = std::move(callback); }
void setExitToSelectorCallback(std::function<void()> callback) { onExitToSelector = std::move(callback); }
void showPauseMenuFromController();
private:
void drawDebugPanel();

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();