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

fix cursor position issues with downscaling

This commit is contained in:
FunkyFr3sh 2023-09-14 16:47:28 +02:00
parent 597cdd9b48
commit accc47e377
5 changed files with 32 additions and 22 deletions

View File

@ -109,6 +109,11 @@ typedef struct CNCDDRAW
struct
{
float scale_x;
float scale_y;
float unscale_x;
float unscale_y;
int y_adjust;
int x_adjust;
RECT rc;

View File

@ -817,11 +817,16 @@ HRESULT dd_SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwFl
g_ddraw->render.unscale_w = ((float)g_ddraw->width / g_ddraw->render.viewport.width);
g_ddraw->render.unscale_h = ((float)g_ddraw->height / g_ddraw->render.viewport.height);
g_ddraw->mouse.scale_x = ((float)(g_ddraw->render.viewport.width - 1) / (g_ddraw->width - 1));
g_ddraw->mouse.scale_y = ((float)(g_ddraw->render.viewport.height - 1) / (g_ddraw->height - 1));
g_ddraw->mouse.unscale_x = ((float)(g_ddraw->width - 1) / (g_ddraw->render.viewport.width - 1));
g_ddraw->mouse.unscale_y = ((float)(g_ddraw->height - 1) / (g_ddraw->render.viewport.height - 1));
g_ddraw->mouse.x_adjust = g_ddraw->render.viewport.x;
g_ddraw->mouse.y_adjust = g_ddraw->render.viewport.y;
g_ddraw->mouse.rc.left = g_ddraw->mouse.x_adjust;;
g_ddraw->mouse.rc.top = g_ddraw->mouse.y_adjust;;
g_ddraw->mouse.rc.left = g_ddraw->mouse.x_adjust;
g_ddraw->mouse.rc.top = g_ddraw->mouse.y_adjust;
g_ddraw->mouse.rc.right = g_ddraw->width + g_ddraw->mouse.x_adjust;
g_ddraw->mouse.rc.bottom = g_ddraw->height + g_ddraw->mouse.y_adjust;

View File

@ -41,8 +41,8 @@ void mouse_lock()
int cur_y = InterlockedExchangeAdd((LONG*)&g_ddraw->cursor.y, 0);
real_SetCursorPos(
g_ddraw->adjmouse ? (int)(rc.left + (cur_x * g_ddraw->render.scale_w)) : rc.left + cur_x,
g_ddraw->adjmouse ? (int)(rc.top + (cur_y * g_ddraw->render.scale_h)) : rc.top + cur_y);
g_ddraw->adjmouse ? (int)(rc.left + (cur_x * g_ddraw->mouse.scale_x)) : rc.left + cur_x,
g_ddraw->adjmouse ? (int)(rc.top + (cur_y * g_ddraw->mouse.scale_y)) : rc.top + cur_y);
CopyRect(&rc, &g_ddraw->mouse.rc);
real_MapWindowPoints(g_ddraw->hwnd, HWND_DESKTOP, (LPPOINT)&rc, 2);
@ -73,8 +73,8 @@ void mouse_unlock()
int cur_y = InterlockedExchangeAdd((LONG*)&g_ddraw->cursor.y, 0);
real_SetCursorPos(
(int)(rc.left + (cur_x * g_ddraw->render.scale_w)),
(int)(rc.top + (cur_y * g_ddraw->render.scale_h)));
(int)(rc.left + (cur_x * g_ddraw->mouse.scale_x)),
(int)(rc.top + (cur_y * g_ddraw->mouse.scale_y)));
real_SetCursor(LoadCursor(NULL, IDC_ARROW));

View File

