Skip to content

Commit

Permalink
Add custom resolution support
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfirex86 committed Jul 27, 2021
1 parent 72bffed commit e5d4fca
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 14 deletions.
5 changes: 5 additions & 0 deletions R2FixCfg/Resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ BEGIN
CONTROL "Enable Ray2Fix",IDC_MAINTOGGLE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,14,56,65,10
GROUPBOX "Resolution / Window Size",IDC_STATIC,6,78,126,46
COMBOBOX IDC_RESOLUTION,14,90,110,74,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
EDITTEXT IDC_RESX,14,90,46,12,ES_AUTOHSCROLL | ES_NUMBER | NOT WS_VISIBLE
CTEXT "x",IDC_RES_LABEL,60,92,18,8,NOT WS_VISIBLE
EDITTEXT IDC_RESY,78,90,46,12,ES_AUTOHSCROLL | ES_NUMBER | NOT WS_VISIBLE
RADIOBUTTON "Windowed*",IDC_FSMODE_WND,14,107,53,10,WS_GROUP
RADIOBUTTON "Fullscreen",IDC_FSMODE_FS,74,107,48,10
GROUPBOX "Advanced",IDC_ADVGROUP,136,78,112,72,NOT WS_VISIBLE
Expand Down Expand Up @@ -186,6 +189,8 @@ BEGIN
LEFTMARGIN, 6
RIGHTMARGIN, 248
VERTGUIDE, 14
VERTGUIDE, 60
VERTGUIDE, 78
VERTGUIDE, 124
VERTGUIDE, 132
VERTGUIDE, 136
Expand Down
18 changes: 14 additions & 4 deletions R2FixCfg/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ BOOL IsDuplicateMode( DISP_MODE *lpMode, int nModes )
DISP_MODE *prevMode = &g_aDispModes[i];

if ( lpMode->dwWidth == prevMode->dwWidth && lpMode->dwHeight == prevMode->dwHeight )
{
return TRUE;
}
}

return FALSE;
}

void AddCustomModeIfSet( int nModes )
{
if ( g_dmCurrentMode.dwWidth <= 0 || g_dmCurrentMode.dwHeight <= 0 ||
IsDuplicateMode(&g_dmCurrentMode, nModes) )
return;

g_dmCurrentMode.dmfFlags |= DMF_CUSTOM;
g_aDispModes[nModes] = g_dmCurrentMode;
}

void FindBestResolution( int nModes )
{
RECT rcWorkArea = { 0 };
Expand Down Expand Up @@ -69,6 +77,9 @@ void EnumResolutions( void )
DMF_NONE
};

if ( mode.dwWidth <= 0 || mode.dwHeight <= 0 )
continue;

if ( IsDuplicateMode(&mode, nModes) )
continue;

Expand All @@ -78,13 +89,12 @@ void EnumResolutions( void )
if ( ratio > 73 && ratio < 82 )
{
if ( IsSafeResolution(&mode) )
{
mode.dmfFlags |= DMF_SAFE;
}

g_aDispModes[nModes++] = mode;
}
}

FindBestResolution(nModes);
AddCustomModeIfSet(nModes);
}
3 changes: 2 additions & 1 deletion R2FixCfg/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ typedef enum tagDM_FLAGS
{
DMF_NONE = 0,
DMF_SAFE = 1 << 0,
DMF_BEST = 1 << 1
DMF_BEST = 1 << 1,
DMF_CUSTOM = 1 << 2
} DM_FLAGS;

typedef enum tagREFRATE
Expand Down
99 changes: 91 additions & 8 deletions R2FixCfg/generaldlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ HWND hThis;
HWND hStatus;
HWND hToggle;
HWND hResolution;

HWND hResX;
HWND hResY;
HWND hResLabel;

HWND hFsModeWin;
HWND hFsModeFs;

Expand All @@ -18,10 +23,20 @@ HWND hVsync;
HWND hRefRateLabel;
HWND hRefRate;

void SetDisplayMode( HWND hCB )
int lCbCustomIdx;
DISP_MODE dmLastMode;

DISP_MODE * GetSelectedDisplayMode( HWND hCB )
{
int idx = ComboBox_GetCurSel(hCB);
DISP_MODE *lpMode = (DISP_MODE*)ComboBox_GetItemData(hCB, idx);

return lpMode;
}

void SetDisplayMode( HWND hCB )
{
DISP_MODE *lpMode = GetSelectedDisplayMode(hCB);

if ( lpMode != NULL )
{
Expand All @@ -30,6 +45,27 @@ void SetDisplayMode( HWND hCB )
}
}

BOOL SetCustomDisplayMode( void )
{
char szBuffer[8];

Edit_GetText(hResX, szBuffer, sizeof(szBuffer) - 1);
DWORD dwWidth = strtol(szBuffer, NULL, 10);
Edit_GetText(hResY, szBuffer, sizeof(szBuffer) - 1);
DWORD dwHeight = strtol(szBuffer, NULL, 10);

if ( dwWidth > 0 && dwHeight > 0 )
{
g_dmCurrentMode.dwWidth = dwWidth;
g_dmCurrentMode.dwHeight = dwHeight;

return TRUE;
}

g_dmCurrentMode = dmLastMode;
return FALSE;
}

void UpdateStatus( HWND hEdit, HWND hButton )
{
char szStatusLine[512];
Expand Down Expand Up @@ -70,13 +106,30 @@ void UpdateStatus( HWND hEdit, HWND hButton )

if ( g_veMissingFiles & VE_GAME_ERROR )
nChars += LoadStringAtChar(IDS_VE_REINSTALLR2, szStatusLine, nChars);

}

Edit_SetText(hEdit, szStatusLine);
Button_SetCheck(hButton, g_bFixState);
}

