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

add experimental aspect_ratio setting (hidden for now)

This commit is contained in:
FunkyFr3sh 2024-08-15 10:16:20 +02:00
parent e23a0ce1d5
commit c7e4b81ad7
5 changed files with 59 additions and 8 deletions

View File

@ -29,6 +29,7 @@ typedef struct CNCDDRAWCONFIG
BOOL windowed;
BOOL maintas;
BOOL boxing;
char aspect_ratio[16];
int maxfps;
BOOL vsync;
BOOL adjmouse;

View File

@ -39,6 +39,7 @@ void cfg_load()
GET_BOOL(g_config.windowed, "windowed", FALSE);
GET_BOOL(g_config.maintas, "maintas", FALSE);
GET_BOOL(g_config.boxing, "boxing", FALSE);
GET_STRING("aspect_ratio", "", g_config.aspect_ratio, sizeof(g_config.aspect_ratio));
GET_INT(g_config.maxfps, "maxfps", -1);
GET_BOOL(g_config.vsync, "vsync", FALSE);
GET_BOOL(g_config.adjmouse, "adjmouse", TRUE);
@ -120,6 +121,9 @@ void cfg_load()
if (g_config.lock_mouse_top_left)
g_config.adjmouse = FALSE;
if (g_config.aspect_ratio[0])
g_config.maintas = TRUE;
ini_free(&g_config.ini);
}

View File

@ -581,6 +581,8 @@ HRESULT dd_SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwFl
if (!dwHeight)
dwHeight = g_ddraw.height ? g_ddraw.height : 600;
//if (dwHeight == 400) dwHeight = 480;
if (!dwBPP)
dwBPP = g_ddraw.bpp ? g_ddraw.bpp : 16;
@ -859,8 +861,22 @@ HRESULT dd_SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwFl
}
else if (g_config.maintas)
{
double dst_ar = (double)g_ddraw.height / g_ddraw.width;
double src_ar = (double)g_ddraw.render.height / g_ddraw.render.width;
double dst_ar;
double src_ar = (double)g_ddraw.render.height / g_ddraw.render.width;;
if (g_config.aspect_ratio[0])
{
char* e = &g_config.aspect_ratio[0];
DWORD cx = strtoul(e, &e, 0);
DWORD cy = strtoul(e + 1, &e, 0);
dst_ar = (double)cy / cx;
}
else
{
dst_ar = (double)g_ddraw.height / g_ddraw.width;
}
g_ddraw.render.viewport.width = g_ddraw.render.width;
g_ddraw.render.viewport.height = (int)round(dst_ar * g_ddraw.render.viewport.width);

View File

@ -622,9 +622,23 @@ void util_toggle_maximize()
int w = dst_rc.right - dst_rc.left;
int h = dst_rc.bottom - dst_rc.top;
double dst_ar = (double)g_ddraw.height / g_ddraw.width;
double dst_ar;
double src_ar = (double)h / w;
if (g_config.aspect_ratio[0])
{
char* e = &g_config.aspect_ratio[0];
DWORD cx = strtoul(e, &e, 0);
DWORD cy = strtoul(e + 1, &e, 0);
dst_ar = (double)cy / cx;
}
else
{
dst_ar = (double)g_ddraw.height / g_ddraw.width;
}
dst_rc.top = 0;
dst_rc.left = 0;
dst_rc.right = w;

View File

@ -317,8 +317,24 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
real_GetWindowLongA(hWnd, GWL_EXSTYLE)) &&
SetRect(&clientrc, 0, 0, clientrc.right - clientrc.left, clientrc.bottom - clientrc.top))
{
double scaleH = (double)g_ddraw.height / g_ddraw.width;
double scaleW = (double)g_ddraw.width / g_ddraw.height;
double scale_h;
double scale_w;
if (g_config.aspect_ratio[0])
{
char* e = &g_config.aspect_ratio[0];
DWORD cx = strtoul(e, &e, 0);
DWORD cy = strtoul(e + 1, &e, 0);
scale_h = (double)cy / cx;
scale_w = (double)cx / cy;
}
else
{
scale_h = (double)g_ddraw.height / g_ddraw.width;
scale_w = (double)g_ddraw.width / g_ddraw.height;
}
switch (wParam)
{
@ -327,19 +343,19 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
case WMSZ_LEFT:
case WMSZ_RIGHT:
{
windowrc->bottom += (LONG)round(scaleH * clientrc.right - clientrc.bottom);
windowrc->bottom += (LONG)round(scale_h * clientrc.right - clientrc.bottom);
break;
}
case WMSZ_TOP:
case WMSZ_BOTTOM:
{
windowrc->right += (LONG)round(scaleW * clientrc.bottom - clientrc.right);
windowrc->right += (LONG)round(scale_w * clientrc.bottom - clientrc.right);
break;
}
case WMSZ_TOPRIGHT:
case WMSZ_TOPLEFT:
{
windowrc->top -= (LONG)round(scaleH * clientrc.right - clientrc.bottom);
windowrc->top -= (LONG)round(scale_h * clientrc.right - clientrc.bottom);
break;
}
}