Skip to content

Commit

Permalink
tweak fallback solution for possible ClipCursor failure
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Jun 2, 2018
1 parent ad07b46 commit 1d83797
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit 1d83797

Please sign in to comment.