mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
improve boxing/maintas cursor lock/unlock - fix automatic mouse sensitivity scaling with boxing/maintas
This commit is contained in:
parent
a1fa61d028
commit
9ce87449ec
8
ddraw.rc
8
ddraw.rc
@ -1,6 +1,6 @@
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 1,1,5,5
|
||||
PRODUCTVERSION 1,1,5,5
|
||||
FILEVERSION 1,1,5,6
|
||||
PRODUCTVERSION 1,1,5,6
|
||||
{
|
||||
BLOCK "StringFileInfo"
|
||||
{
|
||||
@ -8,13 +8,13 @@ PRODUCTVERSION 1,1,5,5
|
||||
{
|
||||
VALUE "CompanyName", "cncnet.org"
|
||||
VALUE "FileDescription", "DirectDraw replacement for C&C95 and Red Alert"
|
||||
VALUE "FileVersion", "1.1.5.5"
|
||||
VALUE "FileVersion", "1.1.5.6"
|
||||
VALUE "InternalName", "ddraw"
|
||||
VALUE "LegalCopyright", "Copyright (c) 2010-2018"
|
||||
VALUE "LegalTrademarks", ""
|
||||
VALUE "OriginalFileName", "ddraw.dll"
|
||||
VALUE "ProductName", "DirectDraw replacement for C&C95 and Red Alert"
|
||||
VALUE "ProductVersion", "1.1.5.5"
|
||||
VALUE "ProductVersion", "1.1.5.6"
|
||||
VALUE "Comments", "https://cncnet.org"
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ typedef struct IDirectDrawImpl
|
||||
HANDLE ev;
|
||||
HANDLE sem;
|
||||
DEVMODE mode;
|
||||
struct { int width; int height; int x; int y; } viewport;
|
||||
|
||||
} render;
|
||||
|
||||
|
63
src/main.c
63
src/main.c
@ -362,6 +362,47 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
|
||||
}
|
||||
}
|
||||
|
||||
ddraw->render.viewport.width = ddraw->render.width;
|
||||
ddraw->render.viewport.height = ddraw->render.height;
|
||||
ddraw->render.viewport.x = 0;
|
||||
ddraw->render.viewport.y = 0;
|
||||
|
||||
if (ddraw->boxing)
|
||||
{
|
||||
ddraw->render.viewport.width = ddraw->width;
|
||||
ddraw->render.viewport.height = ddraw->height;
|
||||
|
||||
int i;
|
||||
for (i = 20; i-- > 1;)
|
||||
{
|
||||
if (ddraw->width * i <= ddraw->render.width && ddraw->height * i <= ddraw->render.height)
|
||||
{
|
||||
ddraw->render.viewport.width *= i;
|
||||
ddraw->render.viewport.height *= i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ddraw->render.viewport.y = ddraw->render.height / 2 - ddraw->render.viewport.height / 2;
|
||||
ddraw->render.viewport.x = ddraw->render.width / 2 - ddraw->render.viewport.width / 2;
|
||||
}
|
||||
else if (ddraw->maintas)
|
||||
{
|
||||
ddraw->render.viewport.width = ddraw->render.width;
|
||||
ddraw->render.viewport.height = ((float)ddraw->height / ddraw->width) * ddraw->render.viewport.width;
|
||||
|
||||
if (ddraw->render.viewport.height > ddraw->render.height)
|
||||
{
|
||||
ddraw->render.viewport.width =
|
||||
((float)ddraw->render.viewport.width / ddraw->render.viewport.height) * ddraw->render.height;
|
||||
|
||||
ddraw->render.viewport.height = ddraw->render.height;
|
||||
}
|
||||
|
||||
ddraw->render.viewport.y = ddraw->render.height / 2 - ddraw->render.viewport.height / 2;
|
||||
ddraw->render.viewport.x = ddraw->render.width / 2 - ddraw->render.viewport.width / 2;
|
||||
}
|
||||
|
||||
if(This->windowed)
|
||||
{
|
||||
if(!This->windowed_init)
|
||||
@ -596,8 +637,26 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
case WM_MBUTTONUP:
|
||||
if (!ddraw->devmode && !ddraw->locked)
|
||||
{
|
||||
ddraw->cursor.x = LOWORD(lParam) * ((float)ddraw->width / ddraw->render.width);
|
||||
ddraw->cursor.y = HIWORD(lParam) * ((float)ddraw->height / ddraw->render.height);
|
||||
int x = LOWORD(lParam);
|
||||
int y = HIWORD(lParam);
|
||||
|
||||
if (x > ddraw->render.viewport.x + ddraw->render.viewport.width ||
|
||||
x < ddraw->render.viewport.x ||
|
||||
y > ddraw->render.viewport.y + ddraw->render.viewport.height ||
|
||||
y < ddraw->render.viewport.y)
|
||||
{
|
||||
ddraw->cursor.x = ddraw->width / 2;
|
||||
ddraw->cursor.y = ddraw->height / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ddraw->cursor.x =
|
||||
(x - ddraw->render.viewport.x) * ((float)ddraw->width / ddraw->render.viewport.width);
|
||||
|
||||
ddraw->cursor.y =
|
||||
(y - ddraw->render.viewport.y) * ((float)ddraw->height / ddraw->render.viewport.height);
|
||||
}
|
||||
|
||||
mouse_lock();
|
||||
return 0;
|
||||
}
|
||||
|
30
src/mouse.c
30
src/mouse.c
@ -44,8 +44,8 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
|
||||
{
|
||||
if(ddraw->adjmouse)
|
||||
{
|
||||
ddraw->cursor.x = pt.x * ((float)ddraw->width / ddraw->render.width);
|
||||
ddraw->cursor.y = pt.y * ((float)ddraw->height / ddraw->render.height);
|
||||
ddraw->cursor.x = pt.x * ((float)ddraw->width / ddraw->render.viewport.width);
|
||||
ddraw->cursor.y = pt.y * ((float)ddraw->height / ddraw->render.viewport.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -53,7 +53,7 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
|
||||
ddraw->cursor.y = pt.y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (lpPoint)
|
||||
{
|
||||
lpPoint->x = (int)ddraw->cursor.x;
|
||||
@ -178,11 +178,15 @@ void mouse_lock()
|
||||
// Get the window client area.
|
||||
GetClientRect(ddraw->hWnd, &rc);
|
||||
|
||||
if(!ddraw->adjmouse)
|
||||
if(ddraw->adjmouse)
|
||||
{
|
||||
// stretching fix
|
||||
rc.right -= (ddraw->render.width - ddraw->width);
|
||||
rc.bottom -= (ddraw->render.height - ddraw->height);
|
||||
rc.right = ddraw->render.viewport.width;
|
||||
rc.bottom = ddraw->render.viewport.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc.right = ddraw->width;
|
||||
rc.bottom = ddraw->height;
|
||||
}
|
||||
|
||||
// Convert the client area to screen coordinates.
|
||||
@ -193,13 +197,13 @@ void mouse_lock()
|
||||
|
||||
SetRect(&rc, pt.x, pt.y, pt2.x, pt2.y);
|
||||
|
||||
rc.bottom -= (yAdjust * 2) * ((float)ddraw->render.height / ddraw->height);
|
||||
rc.bottom -= (yAdjust * 2) * ((float)ddraw->render.viewport.height / ddraw->height);
|
||||
|
||||
if(ddraw->adjmouse)
|
||||
{
|
||||
SetCursorPos(
|
||||
rc.left + (ddraw->cursor.x * ((float)ddraw->render.width / ddraw->width)),
|
||||
rc.top + ((ddraw->cursor.y - yAdjust) * ((float)ddraw->render.height / ddraw->height)));
|
||||
rc.left + (ddraw->cursor.x * ((float)ddraw->render.viewport.width / ddraw->width)),
|
||||
rc.top + ((ddraw->cursor.y - yAdjust) * ((float)ddraw->render.viewport.height / ddraw->height)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -250,8 +254,10 @@ void mouse_unlock()
|
||||
ReleaseCapture();
|
||||
|
||||
SetCursorPos(
|
||||
rc.left + (ddraw->cursor.x * ((float)ddraw->render.width / ddraw->width)),
|
||||
rc.top + ((ddraw->cursor.y + yAdjust) * ((float)ddraw->render.height / ddraw->height)));
|
||||
rc.left + ddraw->render.viewport.x +
|
||||
(ddraw->cursor.x * ((float)ddraw->render.viewport.width / ddraw->width)),
|
||||
rc.top + ddraw->render.viewport.y +
|
||||
((ddraw->cursor.y + yAdjust) * ((float)ddraw->render.viewport.height / ddraw->height)));
|
||||
|
||||
}
|
||||
}
|
||||
|
43
src/render.c
43
src/render.c
@ -118,46 +118,9 @@ DWORD WINAPI render_main(void)
|
||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, PIXEL_FORMAT, GL_UNSIGNED_BYTE, tex);
|
||||
|
||||
DWORD dst_top = 0;
|
||||
DWORD dst_left = 0;
|
||||
DWORD dst_width = ddraw->render.width;
|
||||
DWORD dst_height = ddraw->render.height;
|
||||
|
||||
if (ddraw->boxing)
|
||||
{
|
||||
dst_width = ddraw->width;
|
||||
dst_height = ddraw->height;
|
||||
|
||||
int i;
|
||||
for (i = 20; i-- > 1;)
|
||||
{
|
||||
if (ddraw->width * i <= ddraw->render.width && ddraw->height * i <= ddraw->render.height)
|
||||
{
|
||||
dst_width *= i;
|
||||
dst_height *= i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dst_top = ddraw->render.height / 2 - dst_height / 2;
|
||||
dst_left = ddraw->render.width / 2 - dst_width / 2;
|
||||
}
|
||||
else if (ddraw->maintas)
|
||||
{
|
||||
dst_width = ddraw->render.width;
|
||||
dst_height = ((float)ddraw->height / ddraw->width) * dst_width;
|
||||
|
||||
if (dst_height > ddraw->render.height)
|
||||
{
|
||||
dst_width = ((float)dst_width / dst_height) * ddraw->render.height;
|
||||
dst_height = ddraw->render.height;
|
||||
}
|
||||
|
||||
dst_top = ddraw->render.height / 2 - dst_height / 2;
|
||||
dst_left = ddraw->render.width / 2 - dst_width / 2;
|
||||
}
|
||||
|
||||
glViewport(dst_left, dst_top, dst_width, dst_height);
|
||||
glViewport(
|
||||
ddraw->render.viewport.x, ddraw->render.viewport.y,
|
||||
ddraw->render.viewport.width, ddraw->render.viewport.height);
|
||||
|
||||
if(ddraw->render.filter)
|
||||
{
|
||||
|
@ -60,49 +60,10 @@ DWORD WINAPI render_soft_main(void)
|
||||
bmi->bmiHeader.biBitCount = ddraw->bpp;
|
||||
bmi->bmiHeader.biCompression = BI_RGB;
|
||||
|
||||
DWORD dst_top = 0;
|
||||
DWORD dst_left = 0;
|
||||
DWORD dst_width = ddraw->render.width;
|
||||
DWORD dst_height = ddraw->render.height;
|
||||
|
||||
DWORD tick_start = 0;
|
||||
DWORD tick_end = 0;
|
||||
DWORD frame_len = 0;
|
||||
|
||||
if (ddraw->boxing)
|
||||
{
|
||||
dst_width = ddraw->width;
|
||||
dst_height = ddraw->height;
|
||||
|
||||
int i;
|
||||
for (i = 20; i-- > 1;)
|
||||
{
|
||||
if (ddraw->width * i <= ddraw->render.width && ddraw->height * i <= ddraw->render.height)
|
||||
{
|
||||
dst_width *= i;
|
||||
dst_height *= i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dst_top = ddraw->render.height / 2 - dst_height / 2;
|
||||
dst_left = ddraw->render.width / 2 - dst_width / 2;
|
||||
}
|
||||
else if (ddraw->maintas)
|
||||
{
|
||||
dst_width = ddraw->render.width;
|
||||
dst_height = ((float)ddraw->height / ddraw->width) * dst_width;
|
||||
|
||||
if (dst_height > ddraw->render.height)
|
||||
{
|
||||
dst_width = ((float)dst_width / dst_height) * ddraw->render.height;
|
||||
dst_height = ddraw->render.height;
|
||||
}
|
||||
|
||||
dst_top = ddraw->render.height / 2 - dst_height / 2;
|
||||
dst_left = ddraw->render.width / 2 - dst_width / 2;
|
||||
}
|
||||
|
||||
if(ddraw->render.maxfps < 0)
|
||||
{
|
||||
ddraw->render.maxfps = ddraw->mode.dmDisplayFrequency;
|
||||
@ -144,7 +105,7 @@ DWORD WINAPI render_soft_main(void)
|
||||
|
||||
if ((ddraw->render.width != ddraw->width || ddraw->render.height != ddraw->height) && !(ddraw->vhack && detect_cutscene()) )
|
||||
{
|
||||
StretchDIBits(ddraw->render.hDC, dst_left, dst_top, dst_width, dst_height, 0, 0, ddraw->width, ddraw->height, ddraw->primary->surface, bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
StretchDIBits(ddraw->render.hDC, ddraw->render.viewport.x, ddraw->render.viewport.y, ddraw->render.viewport.width, ddraw->render.viewport.height, 0, 0, ddraw->width, ddraw->height, ddraw->primary->surface, bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
}
|
||||
else if (!(ddraw->vhack && detect_cutscene()))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user