mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
Move mouse movement stuff to fake_GetCursorPos where it should be
This commit is contained in:
parent
c940464de2
commit
fe6322d165
40
main.c
40
main.c
@ -287,21 +287,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
ShowWindow(ddraw->hWnd, SW_RESTORE);
|
ShowWindow(ddraw->hWnd, SW_RESTORE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fall trough */
|
|
||||||
case WM_WINDOWPOSCHANGED:
|
|
||||||
GetClientRect(ddraw->hWnd, &ddraw->cursorclip);
|
|
||||||
|
|
||||||
POINT pt = { ddraw->cursorclip.left, ddraw->cursorclip.top };
|
|
||||||
POINT pt2 = { ddraw->cursorclip.right, ddraw->cursorclip.bottom };
|
|
||||||
ClientToScreen(ddraw->hWnd, &pt);
|
|
||||||
ClientToScreen(ddraw->hWnd, &pt2);
|
|
||||||
SetRect(&ddraw->cursorclip, pt.x, pt.y, pt2.x, pt2.y);
|
|
||||||
|
|
||||||
ddraw->center.x = ddraw->cursorclip.left + ( (ddraw->cursorclip.right - ddraw->cursorclip.left) / 2);
|
|
||||||
ddraw->center.y = ddraw->cursorclip.top + ( (ddraw->cursorclip.bottom - ddraw->cursorclip.top) / 2);
|
|
||||||
|
|
||||||
DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
||||||
return 0;
|
return 0;
|
||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
if(wParam == VK_CONTROL || wParam == VK_TAB)
|
if(wParam == VK_CONTROL || wParam == VK_TAB)
|
||||||
@ -323,31 +308,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
lParam = MAKELPARAM(ddraw->cursor.x, ddraw->cursor.y);
|
lParam = MAKELPARAM(ddraw->cursor.x, ddraw->cursor.y);
|
||||||
break;
|
break;
|
||||||
case WM_MOUSEMOVE:
|
|
||||||
if(ddraw->locked)
|
|
||||||
{
|
|
||||||
if(LOWORD(lParam) != ddraw->render.width / 2 || HIWORD(lParam) != ddraw->render.height / 2)
|
|
||||||
{
|
|
||||||
if(ddraw->adjmouse)
|
|
||||||
{
|
|
||||||
ddraw->cursor.x += (LOWORD(lParam) - ddraw->render.width / 2) * ((float)ddraw->width / ddraw->render.width);
|
|
||||||
ddraw->cursor.y += (HIWORD(lParam) - ddraw->render.height / 2) * ((float)ddraw->height / ddraw->render.height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ddraw->cursor.x += LOWORD(lParam) - ddraw->render.width / 2;
|
|
||||||
ddraw->cursor.y += HIWORD(lParam) - ddraw->render.height / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ddraw->cursor.x < 0) ddraw->cursor.x = 0;
|
|
||||||
if(ddraw->cursor.y < 0) ddraw->cursor.y = 0;
|
|
||||||
if(ddraw->cursor.x > ddraw->width-1) ddraw->cursor.x = ddraw->width-1;
|
|
||||||
if(ddraw->cursor.y > ddraw->height-1) ddraw->cursor.y = ddraw->height-1;
|
|
||||||
|
|
||||||
SetCursorPos(ddraw->center.x, ddraw->center.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ddraw->WndProc(hWnd, uMsg, wParam, lParam);
|
return ddraw->WndProc(hWnd, uMsg, wParam, lParam);
|
||||||
|
49
mouse.c
49
mouse.c
@ -34,6 +34,34 @@ struct hack
|
|||||||
|
|
||||||
BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
|
BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
|
||||||
{
|
{
|
||||||
|
POINT pt;
|
||||||
|
|
||||||
|
if(mouse_active && ddraw->locked)
|
||||||
|
{
|
||||||
|
GetCursorPos(&pt);
|
||||||
|
|
||||||
|
if(ddraw->adjmouse)
|
||||||
|
{
|
||||||
|
ddraw->cursor.x += (pt.x - ddraw->center.x) * ((float)ddraw->width / ddraw->render.width);
|
||||||
|
ddraw->cursor.y += (pt.y - ddraw->center.y) * ((float)ddraw->height / ddraw->render.height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ddraw->cursor.x += pt.x - ddraw->center.x;
|
||||||
|
ddraw->cursor.y += pt.y - ddraw->center.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ddraw->cursor.x < 0) ddraw->cursor.x = 0;
|
||||||
|
if(ddraw->cursor.y < 0) ddraw->cursor.y = 0;
|
||||||
|
if(ddraw->cursor.x > ddraw->width-1) ddraw->cursor.x = ddraw->width-1;
|
||||||
|
if(ddraw->cursor.y > ddraw->height-1) ddraw->cursor.y = ddraw->height-1;
|
||||||
|
|
||||||
|
if(pt.x != ddraw->center.x || pt.y != ddraw->center.y)
|
||||||
|
{
|
||||||
|
SetCursorPos(ddraw->center.x, ddraw->center.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lpPoint->x = (int)ddraw->cursor.x;
|
lpPoint->x = (int)ddraw->cursor.x;
|
||||||
lpPoint->y = (int)ddraw->cursor.y;
|
lpPoint->y = (int)ddraw->cursor.y;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -138,12 +166,21 @@ void hack_iat(struct hack *hck)
|
|||||||
|
|
||||||
void mouse_lock()
|
void mouse_lock()
|
||||||
{
|
{
|
||||||
|
RECT rc;
|
||||||
|
|
||||||
if(mouse_active && !ddraw->locked)
|
if(mouse_active && !ddraw->locked)
|
||||||
{
|
{
|
||||||
ddraw->locked = TRUE;
|
GetWindowRect(ddraw->hWnd, &rc);
|
||||||
|
|
||||||
|
ddraw->center.x = (rc.right + rc.left) / 2;
|
||||||
|
ddraw->center.y = (rc.top + rc.bottom) / 2;
|
||||||
|
|
||||||
SetCursorPos(ddraw->center.x, ddraw->center.y);
|
SetCursorPos(ddraw->center.x, ddraw->center.y);
|
||||||
ClipCursor(&ddraw->cursorclip);
|
SetCapture(ddraw->hWnd);
|
||||||
|
ClipCursor(&rc);
|
||||||
|
|
||||||
while(ShowCursor(FALSE) > 0);
|
while(ShowCursor(FALSE) > 0);
|
||||||
|
ddraw->locked = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,10 +195,13 @@ void mouse_unlock()
|
|||||||
{
|
{
|
||||||
while(ShowCursor(TRUE) < 0);
|
while(ShowCursor(TRUE) < 0);
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||||
|
|
||||||
|
ClipCursor(NULL);
|
||||||
|
ReleaseCapture();
|
||||||
|
|
||||||
|
ddraw->locked = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ddraw->locked = FALSE;
|
|
||||||
ClipCursor(NULL);
|
|
||||||
ddraw->cursor.x = ddraw->width / 2;
|
ddraw->cursor.x = ddraw->width / 2;
|
||||||
ddraw->cursor.y = ddraw->height / 2;
|
ddraw->cursor.y = ddraw->height / 2;
|
||||||
}
|
}
|
||||||
@ -170,7 +210,6 @@ void mouse_init(HWND hWnd)
|
|||||||
{
|
{
|
||||||
if(ddraw->mhack)
|
if(ddraw->mhack)
|
||||||
{
|
{
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
|
||||||
hack_iat(&hacks[0]);
|
hack_iat(&hacks[0]);
|
||||||
mouse_active = TRUE;
|
mouse_active = TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user