1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

fix jumping cursor while zooming

This commit is contained in:
FunkyFr3sh 2024-07-26 08:27:42 +02:00
parent fa14a8b60a
commit 918037dd3e
2 changed files with 29 additions and 6 deletions

View File

@ -642,8 +642,8 @@ HRESULT dd_SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwFl
g_ddraw.height = dwHeight;
g_ddraw.bpp = dwBPP;
InterlockedExchange((LONG*)&g_ddraw.cursor.x, dwWidth / 2);
InterlockedExchange((LONG*)&g_ddraw.cursor.y, dwHeight / 2);
//InterlockedExchange((LONG*)&g_ddraw.cursor.x, dwWidth / 2);
//InterlockedExchange((LONG*)&g_ddraw.cursor.y, dwHeight / 2);
BOOL border = g_config.border;
BOOL nonexclusive = FALSE;

View File

@ -38,12 +38,35 @@ void mouse_lock()
real_MapWindowPoints(g_ddraw.hwnd, HWND_DESKTOP, (LPPOINT)&rc, 2);
OffsetRect(&rc, g_ddraw.render.viewport.x, g_ddraw.render.viewport.y);
int cur_x = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.x, 0);
int cur_y = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.y, 0);
POINT pt;
real_GetCursorPos(&pt);
if (!g_config.windowed || real_ScreenToClient(g_ddraw.hwnd, &pt))
{
if (pt.x > g_ddraw.render.viewport.x + g_ddraw.render.viewport.width ||
pt.x < g_ddraw.render.viewport.x ||
pt.y > g_ddraw.render.viewport.y + g_ddraw.render.viewport.height ||
pt.y < g_ddraw.render.viewport.y)
{
pt.x = g_ddraw.width / 2;
pt.y = g_ddraw.height / 2;
}
else
{
pt.x = (DWORD)((pt.x - g_ddraw.render.viewport.x) * g_ddraw.mouse.unscale_x);
pt.y = (DWORD)((pt.y - g_ddraw.render.viewport.y) * g_ddraw.mouse.unscale_y);
}
pt.x = min(pt.x, g_ddraw.width - 1);
pt.y = min(pt.y, g_ddraw.height - 1);
InterlockedExchange((LONG*)&g_ddraw.cursor.x, pt.x);
InterlockedExchange((LONG*)&g_ddraw.cursor.y, pt.y);
}
real_SetCursorPos(
g_config.adjmouse ? (int)(rc.left + (cur_x * g_ddraw.mouse.scale_x)) : rc.left + cur_x,
g_config.adjmouse ? (int)(rc.top + (cur_y * g_ddraw.mouse.scale_y)) : rc.top + cur_y);
g_config.adjmouse ? (int)(rc.left + (pt.x * g_ddraw.mouse.scale_x)) : rc.left + pt.x,
g_config.adjmouse ? (int)(rc.top + (pt.y * g_ddraw.mouse.scale_y)) : rc.top + pt.y);
CopyRect(&rc, &g_ddraw.mouse.rc);
real_MapWindowPoints(g_ddraw.hwnd, HWND_DESKTOP, (LPPOINT)&rc, 2);