Clamp mouse motion to the video region rather than dropping it

This commit is contained in:
Cameron Gutman 2020-04-24 17:35:35 -07:00
parent 8cb98b5365
commit ab2bb51879

View file

@ -686,16 +686,12 @@ void SdlInputHandler::handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotion
// Use the stream and window sizes to determine the video region // Use the stream and window sizes to determine the video region
StreamUtils::scaleSourceToDestinationSurface(&src, &dst); StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
// Ignore motion outside the video region // Clamp motion to the video region
if (event->x < dst.x || event->y < dst.y || short x = qMin(qMax(event->x - dst.x, 0), dst.w);
event->x > dst.x + dst.w || event->y > dst.y + dst.h) { short y = qMin(qMax(event->y - dst.y, 0), dst.h);
return;
}
// Send the mouse position update with coordinates relative to // Send the mouse position update
// the video region. LiSendMousePositionEvent(x, y, dst.w, dst.h);
LiSendMousePositionEvent(event->x - dst.x, event->y - dst.y,
dst.w, dst.h);
} }
else { else {
// Batch until the next mouse polling window or we'll get awful // Batch until the next mouse polling window or we'll get awful
@ -752,7 +748,7 @@ void SdlInputHandler::sendGamepadState(GamepadState* state)
state->rsY); state->rsY);
} }
Uint32 SdlInputHandler::longPressTimerCallback(Uint32, void *param) Uint32 SdlInputHandler::longPressTimerCallback(Uint32, void*)
{ {
// Raise the left click and start a right click // Raise the left click and start a right click
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT); LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);