diff --git a/src/Application.cpp b/src/Application.cpp index 3a58f8c..7549099 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -321,12 +321,15 @@ bool Application::init(const char* title, int width, int height) } SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); + _coreName.clear(); _gameData = NULL; _validSlots = 0; _isDriveFloppy = false; lastHardcore = hardcore(); cancelLoad = false; + _absViewMouseX = _absViewMouseY = 0; + updateMenu(); updateDiscMenu(true); return true; @@ -2420,6 +2423,7 @@ void Application::handle(const SDL_SysWMEvent* syswm) case IDM_EMULATOR_CONFIG: _config.showEmulatorSettingsDialog(); + updateMouseCapture(); updateSpeedIndicator(); _video.redraw(); break; @@ -2527,34 +2531,45 @@ void Application::handle(const SDL_MouseMotionEvent* motion) else if (viewY >= viewScaledHeight) viewY = viewScaledHeight - 1; + if (SDL_GetRelativeMouseMode()) + { + _absViewMouseX += motion->xrel; + _absViewMouseY += motion->yrel; + } + else + { + _absViewMouseX = viewX; + _absViewMouseY = viewY; + } + switch (_video.getRotation()) { default: rel_x = ((viewX << 16) / viewScaledWidth) - 32767; rel_y = ((viewY << 16) / viewScaledHeight) - 32767; - abs_x = (viewX * viewWidth) / viewScaledWidth; - abs_y = (viewY * viewHeight) / viewScaledHeight; + abs_x = (_absViewMouseX * viewWidth) / viewScaledWidth; + abs_y = (_absViewMouseY * viewHeight) / viewScaledHeight; break; case Video::Rotation::Ninety: rel_x = 32767 - ((viewY << 16) / viewScaledHeight); rel_y = ((viewX << 16) / viewScaledWidth) - 32767; - abs_x = viewWidth - ((viewY * viewWidth) / viewScaledHeight) - 1; - abs_y = (viewX * viewHeight) / viewScaledWidth; + abs_x = viewWidth - ((_absViewMouseY * viewWidth) / viewScaledHeight) - 1; + abs_y = (_absViewMouseX * viewHeight) / viewScaledWidth; break; case Video::Rotation::OneEighty: rel_x = 32767 - ((viewX << 16) / viewScaledWidth); rel_y = 32767 - ((viewY << 16) / viewScaledHeight); - abs_x = viewWidth - ((viewX * viewWidth) / viewScaledWidth) - 1; - abs_y = viewHeight - ((viewY * viewHeight) / viewScaledHeight) - 1; + abs_x = viewWidth - ((_absViewMouseX * viewWidth) / viewScaledWidth) - 1; + abs_y = viewHeight - ((_absViewMouseY * viewHeight) / viewScaledHeight) - 1; break; case Video::Rotation::TwoSeventy: rel_x = ((viewY << 16) / viewScaledHeight) - 32767; rel_y = 32767 - ((viewX << 16) / viewScaledWidth); - abs_x = (viewY * viewWidth) / viewScaledHeight; - abs_y = viewHeight - ((viewX * viewHeight) / viewScaledWidth) - 1; + abs_x = (_absViewMouseY * viewWidth) / viewScaledHeight; + abs_y = viewHeight - ((_absViewMouseX * viewHeight) / viewScaledWidth) - 1; break; } @@ -2684,11 +2699,16 @@ void Application::handle(const KeyBinds::Action action, unsigned extra) updateMenu(); _video.showMessage(_keybinds.hasGameFocus() ? "Game focus enabled" : "Game focus disabled", 60); - SDL_SetRelativeMouseMode(_keybinds.hasGameFocus() ? SDL_TRUE : SDL_FALSE); + updateMouseCapture(); break; } } +void Application::updateMouseCapture() +{ + SDL_SetRelativeMouseMode(_keybinds.hasGameFocus() && _config.getGameFocusCaptureMouse() ? SDL_TRUE : SDL_FALSE); +} + void Application::toggleFastForwarding(unsigned extra) { // get the current fast forward selection diff --git a/src/Application.h b/src/Application.h index fe0a202..c7fb758 100644 --- a/src/Application.h +++ b/src/Application.h @@ -125,6 +125,7 @@ class Application void loadConfiguration(int* window_x, int* window_y, int* window_width, int* window_height); void saveConfiguration(); std::string serializeRecentList(); + void updateMouseCapture(); void updateSpeedIndicator(); void toggleFastForwarding(unsigned extra); void toggleBackgroundInput(); @@ -180,4 +181,7 @@ class Application HMENU _menu; HMENU _cdRomMenu; + + int _absViewMouseX; + int _absViewMouseY; }; diff --git a/src/components/Config.cpp b/src/components/Config.cpp index 5e98692..0e50489 100644 --- a/src/components/Config.cpp +++ b/src/components/Config.cpp @@ -95,6 +95,7 @@ bool Config::init(libretro::LoggerComponent* logger) _fastForwardRatio = 5; _backgroundInput = false; _showSpeedIndicator = true; + _gameFocusCaptureMouse = false; reset(); return true; @@ -570,6 +571,10 @@ std::string Config::serializeEmulatorSettings() const json.append("\"showSpeedIndicator\":"); json.append(_showSpeedIndicator ? "true" : "false"); + json.append(","); + + json.append("\"gameFocusCaptureMouse\":"); + json.append(_gameFocusCaptureMouse ? "true" : "false"); json.append("}"); return json; @@ -608,6 +613,10 @@ bool Config::deserializeEmulatorSettings(const char* json) { ud->self->_showSpeedIndicator = num != 0; } + else if (ud->key == "gameFocusCaptureMouse") + { + ud->self->_gameFocusCaptureMouse = num != 0; + } } else if (event == JSONSAX_NUMBER) { @@ -939,6 +948,10 @@ void Config::showEmulatorSettingsDialog() db.addCheckbox("Show Indicator when Paused or Fast Forwarding", 51004, 0, y, WIDTH - 10, 8, &showSpeedIndicator); y += LINE; + bool gameFocusCaptureMouse = _gameFocusCaptureMouse; + db.addCheckbox("Capture mouse in Game Focus mode", 51005, 0, y, WIDTH - 10, 8, &gameFocusCaptureMouse); + y += LINE; + db.addButton("OK", IDOK, WIDTH - 55 - 50, y, 50, 14, true); db.addButton("Cancel", IDCANCEL, WIDTH - 50, y, 50, 14, false); @@ -947,6 +960,7 @@ void Config::showEmulatorSettingsDialog() _audioWhileFastForwarding = playAudio; _fastForwardRatio = fastForwardRatio + 2; _showSpeedIndicator = showSpeedIndicator; + _gameFocusCaptureMouse = gameFocusCaptureMouse; } } #endif diff --git a/src/components/Config.h b/src/components/Config.h index 071a5fa..2b3cd3e 100644 --- a/src/components/Config.h +++ b/src/components/Config.h @@ -60,6 +60,8 @@ class Config: public libretro::ConfigComponent virtual bool getShowSpeedIndicator() override { return _showSpeedIndicator; } virtual void setShowSpeedIndicator(bool value) override { _showSpeedIndicator = value; } + virtual bool getGameFocusCaptureMouse() override { return _gameFocusCaptureMouse; } + void setSaveDirectory(const std::string& path) { _saveFolder = path; } const char* getRootFolder() @@ -152,6 +154,7 @@ class Config: public libretro::ConfigComponent bool _audioWhileFastForwarding; bool _backgroundInput; bool _showSpeedIndicator; + bool _gameFocusCaptureMouse; int _fastForwardRatio; diff --git a/src/libretro/Components.h b/src/libretro/Components.h index 8060440..2b5e4d5 100644 --- a/src/libretro/Components.h +++ b/src/libretro/Components.h @@ -159,6 +159,8 @@ namespace libretro virtual bool getShowSpeedIndicator() = 0; virtual void setShowSpeedIndicator(bool value) = 0; + + virtual bool getGameFocusCaptureMouse() = 0; }; /** diff --git a/src/libretro/Core.cpp b/src/libretro/Core.cpp index 1a021ca..4d62abb 100644 --- a/src/libretro/Core.cpp +++ b/src/libretro/Core.cpp @@ -164,6 +164,11 @@ namespace { (void)value; } + + virtual bool getGameFocusCaptureMouse() override + { + return false; + } }; class DummyVideoContext : public libretro::VideoContextComponent