SDL: Implement lockMouse() in the 2D graphics managers (#2517)

This commit is contained in:
Cameron Cawley 2020-10-13 20:31:10 +01:00 committed by GitHub
parent 59ba9cb715
commit 26cd7d44e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 13 deletions

View File

@ -191,6 +191,10 @@ bool SdlGraphicsManager::showMouse(bool visible) {
return WindowedGraphicsManager::showMouse(visible);
}
bool SdlGraphicsManager::lockMouse(bool lock) {
return _window->lockMouse(lock);
}
bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
mouse.x = CLIP<int16>(mouse.x, 0, _windowWidth - 1);
mouse.y = CLIP<int16>(mouse.y, 0, _windowHeight - 1);

View File

@ -95,6 +95,7 @@ public:
virtual bool notifyMousePosition(Common::Point &mouse);
virtual bool showMouse(bool visible) override;
virtual bool lockMouse(bool lock) override;
virtual bool saveScreenshot(const Common::String &filename) const { return false; }
void saveScreenshot() override;

View File

@ -192,21 +192,9 @@ bool SdlGraphics3dManager::showMouse(bool visible) {
}
bool SdlGraphics3dManager::lockMouse(bool lock) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (lock)
SDL_SetRelativeMouseMode(SDL_TRUE);
else
SDL_SetRelativeMouseMode(SDL_FALSE);
#else
if (lock)
SDL_WM_GrabInput(SDL_GRAB_ON);
else
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
return true;
return _window->lockMouse(lock);
}
bool SdlGraphics3dManager::notifyMousePosition(Common::Point &mouse) {
transformMouseCoordinates(mouse);

View File

@ -162,6 +162,21 @@ void SdlWindow::toggleMouseGrab() {
#endif
}
bool SdlWindow::lockMouse(bool lock) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (lock)
SDL_SetRelativeMouseMode(SDL_TRUE);
else
SDL_SetRelativeMouseMode(SDL_FALSE);
#else
if (lock)
SDL_WM_GrabInput(SDL_GRAB_ON);
else
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
return true;
}
bool SdlWindow::hasMouseFocus() const {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) {

View File

@ -51,6 +51,11 @@ public:
*/
void toggleMouseGrab();
/**
* Lock or unlock the mouse cursor within the window.
*/
bool lockMouse(bool lock);
/**
* Check whether the application has mouse focus.
*/