void ShowCustomRes( void )
{
char szBuffer[8];

sprintf_s(szBuffer, sizeof(szBuffer), "%d", g_dmCurrentMode.dwWidth);
Edit_SetText(hResX, szBuffer);
sprintf_s(szBuffer, sizeof(szBuffer), "%d", g_dmCurrentMode.dwHeight);
Edit_SetText(hResY, szBuffer);

dmLastMode = g_dmCurrentMode;

ShowWindow(hResolution, SW_HIDE);
ShowWindow(hResX, SW_SHOW);
ShowWindow(hResY, SW_SHOW);
ShowWindow(hResLabel, SW_SHOW);
SetFocus(hResX);
}

void ToggleAdvanced( BOOL bVisible )
{
int nCmdShow = bVisible ? SW_SHOW : SW_HIDE;
Expand All @@ -94,27 +147,30 @@ void PopulateDisplayModes( HWND hCB )
for ( int i = 0; i < MAX_MODES; i++ )
{
DISP_MODE *lpMode = &g_aDispModes[i];
char szItemText[60];

if ( lpMode->dwWidth == 0 )
break;

char szItemText[60];
sprintf_s(szItemText, sizeof(szItemText), "%d x %d ", lpMode->dwWidth, lpMode->dwHeight);
sprintf_s(szItemText, sizeof(szItemText), "%d x %d", lpMode->dwWidth, lpMode->dwHeight);

if ( lpMode->dmfFlags & DMF_SAFE )
strcat_s(szItemText, sizeof(szItemText), "*");
strcat_s(szItemText, sizeof(szItemText), " *");

if ( lpMode->dmfFlags & DMF_BEST )
strcat_s(szItemText, sizeof(szItemText), "+");
strcat_s(szItemText, sizeof(szItemText), " +");

if ( lpMode->dmfFlags & DMF_CUSTOM )
strcat_s(szItemText, sizeof(szItemText), " (custom)");

int idx = ComboBox_AddString(hCB, szItemText);
ComboBox_SetItemData(hCB, idx, lpMode);

if ( lpMode->dmfFlags )
ComboBox_SetCurSel(hCB, idx);

if ( lpMode->dwWidth == g_dmCurrentMode.dwWidth
&& lpMode->dwHeight == g_dmCurrentMode.dwHeight )
if ( lpMode->dwWidth == g_dmCurrentMode.dwWidth &&
lpMode->dwHeight == g_dmCurrentMode.dwHeight )
{
idxSelected = idx;
}
Expand All @@ -124,6 +180,9 @@ void PopulateDisplayModes( HWND hCB )
ComboBox_SetCurSel(hCB, idxSelected);

SetDisplayMode(hResolution);

// Add special "Custom..." item at the end of the combo box
lCbCustomIdx = ComboBox_AddString(hCB, "Custom...");
}

void PopulateRefRates( HWND hCB )
Expand Down Expand Up @@ -158,6 +217,10 @@ BOOL CALLBACK GeneralDialogProc(
hStatus = GetDlgItem(hWnd, IDC_STATUSLINE);
hToggle = GetDlgItem(hWnd, IDC_MAINTOGGLE);
hResolution = GetDlgItem(hWnd, IDC_RESOLUTION);
hResX = GetDlgItem(hWnd, IDC_RESX);
hResY = GetDlgItem(hWnd, IDC_RESY);
hResLabel = GetDlgItem(hWnd, IDC_RES_LABEL);

hFsModeWin = GetDlgItem(hWnd, IDC_FSMODE_WND);
hFsModeFs = GetDlgItem(hWnd, IDC_FSMODE_FS);

Expand All @@ -174,6 +237,9 @@ BOOL CALLBACK GeneralDialogProc(
Button_SetCheck(hFsModeWin, !g_bFullscreen);
Button_SetCheck(hFsModeFs, g_bFullscreen);

SendMessage(hResX, EM_LIMITTEXT, 7, 0);
SendMessage(hResY, EM_LIMITTEXT, 7, 0);

break;

case WM_ADVTOGGLE:
Expand All @@ -193,12 +259,29 @@ BOOL CALLBACK GeneralDialogProc(
case IDC_RESOLUTION:
if ( HIWORD(wParam) == CBN_SELCHANGE )
{
if ( ComboBox_GetCurSel(hResolution) == lCbCustomIdx )
{
ShowCustomRes();
break;
}

SetDisplayMode(hResolution);
g_bUnsavedChanges = TRUE;
break;
}
return FALSE;

case IDC_RESX:
case IDC_RESY:
if ( HIWORD(wParam) == EN_KILLFOCUS )
{
if ( SetCustomDisplayMode() )
g_bUnsavedChanges = TRUE;

break;
}
return FALSE;

case IDC_FSMODE_WND:
g_bFullscreen = FALSE;
Button_SetCheck(hFsModeWin, BST_CHECKED);
Expand Down
1 change: 1 addition & 0 deletions R2FixCfg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ BOOL CALLBACK MainDialogProc(
break;

case IDOK:
SetFocus(NULL);
WriteConfig();
g_bUnsavedChanges = FALSE;
// fall-through
Expand Down
5 changes: 4 additions & 1 deletion R2FixCfg/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#define IDC_MODLOADER 1025
#define IDC_SHOWPOS 1026
#define IDC_LUMCONTROL 1027
#define IDC_RESX 1029
#define IDC_RESY 1030
#define IDC_RES_LABEL 1031
#define ID_DEBUG 40001

// Next default values for new objects
Expand All @@ -50,7 +53,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 111
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1029
#define _APS_NEXT_CONTROL_VALUE 1032
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

0 comments on commit e5d4fca

Please sign in to comment.