[Scummvm-git-logs] scummvm master -> c6836c9b7778024617ed4838f7a0bdeaff412cb4
sev-
noreply at scummvm.org
Fri Nov 19 18:53:03 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
c6836c9b77 SDL: Use SDL_SetWindowMouseRect to confine the mouse area
Commit: c6836c9b7778024617ed4838f7a0bdeaff412cb4
https://github.com/scummvm/scummvm/commit/c6836c9b7778024617ed4838f7a0bdeaff412cb4
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-11-19T19:52:58+01:00
Commit Message:
SDL: Use SDL_SetWindowMouseRect to confine the mouse area
Changed paths:
backends/graphics/sdl/sdl-graphics.cpp
backends/graphics/sdl/sdl-graphics.h
backends/graphics/windowed.h
backends/platform/sdl/sdl-window.cpp
backends/platform/sdl/sdl-window.h
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index acc405bcba..b3c8e4e74c 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -282,6 +282,10 @@ void SdlGraphicsManager::setSystemMousePosition(const int x, const int y) {
}
}
+void SdlGraphicsManager::notifyActiveAreaChanged() {
+ _window->setMouseRect(_activeArea.drawRect);
+}
+
void SdlGraphicsManager::handleResizeImpl(const int width, const int height) {
_forceRedraw = true;
}
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 921eda5bfd..1b36ef20dc 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -182,6 +182,8 @@ protected:
void setSystemMousePosition(const int x, const int y) override;
+ void notifyActiveAreaChanged() override;
+
void handleResizeImpl(const int width, const int height) override;
#if SDL_VERSION_ATLEAST(2, 0, 0)
diff --git a/backends/graphics/windowed.h b/backends/graphics/windowed.h
index 4430c517db..d9763ef4d1 100644
--- a/backends/graphics/windowed.h
+++ b/backends/graphics/windowed.h
@@ -63,6 +63,7 @@ public:
_activeArea.height = getOverlayHeight();
_overlayVisible = true;
_forceRedraw = true;
+ notifyActiveAreaChanged();
}
void hideOverlay() override {
@@ -74,6 +75,7 @@ public:
_activeArea.height = getHeight();
_overlayVisible = false;
_forceRedraw = true;
+ notifyActiveAreaChanged();
}
bool isOverlayVisible() const override { return _overlayVisible; }
@@ -211,6 +213,7 @@ protected:
_activeArea.width = getWidth();
_activeArea.height = getHeight();
}
+ notifyActiveAreaChanged();
}
/**
@@ -222,6 +225,11 @@ protected:
*/
virtual void setSystemMousePosition(const int x, const int y) = 0;
+ /**
+ * Called whenever the active area has changed.
+ */
+ virtual void notifyActiveAreaChanged() {}
+
bool showMouse(bool visible) override {
if (_cursorVisible == visible) {
return visible;
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index 70b2e6444a..43e0ebecd1 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -39,6 +39,7 @@ SdlWindow::SdlWindow() :
#endif
_inputGrabState(false), _inputLockState(false)
{
+ memset(&grabRect, 0, sizeof(grabRect));
#if SDL_VERSION_ATLEAST(2, 0, 0)
#elif SDL_VERSION_ATLEAST(1, 2, 10)
@@ -150,6 +151,9 @@ void SdlWindow::grabMouse(bool grab) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) {
SDL_SetWindowGrab(_window, grab ? SDL_TRUE : SDL_FALSE);
+#if SDL_VERSION_ATLEAST(2, 0, 17)
+ SDL_SetWindowMouseRect(_window, grab ? &grabRect : NULL);
+#endif
}
_inputGrabState = grab;
#else
@@ -164,6 +168,19 @@ void SdlWindow::grabMouse(bool grab) {
#endif
}
+void SdlWindow::setMouseRect(const Common::Rect &rect) {
+ grabRect.x = rect.left;
+ grabRect.y = rect.top;
+ grabRect.w = rect.width();
+ grabRect.h = rect.height();
+
+#if SDL_VERSION_ATLEAST(2, 0, 17)
+ if (_inputGrabState || _lastFlags & fullscreenMask) {
+ SDL_SetWindowMouseRect(_window, &grabRect);
+ }
+#endif
+}
+
bool SdlWindow::lockMouse(bool lock) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetRelativeMouseMode(lock ? SDL_TRUE : SDL_FALSE);
@@ -397,6 +414,9 @@ bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) {
const bool shouldGrab = (flags & SDL_WINDOW_INPUT_GRABBED) || fullscreenFlags;
SDL_SetWindowGrab(_window, shouldGrab ? SDL_TRUE : SDL_FALSE);
+#if SDL_VERSION_ATLEAST(2, 0, 17)
+ SDL_SetWindowMouseRect(_window, shouldGrab ? &grabRect : NULL);
+#endif
if (!_window) {
return false;
diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h
index 7006d82029..f969c44a59 100644
--- a/backends/platform/sdl/sdl-window.h
+++ b/backends/platform/sdl/sdl-window.h
@@ -51,6 +51,11 @@ public:
*/
void grabMouse(bool grab);
+ /**
+ * Specify the area of the window to confine the mouse cursor.
+ */
+ void setMouseRect(const Common::Rect &rect);
+
/**
* Lock or unlock the mouse cursor within the window.
*/
@@ -124,6 +129,7 @@ public:
private:
Common::Rect _desktopRes;
bool _inputGrabState, _inputLockState;
+ SDL_Rect grabRect;
protected:
void getDisplayDpi(float *dpi, float *defaultDpi) const;
More information about the Scummvm-git-logs
mailing list