aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
authorColin Snover2017-09-13 19:55:14 -0500
committerColin Snover2017-10-15 13:24:21 -0500
commitcd538ffffab9e49443da4ee043916d8dc22c3c07 (patch)
treeaebfd4a4009e2653a743241875a0ce27cad07065 /backends/graphics
parent319ab07fe0900e6ec2f89666b544e695edca6dde (diff)
downloadscummvm-rg350-cd538ffffab9e49443da4ee043916d8dc22c3c07.tar.gz
scummvm-rg350-cd538ffffab9e49443da4ee043916d8dc22c3c07.tar.bz2
scummvm-rg350-cd538ffffab9e49443da4ee043916d8dc22c3c07.zip
BACKENDS: Do not send mouse events to games occurring outside the game draw rect
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp39
-rw-r--r--backends/graphics/sdl/sdl-graphics.h4
-rw-r--r--backends/graphics/windowed.h9
3 files changed, 43 insertions, 9 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index 6ce0bc7bac..e6699df1cd 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -169,22 +169,47 @@ bool SdlGraphicsManager::showMouse(const bool visible) {
return WindowedGraphicsManager::showMouse(visible);
}
-void SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
+bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
int showCursor = SDL_DISABLE;
- if (!_activeArea.drawRect.contains(mouse)) {
+ bool valid = true;
+ if (_activeArea.drawRect.contains(mouse)) {
+ _cursorLastInActiveArea = true;
+ } else {
mouse.x = CLIP<int>(mouse.x, _activeArea.drawRect.left, _activeArea.drawRect.right - 1);
mouse.y = CLIP<int>(mouse.y, _activeArea.drawRect.top, _activeArea.drawRect.bottom - 1);
- if (_window->mouseIsGrabbed()) {
+ if (_window->mouseIsGrabbed() ||
+ // Keep the mouse inside the game area during dragging to prevent an
+ // event mismatch where the mouseup event gets lost because it is
+ // performed outside of the game area
+ (_cursorLastInActiveArea && SDL_GetMouseState(nullptr, nullptr) != 0)) {
setSystemMousePosition(mouse.x, mouse.y);
- } else if (_cursorVisible) {
- showCursor = SDL_ENABLE;
+ } else {
+ // Allow the in-game mouse to get a final movement event to the edge
+ // of the window if the mouse was moved out of the game area
+ if (_cursorLastInActiveArea) {
+ _cursorLastInActiveArea = false;
+ } else if (_cursorVisible) {
+ // Keep sending events to the game if the cursor is invisible,
+ // since otherwise if a game lets you skip a cutscene by
+ // clicking and the user moved the mouse outside the active
+ // area, the clicks wouldn't do anything, which would be
+ // confusing
+ valid = false;
+ }
+
+ if (_cursorVisible) {
+ showCursor = SDL_ENABLE;
+ }
}
}
SDL_ShowCursor(showCursor);
- setMousePosition(mouse.x, mouse.y);
- mouse = convertWindowToVirtual(mouse.x, mouse.y);
+ if (valid) {
+ setMousePosition(mouse.x, mouse.y);
+ mouse = convertWindowToVirtual(mouse.x, mouse.y);
+ }
+ return valid;
}
void SdlGraphicsManager::handleResizeImpl(const int width, const int height) {
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 772bc88637..993a1c3db6 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -84,8 +84,10 @@ public:
*
* @param mouse The mouse position in window coordinates, which must be
* converted synchronously to virtual coordinates.
+ * @returns true if the mouse was in a valid position for the game and
+ * should cause the event to be sent to the game.
*/
- virtual void notifyMousePosition(Common::Point &mouse);
+ virtual bool notifyMousePosition(Common::Point &mouse);
virtual bool showMouse(const bool visible) override;
diff --git a/backends/graphics/windowed.h b/backends/graphics/windowed.h
index 52bb96c2cf..1d4958c9d6 100644
--- a/backends/graphics/windowed.h
+++ b/backends/graphics/windowed.h
@@ -39,7 +39,8 @@ public:
_cursorVisible(false),
_cursorX(0),
_cursorY(0),
- _cursorNeedsRedraw(false) {}
+ _cursorNeedsRedraw(false),
+ _cursorLastInActiveArea(true) {}
virtual void showOverlay() override {
if (_overlayVisible)
@@ -304,6 +305,12 @@ protected:
bool _cursorNeedsRedraw;
/**
+ * Whether the last position of the system cursor was within the active area
+ * of the window.
+ */
+ bool _cursorLastInActiveArea;
+
+ /**
* The position of the mouse cursor, in window coordinates.
*/
int _cursorX, _cursorY;