@ -74,8 +74,8 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
if (g_ddraw->adjmouse)
{
x = min((DWORD)(roundf(pt.x * g_ddraw->render.unscale_w)), g_ddraw->width - 1);
y = min((DWORD)(roundf(pt.y * g_ddraw->render.unscale_h)), g_ddraw->height - 1);
x = min((DWORD)(roundf(pt.x * g_ddraw->mouse.unscale_x)), g_ddraw->width - 1);
y = min((DWORD)(roundf(pt.y * g_ddraw->mouse.unscale_y)), g_ddraw->height - 1);
}
else
{
@ -299,8 +299,8 @@ BOOL WINAPI fake_SetCursorPos(int X, int Y)
if (g_ddraw->adjmouse)
{
pt.x = (LONG)(roundf(pt.x * g_ddraw->render.scale_w));
pt.y = (LONG)(roundf(pt.y * g_ddraw->render.scale_h));
pt.x = (LONG)(roundf(pt.x * g_ddraw->mouse.scale_x));
pt.y = (LONG)(roundf(pt.y * g_ddraw->mouse.scale_y));
}
pt.x += g_ddraw->mouse.x_adjust;
@ -428,8 +428,8 @@ LRESULT WINAPI fake_SendMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPar
if (g_ddraw->adjmouse)
{
x = (int)(roundf(x * g_ddraw->render.scale_w));
y = (int)(roundf(y * g_ddraw->render.scale_h));
x = (int)(roundf(x * g_ddraw->mouse.scale_x));
y = (int)(roundf(y * g_ddraw->mouse.scale_y));
}
lParam = MAKELPARAM(x + g_ddraw->mouse.x_adjust, y + g_ddraw->mouse.y_adjust);
@ -620,8 +620,8 @@ BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT w
}
else
{
x = (DWORD)((x - g_ddraw->render.viewport.x) * g_ddraw->render.unscale_w);
y = (DWORD)((y - g_ddraw->render.viewport.y) * g_ddraw->render.unscale_h);
x = (DWORD)((x - g_ddraw->render.viewport.x) * g_ddraw->mouse.unscale_x);
y = (DWORD)((y - g_ddraw->render.viewport.y) * g_ddraw->mouse.unscale_y);
}
InterlockedExchange((LONG*)&g_ddraw->cursor.x, x);
@ -667,8 +667,8 @@ BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT w
}
else
{
x = (DWORD)(roundf(x * g_ddraw->render.unscale_w));
y = (DWORD)(roundf(y * g_ddraw->render.unscale_h));
x = (DWORD)(roundf(x * g_ddraw->mouse.unscale_x));
y = (DWORD)(roundf(y * g_ddraw->mouse.unscale_y));
}
}

View File

@ -758,8 +758,8 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
}
else
{
x = (DWORD)((x - g_ddraw->render.viewport.x) * g_ddraw->render.unscale_w);
y = (DWORD)((y - g_ddraw->render.viewport.y) * g_ddraw->render.unscale_h);
x = (DWORD)((x - g_ddraw->render.viewport.x) * g_ddraw->mouse.unscale_x);
y = (DWORD)((y - g_ddraw->render.viewport.y) * g_ddraw->mouse.unscale_y);
}
InterlockedExchange((LONG*)&g_ddraw->cursor.x, x);
@ -804,8 +804,8 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
}
else
{
x = (DWORD)(roundf(x * g_ddraw->render.unscale_w));
y = (DWORD)(roundf(y * g_ddraw->render.unscale_h));
x = (DWORD)(roundf(x * g_ddraw->mouse.unscale_x));
y = (DWORD)(roundf(y * g_ddraw->mouse.unscale_y));
}
}
@ -833,8 +833,8 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
{
if (!g_ddraw->devmode && !g_mouse_locked)
{
int x = (DWORD)((GET_X_LPARAM(lParam) - g_ddraw->render.viewport.x) * g_ddraw->render.unscale_w);
int y = (DWORD)((GET_Y_LPARAM(lParam) - g_ddraw->render.viewport.y) * g_ddraw->render.unscale_h);
int x = (DWORD)((GET_X_LPARAM(lParam) - g_ddraw->render.viewport.x) * g_ddraw->mouse.unscale_x);
int y = (DWORD)((GET_Y_LPARAM(lParam) - g_ddraw->render.viewport.y) * g_ddraw->mouse.unscale_y);
InterlockedExchange((LONG*)&g_ddraw->cursor.x, x);
InterlockedExchange((LONG*)&g_ddraw->cursor.y, y);