From 1d83797a48273f0c1f9a4f4075cbbc147c963ba9 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sat, 2 Jun 2018 13:21:00 +0200 Subject: [PATCH] tweak fallback solution for possible ClipCursor failure --- src/mouse.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index 120bea3..ef94a90 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -47,21 +47,35 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint) { //fallback solution for possible ClipCursor failure int diffx = 0, diffy = 0; + int maxWidth = ddraw->adjmouse ? ddraw->render.viewport.width : ddraw->width; + int maxHeight = ddraw->adjmouse ? ddraw->render.viewport.height : ddraw->height; if (pt.x < 0) { - diffx = abs(pt.x); + diffx = pt.x; pt.x = 0; } if (pt.y < 0) { - diffy = abs(pt.y); + diffy = pt.y; pt.y = 0; } + if (pt.x > maxWidth) + { + diffx = pt.x - maxWidth; + pt.x = maxWidth; + } + + if (pt.y > maxHeight) + { + diffy = pt.y - maxHeight; + pt.y = maxHeight; + } + if (diffx || diffy) - SetCursorPos(realpt.x + diffx, realpt.y + diffy); + SetCursorPos(realpt.x - diffx, realpt.y - diffy); if(ddraw->adjmouse) @@ -75,26 +89,6 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint) ddraw->cursor.y = pt.y; } - //fallback solution for possible ClipCursor failure - diffx = 0; - diffy = 0; - - if (ddraw->cursor.x > ddraw->width) - { - diffx = ddraw->cursor.x - ddraw->width; - ddraw->cursor.x = ddraw->width; - } - - if (ddraw->cursor.y > ddraw->height) - { - diffy = ddraw->cursor.y - ddraw->height; - ddraw->cursor.y = ddraw->height; - } - - if (diffx || diffy) - SetCursorPos(realpt.x - diffx, realpt.y - diffy); - - if (ddraw->vhack && (ddraw->iscnc1 || ddraw->isredalert) && ddraw->incutscene) { diffx = 0;