From 5ad5e16a405ab438211879299f3e78ee01453e82 Mon Sep 17 00:00:00 2001 From: retr0s4ge Date: Mon, 9 Jul 2018 01:03:35 +0200 Subject: [PATCH] (Windows Frontend) Allow screen resizing in horizontal display layout. The right hand screen is allowed to be resized in horizontal screen layout to enable the window or full screen display to better utilize the screen area. Changes: 1- Modify scaling, resizing and update functions to allow for new screen resizing ratio 2- Modify touch input scaling (incl. HUD editing) to adapt to different screen sizes 3- Add GUI menu for user to select the screen resizing ratio 4- Implement saving/loading settings from file similar to other settings --- desmume/src/frontend/windows/main.cpp | 98 +++++++++++++++++++---- desmume/src/frontend/windows/resource.h | 8 +- desmume/src/frontend/windows/resources.rc | 9 +++ 3 files changed, 100 insertions(+), 15 deletions(-) diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index db548f378..daa3f31a3 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -519,6 +519,8 @@ bool continuousframeAdvancing = false; unsigned short windowSize = 0; +float screenSizeRatio = 1.0f; + /*const u32 gapColors[16] = { Color::Gray, Color::Brown, @@ -714,7 +716,10 @@ void ScaleScreen(float factor, bool user) MainWindow->setClientSize((int)(video.rotatedwidthgap() * factor), (int)(video.rotatedheightgap() * factor)); else if (video.layout == 1) - MainWindow->setClientSize((int)(video.rotatedwidthgap() * factor * 2), (int)(video.rotatedheightgap() * factor / 2)); + { + factor /= screenSizeRatio; + MainWindow->setClientSize((int)(video.rotatedwidthgap() * factor * 2), (int)(video.rotatedheightgap() * factor * screenSizeRatio / 2)); + } else if (video.layout == 2) MainWindow->setClientSize((int)(video.rotatedwidthgap() * factor), (int)(video.rotatedheightgap() * factor / 2)); @@ -868,22 +873,50 @@ void ToDSScreenRelativeCoords(s32& x, s32& y, int whichScreen) { bool topOnTop = (video.swap == 0) || (video.swap == 2 && isMainGPUFirst) || (video.swap == 3 && !isMainGPUFirst); bool bottom = (whichScreen > 0); - if(topOnTop) - x += bottom ? -GPU_FRAMEBUFFER_NATIVE_WIDTH : 0; + if (topOnTop) + { + if (bottom) + { + x += -GPU_FRAMEBUFFER_NATIVE_WIDTH * screenSizeRatio; + x /= (2 - screenSizeRatio); + y /= (2 - screenSizeRatio); + } + } else - x += (x < GPU_FRAMEBUFFER_NATIVE_WIDTH) ? (bottom ? 0 : GPU_FRAMEBUFFER_NATIVE_WIDTH) : (bottom ? 0 : -GPU_FRAMEBUFFER_NATIVE_WIDTH); + { + if (x < GPU_FRAMEBUFFER_NATIVE_WIDTH * screenSizeRatio) + { + if (bottom == 0) + x += GPU_FRAMEBUFFER_NATIVE_WIDTH * screenSizeRatio; + } + else + { + if (bottom == 0) + x += -GPU_FRAMEBUFFER_NATIVE_WIDTH * screenSizeRatio; + } + x /= screenSizeRatio; + } } else { + x /= screenSizeRatio; if(x >= GPU_FRAMEBUFFER_NATIVE_WIDTH) { x -= GPU_FRAMEBUFFER_NATIVE_WIDTH; - y += GPU_FRAMEBUFFER_NATIVE_HEIGHT; + x *= screenSizeRatio / (2 - screenSizeRatio); + y += GPU_FRAMEBUFFER_NATIVE_HEIGHT * (2 - screenSizeRatio); + y /= (2 - screenSizeRatio); + if (y < GPU_FRAMEBUFFER_NATIVE_HEIGHT) + y = GPU_FRAMEBUFFER_NATIVE_HEIGHT; } else if(x < 0) { - x += GPU_FRAMEBUFFER_NATIVE_WIDTH; - y -= GPU_FRAMEBUFFER_NATIVE_HEIGHT; + x = 0; + } + else + { + if (y > GPU_FRAMEBUFFER_NATIVE_HEIGHT) + y = GPU_FRAMEBUFFER_NATIVE_HEIGHT; } } } @@ -1161,8 +1194,8 @@ void UpdateWndRects(HWND hwnd) if (video.layout == 1) //horizontal { - rc = CalculateDisplayLayoutWrapper(rc, GPU_FRAMEBUFFER_NATIVE_WIDTH * 2, GPU_FRAMEBUFFER_NATIVE_HEIGHT, tbheight, maximized); - + rc = CalculateDisplayLayoutWrapper(rc, GPU_FRAMEBUFFER_NATIVE_WIDTH * 2, (int)((float)(GPU_FRAMEBUFFER_NATIVE_HEIGHT * screenSizeRatio)), tbheight, maximized); + wndWidth = (rc.bottom - rc.top) - tbheight; wndHeight = (rc.right - rc.left); @@ -1176,20 +1209,20 @@ void UpdateWndRects(HWND hwnd) ClientToScreen(hwnd, &ptClient); MainScreenRect.left = ptClient.x; MainScreenRect.top = ptClient.y; - ptClient.x = (rc.left + oneScreenHeight); + ptClient.x = (rc.left + oneScreenHeight * screenSizeRatio); ptClient.y = (rc.top + wndWidth); ClientToScreen(hwnd, &ptClient); MainScreenRect.right = ptClient.x; MainScreenRect.bottom = ptClient.y; // Sub screen - ptClient.x = (rc.left + oneScreenHeight); + ptClient.x = (rc.left + oneScreenHeight * screenSizeRatio); ptClient.y = rc.top; ClientToScreen(hwnd, &ptClient); SubScreenRect.left = ptClient.x; SubScreenRect.top = ptClient.y; - ptClient.x = (rc.left + oneScreenHeight + oneScreenHeight); - ptClient.y = (rc.top + wndWidth); + ptClient.x = (rc.left + oneScreenHeight * 2); + ptClient.y = (rc.top + wndWidth * (2 - screenSizeRatio)); ClientToScreen(hwnd, &ptClient); SubScreenRect.right = ptClient.x; SubScreenRect.bottom = ptClient.y; @@ -3008,6 +3041,7 @@ int _main() msgbox = &msgBoxWnd; char text[80] = {0}; + char scrRatStr[4] = "1.0"; path.ReadPathSettings(); @@ -3071,6 +3105,8 @@ int _main() GetPrivateProfileString("MicSettings", "MicSampleFile", "micsample.raw", MicSampleName, MAX_PATH, IniName); RefreshMicSettings(); + GetPrivateProfileString("Display", "Screen Size Ratio", "1.0", scrRatStr, 4, IniName); + screenSizeRatio = atof(scrRatStr); video.screengap = GetPrivateProfileInt("Display", "ScreenGap", 0, IniName); SeparationBorderDrag = GetPrivateProfileBool("Display", "Window Split Border Drag", true, IniName); ScreenGapColor = GetPrivateProfileInt("Display", "ScreenGapColor", 0xFFFFFF, IniName); @@ -4629,6 +4665,20 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM MainWindow->checkMenu(IDM_ALWAYS_ON_TOP, (GetStyle()&DWS_ALWAYSONTOP)!=0); MainWindow->checkMenu(IDM_LOCKDOWN, (GetStyle()&DWS_LOCKDOWN)!=0); + //Screen Size Ratio + MainWindow->checkMenu(IDC_SCR_RATIO_1p0, ((int)(screenSizeRatio*10)==10)); + MainWindow->checkMenu(IDC_SCR_RATIO_1p1, ((int)(screenSizeRatio*10)==11)); + MainWindow->checkMenu(IDC_SCR_RATIO_1p2, ((int)(screenSizeRatio*10)==12)); + MainWindow->checkMenu(IDC_SCR_RATIO_1p3, ((int)(screenSizeRatio*10)==13)); + MainWindow->checkMenu(IDC_SCR_RATIO_1p4, ((int)(screenSizeRatio*10)==14)); + MainWindow->checkMenu(IDC_SCR_RATIO_1p5, ((int)(screenSizeRatio*10)==15)); + DesEnableMenuItem(mainMenu, IDC_SCR_RATIO_1p0, (video.layout == 1)); + DesEnableMenuItem(mainMenu, IDC_SCR_RATIO_1p1, (video.layout == 1)); + DesEnableMenuItem(mainMenu, IDC_SCR_RATIO_1p2, (video.layout == 1)); + DesEnableMenuItem(mainMenu, IDC_SCR_RATIO_1p3, (video.layout == 1)); + DesEnableMenuItem(mainMenu, IDC_SCR_RATIO_1p4, (video.layout == 1)); + DesEnableMenuItem(mainMenu, IDC_SCR_RATIO_1p5, (video.layout == 1)); + //Screen Separation MainWindow->checkMenu(IDM_SCREENSEP_NONE, ((video.screengap==kGapNone))); MainWindow->checkMenu(IDM_SCREENSEP_BORDER, ((video.screengap==kGapBorder))); @@ -4920,7 +4970,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM else if (video.layout == 1) { minX = video.rotatedwidthgap() * 2; - minY = video.rotatedheightgap() / 2; + minY = video.rotatedheightgap() * screenSizeRatio / 2; } else if (video.layout == 2) { @@ -6278,6 +6328,26 @@ DOKEYDOWN: WritePrivateProfileInt("Video","Window Size",windowSize,IniName); break; + case IDC_SCR_RATIO_1p0: + case IDC_SCR_RATIO_1p1: + case IDC_SCR_RATIO_1p2: + case IDC_SCR_RATIO_1p3: + case IDC_SCR_RATIO_1p4: + case IDC_SCR_RATIO_1p5: + { + screenSizeRatio = LOWORD(wParam) - IDC_SCR_RATIO_1p0; + screenSizeRatio = screenSizeRatio * 0.1 + 1; + + RECT rc; + GetClientRect(hwnd, &rc); + MainWindow->setClientSize((int)((rc.right - rc.left + 8) / screenSizeRatio), rc.bottom - rc.top); + + char scrRatStr[4] = "1.0"; + sprintf(scrRatStr, "%.1f", screenSizeRatio); + WritePrivateProfileString("Display", "Screen Size Ratio", scrRatStr, IniName); + } + return 0; + case IDC_VIEW_PADTOINTEGER: PadToInteger = (!PadToInteger)?TRUE:FALSE; WritePrivateProfileInt("Video","Window Pad To Integer",PadToInteger,IniName); diff --git a/desmume/src/frontend/windows/resource.h b/desmume/src/frontend/windows/resource.h index 46de3140a..b2bc38c69 100644 --- a/desmume/src/frontend/windows/resource.h +++ b/desmume/src/frontend/windows/resource.h @@ -958,6 +958,12 @@ #define IDM_RENDER_3XBRZ 40123 #define IDM_RENDER_4XBRZ 40124 #define IDM_RENDER_5XBRZ 40125 +#define IDC_SCR_RATIO_1p0 40143 +#define IDC_SCR_RATIO_1p1 40144 +#define IDC_SCR_RATIO_1p2 40145 +#define IDC_SCR_RATIO_1p3 40146 +#define IDC_SCR_RATIO_1p4 40147 +#define IDC_SCR_RATIO_1p5 40148 #define ID_LABEL_HK3b 44670 #define ID_LABEL_HK3c 44671 #define ID_LABEL_HK3d 44672 @@ -1072,7 +1078,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 128 -#define _APS_NEXT_COMMAND_VALUE 40126 +#define _APS_NEXT_COMMAND_VALUE 40149 #define _APS_NEXT_CONTROL_VALUE 1065 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/desmume/src/frontend/windows/resources.rc b/desmume/src/frontend/windows/resources.rc index e2c99e650..455172ed0 100644 --- a/desmume/src/frontend/windows/resources.rc +++ b/desmume/src/frontend/windows/resources.rc @@ -1609,6 +1609,15 @@ BEGIN MENUITEM "&Always On Top", IDM_ALWAYS_ON_TOP MENUITEM "&Lockdown", IDM_LOCKDOWN END + POPUP "Screen Size Ratio (L:R)" + BEGIN + MENUITEM "1.0 : 1.0", IDC_SCR_RATIO_1p0 + MENUITEM "1.1 : 0.9", IDC_SCR_RATIO_1p1 + MENUITEM "1.2 : 0.8", IDC_SCR_RATIO_1p2 + MENUITEM "1.3 : 0.7", IDC_SCR_RATIO_1p3 + MENUITEM "1.4 : 0.6", IDC_SCR_RATIO_1p4 + MENUITEM "1.5 : 0.5", IDC_SCR_RATIO_1p5 + END POPUP "Screen &Gap" BEGIN MENUITEM "&None\t(0 px)", IDM_SCREENSEP_NONE