From e9856334ea74b2c344fc11943fca1c75e8a5cae7 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 20 Feb 2021 18:18:02 +0200 Subject: [PATCH] Statusline DPI fix --- include/statusline.h | 2 +- od-win32/dxwrap.h | 1 + od-win32/statusline_win32.cpp | 8 +++--- od-win32/win32.cpp | 25 ++++++++++++------ od-win32/win32.h | 3 +++ od-win32/win32gfx.cpp | 49 +++++++++++++++++++++++++---------- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/include/statusline.h b/include/statusline.h index 355a2b94..61ca1636 100644 --- a/include/statusline.h +++ b/include/statusline.h @@ -43,7 +43,7 @@ bool softstatusline(void); #define STATUSTYPE_CD 4 #define STATUSTYPE_OTHER 5 -bool createstatusline(int); +bool createstatusline(HWND, int); void deletestatusline(int); void statusline_render(int, uae_u8 *buf, int bpp, int pitch, int width, int height, uae_u32 *rc, uae_u32 *gc, uae_u32 *bc, uae_u32 *alpha); void statusline_add_message(int statustype, const TCHAR *format, ...); diff --git a/od-win32/dxwrap.h b/od-win32/dxwrap.h index d31dcbac..8099168b 100644 --- a/od-win32/dxwrap.h +++ b/od-win32/dxwrap.h @@ -120,6 +120,7 @@ struct AmigaMonitor { int ratio_adjust_x, ratio_adjust_y; bool ratio_sizing; bool render_ok, wait_render; + int dpi; int in_sizemove; int manual_painting_needed; diff --git a/od-win32/statusline_win32.cpp b/od-win32/statusline_win32.cpp index 8d7e4238..96bf193a 100644 --- a/od-win32/statusline_win32.cpp +++ b/od-win32/statusline_win32.cpp @@ -52,7 +52,7 @@ void deletestatusline(int monid) statusline_palette = NULL; } -static void create_led_font(int monid) +static void create_led_font(HWND parent, int monid) { HDC hdc; LPLOGPALETTE lp; @@ -70,7 +70,7 @@ static void create_led_font(int monid) hdc = CreateCompatibleDC(NULL); if (hdc) { - int y = GetDeviceCaps(hdc, LOGPIXELSY); + int y = getdpiforwindow(parent); int fontsize = -MulDiv(6, y, 72); fontsize = fontsize * statusline_get_multiplier(monid) / 100; lp = (LOGPALETTE *)xcalloc(uae_u8, sizeof(LOGPALETTE) + 3 * sizeof(PALETTEENTRY)); @@ -186,7 +186,7 @@ static void create_led_font(int monid) } } -bool createstatusline(int monid) +bool createstatusline(HWND parentHwnd, int monid) { struct AmigaMonitor *mon = &AMonitors[monid]; BITMAPINFO *bi; @@ -235,7 +235,7 @@ bool createstatusline(int monid) SelectObject(statusline_hdc, statusline_bitmap); RealizePalette(statusline_hdc); - create_led_font(monid); + create_led_font(parentHwnd, monid); statusline_font = CreateFont(-10, 0, 0, 0, diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 8639a519..8ee17118 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -236,6 +236,12 @@ static GETTOUCHINPUTINFO pGetTouchInputInfo; static CLOSETOUCHINPUTHANDLE pCloseTouchInputHandle; #endif +ADJUSTWINDOWRECTEXFORDPI pAdjustWindowRectExForDpi; +typedef HRESULT(CALLBACK* GETDPIFORMONITOR)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); +static GETDPIFORMONITOR pGetDpiForMonitor; +typedef UINT(CALLBACK* GETDPIFORWINDOW)(HWND); +static GETDPIFORWINDOW pGetDpiForWindow; + int getdpiformonitor(HMONITOR mon) { if (mon) { @@ -243,8 +249,9 @@ int getdpiformonitor(HMONITOR mon) if (!shcore) shcore = LoadLibrary(_T("Shcore.dll")); if (shcore) { - typedef HRESULT(CALLBACK *GETDPIFORMONITOR)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *); - GETDPIFORMONITOR pGetDpiForMonitor = (GETDPIFORMONITOR)GetProcAddress(shcore, "GetDpiForMonitor"); + if (!pGetDpiForMonitor) { + pGetDpiForMonitor = (GETDPIFORMONITOR)GetProcAddress(shcore, "GetDpiForMonitor"); + } if (pGetDpiForMonitor) { UINT x, y; if (SUCCEEDED(pGetDpiForMonitor(mon, MDT_EFFECTIVE_DPI, &x, &y))) @@ -260,8 +267,9 @@ int getdpiformonitor(HMONITOR mon) int getdpiforwindow(HWND hwnd) { - typedef UINT(CALLBACK *GETDPIFORWINDOW)(HWND); - GETDPIFORWINDOW pGetDpiForWindow = (GETDPIFORWINDOW)GetProcAddress(userdll, "GetDpiForWindow"); + if (!pGetDpiForWindow) { + pGetDpiForWindow = (GETDPIFORWINDOW)GetProcAddress(userdll, "GetDpiForWindow"); + } if (pGetDpiForWindow) return pGetDpiForWindow(hwnd); HDC hdc = GetDC(NULL); @@ -2740,9 +2748,9 @@ static LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPMINMAXINFO lpmmi; lpmmi = (LPMINMAXINFO)lParam; lpmmi->ptMinTrackSize.x = 160 + mon->window_extra_width; - lpmmi->ptMinTrackSize.y = 128 + mon->window_extra_height + mon->window_extra_height_bar; + lpmmi->ptMinTrackSize.y = 128 + mon->window_extra_height; lpmmi->ptMaxTrackSize.x = max_uae_width + mon->window_extra_width; - lpmmi->ptMaxTrackSize.y = max_uae_height + mon->window_extra_height + mon->window_extra_height_bar; + lpmmi->ptMaxTrackSize.y = max_uae_height + mon->window_extra_height; } return 0; @@ -2793,9 +2801,9 @@ static LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT message, WPARAM wParam, int w = mon->mainwin_rect.right - mon->mainwin_rect.left; int h = mon->mainwin_rect.bottom - mon->mainwin_rect.top; if (w != changed_prefs.gfx_monitor[mon->monitor_id].gfx_size_win.width + mon->window_extra_width || - h != changed_prefs.gfx_monitor[mon->monitor_id].gfx_size_win.height + mon->window_extra_height + mon->window_extra_height_bar) { + h != changed_prefs.gfx_monitor[mon->monitor_id].gfx_size_win.height + mon->window_extra_height) { changed_prefs.gfx_monitor[mon->monitor_id].gfx_size_win.width = w - mon->window_extra_width; - changed_prefs.gfx_monitor[mon->monitor_id].gfx_size_win.height = h - (mon->window_extra_height + mon->window_extra_height_bar); + changed_prefs.gfx_monitor[mon->monitor_id].gfx_size_win.height = h - mon->window_extra_height; set_config_changed(); } } @@ -7942,6 +7950,7 @@ int PASCAL wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL } } } + pAdjustWindowRectExForDpi = (ADJUSTWINDOWRECTEXFORDPI)GetProcAddress(userdll, "AdjustWindowRectExForDpi"); InitCommonControls (); diff --git a/od-win32/win32.h b/od-win32/win32.h index 6b1113a9..42a03521 100644 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -226,4 +226,7 @@ BOOL SetFileAttributesSafe (const TCHAR *name, DWORD attr); void HtmlHelp(HWND a, LPCWSTR b, UINT c, const TCHAR *d); +typedef BOOL(CALLBACK* ADJUSTWINDOWRECTEXFORDPI)(LPRECT, DWORD, BOOL, DWORD, UINT); +extern ADJUSTWINDOWRECTEXFORDPI pAdjustWindowRectExForDpi; + #endif diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index beab1e12..1b8c33d1 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -979,6 +979,7 @@ static BOOL CALLBACK monitorEnumProc (HMONITOR h, HDC hdc, LPRECT rect, LPARAM d while (md - Displays < MAX_DISPLAYS && md->monitorid) { if (!_tcscmp (md->adapterid, lpmi.szDevice)) { TCHAR tmp[1000]; + md->monitor = h; md->rect = lpmi.rcMonitor; md->workrect = lpmi.rcWork; adjustappbar(&md->rect, &md->workrect); @@ -1006,6 +1007,7 @@ static BOOL CALLBACK monitorEnumProc2(HMONITOR h, HDC hdc, LPRECT rect, LPARAM d struct MultiDisplay *md = &Displays[i]; if (!_tcscmp (md->adapterid, lpmi.szDevice) && !memcmp(&md->rect, &lpmi.rcMonitor, sizeof RECT)) { md->workrect = lpmi.rcWork; + md->monitor = h; adjustappbar(&md->rect, &md->workrect); return TRUE; } @@ -2250,9 +2252,7 @@ static int getstatuswindowheight(int monid, HWND hwnd) return def; wi.cbSize = sizeof wi; if (GetWindowInfo(h, &wi)) { - int dpi = getdpiforwindow(h); def = wi.rcWindow.bottom - wi.rcWindow.top; - def = def * dpi / 96; } DestroyWindow(h); return def; @@ -3658,6 +3658,7 @@ static int create_windows_2(struct AmigaMonitor *mon) GetWindowRect (mon->hAmigaWnd, &r); int sbheight = currprefs.win32_statusbar ? getstatuswindowheight(mon->monitor_id, mon->hAmigaWnd) : 0; + int dpi = getdpiforwindow(mon->hAmigaWnd); x = r.left; y = r.top; @@ -3693,18 +3694,34 @@ static int create_windows_2(struct AmigaMonitor *mon) else ny = rc.top + (rc.bottom - rc.top - nh); } - if (w != nw || h != nh || x != nx || y != ny || sbheight != mon->window_extra_height_bar) { + if (w != nw || h != nh || x != nx || y != ny || sbheight != mon->window_extra_height_bar || dpi != mon->dpi) { w = nw; h = nh; x = nx; y = ny; - mon->window_extra_height_bar = sbheight; mon->in_sizemove++; if (mon->hMainWnd && !fsw && !dxfs && !d3dfs && !rp_isactive()) { + if (dpi != mon->dpi) { + mon->window_extra_height -= mon->window_extra_height_bar; + mon->window_extra_height += sbheight; + } else { + mon->window_extra_height += (sbheight - mon->window_extra_height_bar); + } + GetWindowRect(mon->hMainWnd, &r); +#if 0 + RECT r2; + GetClientRect(mon->hMainWnd, &r2); + if (pAdjustWindowRectExForDpi) { + HMONITOR mon = MonitorFromRect(&r, MONITOR_DEFAULTTONEAREST); + pAdjustWindowRectExForDpi(&r, borderless ? WS_POPUP : style, FALSE, exstyle, getdpiformonitor(mon)); + } else { + AdjustWindowRectEx(&r, borderless ? WS_POPUP : style, FALSE, exstyle); + } +#endif x = r.left; y = r.top; - SetWindowPos(mon->hMainWnd, HWND_TOP, x, y, w + mon->window_extra_width, h + mon->window_extra_height + mon->window_extra_height_bar, + SetWindowPos(mon->hMainWnd, HWND_TOP, x, y, w + mon->window_extra_width, h + mon->window_extra_height, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER); x = gap; y = gap; @@ -3712,6 +3729,7 @@ static int create_windows_2(struct AmigaMonitor *mon) SetWindowPos(mon->hAmigaWnd, HWND_TOP, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER); mon->in_sizemove--; + mon->dpi = dpi; } else { w = nw; h = nh; @@ -3719,7 +3737,7 @@ static int create_windows_2(struct AmigaMonitor *mon) y = ny; } createstatuswindow(mon); - createstatusline(mon->monitor_id); + createstatusline(mon->hAmigaWnd, mon->monitor_id); updatewinrect(mon, false); GetWindowRect (mon->hMainWnd, &mon->mainwin_rect); if (d3dfs || dxfs) @@ -3728,6 +3746,7 @@ static int create_windows_2(struct AmigaMonitor *mon) mon->amigawin_rect.left, mon->amigawin_rect.top, mon->amigawin_rect.right - mon->amigawin_rect.left, mon->amigawin_rect.bottom - mon->amigawin_rect.top); updatemouseclip(mon); rp_screenmode_changed (); + mon->window_extra_height_bar = sbheight; return 1; } @@ -3779,7 +3798,12 @@ static int create_windows_2(struct AmigaMonitor *mon) oldx = rc.left; oldy = rc.top; - AdjustWindowRect (&rc, borderless ? WS_POPUP : style, FALSE); + if (pAdjustWindowRectExForDpi) { + HMONITOR mon = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); + pAdjustWindowRectExForDpi(&rc, borderless ? WS_POPUP : style, FALSE, exstyle, getdpiformonitor(mon)); + } else { + AdjustWindowRectEx(&rc, borderless ? WS_POPUP : style, FALSE, exstyle); + } mon->win_x_diff = rc.left - oldx; mon->win_y_diff = rc.top - oldy; @@ -3833,12 +3857,10 @@ static int create_windows_2(struct AmigaMonitor *mon) break; } GetWindowRect(mon->hMainWnd, &rc2); - mon->window_extra_width = (rc2.right - rc2.left) - mon->currentmode.current_width; - mon->window_extra_height = (rc2.bottom - rc2.top) - mon->currentmode.current_height; - mon->window_extra_height -= sbheight; - mon->window_extra_height_bar = sbheight; + mon->window_extra_width = rc2.right - rc2.left - mon->currentmode.current_width; + mon->window_extra_height = rc2.bottom - rc2.top - mon->currentmode.current_height; createstatuswindow(mon); - createstatusline(mon->monitor_id); + createstatusline(mon->hMainWnd, mon->monitor_id); } else { x = rc.left; y = rc.top; @@ -3898,6 +3920,7 @@ static int create_windows_2(struct AmigaMonitor *mon) movecursor (x + w / 2, y + h / 2); addnotifications (mon->hAmigaWnd, FALSE, FALSE); mon->window_extra_height_bar = sbheight; + mon->dpi = getdpiforwindow(mon->hAmigaWnd); if (mon->monitor_id) { ShowWindow(mon->hMainWnd, SW_SHOWNOACTIVATE); @@ -4206,7 +4229,7 @@ retry: display_param_init(mon); - createstatusline(mon->monitor_id); + createstatusline(mon->hAmigaWnd, mon->monitor_id); picasso_refresh(mon->monitor_id); #ifdef RETROPLATFORM rp_set_hwnd_delayed (); -- 2.47.3