From bf83f0f605ade9addf8368f5d82272acd6e043c0 Mon Sep 17 00:00:00 2001 From: OV2 Date: Thu, 9 May 2024 14:59:31 +0200 Subject: [PATCH] win32: add hotkey to switch aspect ratio (#912) --- win32/wconfig.cpp | 1 + win32/wlanguage.h | 2 ++ win32/wsnes9x.cpp | 43 ++++++++++++++++++++++++++++++++++++------- win32/wsnes9x.h | 4 ++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/win32/wconfig.cpp b/win32/wconfig.cpp index e1977f04..319e1b6f 100644 --- a/win32/wconfig.cpp +++ b/win32/wconfig.cpp @@ -939,6 +939,7 @@ void WinRegisterConfigItems() ADD(SaveFileSelect); ADD(LoadFileSelect); ADD(Mute); ADD(ToggleBackdrop); + ADD(AspectRatio); #undef ADD #undef ADDN #undef CATEGORY diff --git a/win32/wlanguage.h b/win32/wlanguage.h index c74a64d8..46e819aa 100644 --- a/win32/wlanguage.h +++ b/win32/wlanguage.h @@ -136,6 +136,8 @@ Nintendo is a trademark.") #define HOTKEYS_LABEL_4_11 TEXT("Save to file:") #define HOTKEYS_LABEL_4_12 TEXT("Load from file:") +#define HOTKEYS_SWITCH_ASPECT_RATIO TEXT("Switch aspect Ratio:") + // gaming buttons and axes #define GAMEDEVICE_JOYNUMPREFIX "(J%x)" // don't change this #define GAMEDEVICE_JOYBUTPREFIX "#[%d]" // don't change this diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index a4c2cb94..df18000c 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -125,7 +125,8 @@ void S9xWinScanJoypads(); #define TIMER_SCANJOYPADS (99999) #define NC_SEARCHDB 0x8000 -#define MAX_SWITCHABLE_HOTKEY_DIALOG_ITEMS 14 +constexpr int MAX_SWITCHABLE_HOTKEY_DIALOG_ITEMS = 14; +constexpr int MAX_SWITCHABLE_HOTKEY_DIALOG_PAGES = 5; #ifdef UNICODE #define S9XW_SHARD_PATH SHARD_PATHW @@ -1222,6 +1223,18 @@ int HandleKeyMessage(WPARAM wParam, LPARAM lParam) FreezeUnfreezeDialog(FALSE); hitHotKey = true; } + if (wParam == CustomKeys.AspectRatio.key + && modifiers == CustomKeys.AspectRatio.modifiers) + { + if (GUI.AspectWidth == ASPECT_WIDTH_4_3) + { + GUI.AspectWidth = ASPECT_WIDTH_8_7; + } + else + { + GUI.AspectWidth = ASPECT_WIDTH_4_3; + } + } if (wParam == CustomKeys.Mute.key && modifiers == CustomKeys.Mute.modifiers) @@ -7562,10 +7575,10 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) SendDlgItemMessage(hDlg, IDC_ASPECTDROP, CB_ADDSTRING, 0, (LPARAM)TEXT("8:7")); SendDlgItemMessage(hDlg, IDC_ASPECTDROP, CB_ADDSTRING, 0, (LPARAM)TEXT("4:3")); switch (GUI.AspectWidth) { - case 256: + case ASPECT_WIDTH_4_3: SendDlgItemMessage(hDlg, IDC_ASPECTDROP, CB_SETCURSEL, (WPARAM)0, 0); break; - case 299: + case ASPECT_WIDTH_8_7: SendDlgItemMessage(hDlg, IDC_ASPECTDROP, CB_SETCURSEL, (WPARAM)1, 0); break; default: @@ -7731,10 +7744,10 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) int newsel = SendDlgItemMessage(hDlg,IDC_ASPECTDROP,CB_GETCURSEL,0,0); switch(newsel) { case 0: - GUI.AspectWidth = 256; + GUI.AspectWidth = ASPECT_WIDTH_4_3; break; case 1: - GUI.AspectWidth = 299; + GUI.AspectWidth = ASPECT_WIDTH_8_7; break; default: GUI.AspectWidth = prevAspectWidth; @@ -8301,7 +8314,7 @@ struct hotkey_dialog_item { // this structure defines the four sub pages in the hotkey config dialog // to keep an entry blank, set the SCustomKey pointer to NULL and the text to an empty string -static hotkey_dialog_item hotkey_dialog_items[4][MAX_SWITCHABLE_HOTKEY_DIALOG_ITEMS] = { +static hotkey_dialog_item hotkey_dialog_items[MAX_SWITCHABLE_HOTKEY_DIALOG_PAGES][MAX_SWITCHABLE_HOTKEY_DIALOG_ITEMS] = { { { &CustomKeys.SpeedUp, HOTKEYS_LABEL_1_1 }, { &CustomKeys.SpeedDown, HOTKEYS_LABEL_1_2 }, @@ -8366,6 +8379,22 @@ static hotkey_dialog_item hotkey_dialog_items[4][MAX_SWITCHABLE_HOTKEY_DIALOG_IT { NULL, _T("") }, { NULL, _T("") }, }, + { + { &CustomKeys.AspectRatio, HOTKEYS_SWITCH_ASPECT_RATIO }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + { NULL, _T("") }, + }, }; static void set_hotkeyinfo(HWND hDlg) @@ -8434,7 +8463,7 @@ switch(msg) SetWindowText(hDlg,HOTKEYS_TITLE); // insert hotkey page list items - for(i=1 ; i <= 4 ; i++) + for(i=1 ; i <= MAX_SWITCHABLE_HOTKEY_DIALOG_PAGES; i++) { TCHAR temp[256]; _stprintf(temp,HOTKEYS_HKCOMBO,i); diff --git a/win32/wsnes9x.h b/win32/wsnes9x.h index 2995fd16..2084ddae 100644 --- a/win32/wsnes9x.h +++ b/win32/wsnes9x.h @@ -39,6 +39,9 @@ #define NUM_SAVE_BANKS 10 #define LAST_SAVE_BANK (NUM_SAVE_BANKS - 1) +constexpr int ASPECT_WIDTH_4_3 = 256; +constexpr int ASPECT_WIDTH_8_7 = 299; + #include "_tfwopen.h" #ifdef UNICODE #define _tToChar WideToUtf8 @@ -348,6 +351,7 @@ struct SCustomKeys { SCustomKey SaveFileSelect; SCustomKey LoadFileSelect; SCustomKey Mute; + SCustomKey AspectRatio; }; struct SJoypad {