]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Statusline DPI fix
authorToni Wilen <twilen@winuae.net>
Sat, 20 Feb 2021 16:18:02 +0000 (18:18 +0200)
committerToni Wilen <twilen@winuae.net>
Sat, 20 Feb 2021 16:18:02 +0000 (18:18 +0200)
include/statusline.h
od-win32/dxwrap.h
od-win32/statusline_win32.cpp
od-win32/win32.cpp
od-win32/win32.h
od-win32/win32gfx.cpp

index 355a2b943df1d48d19610a3b897b86eb187e69ad..61ca16365c0cd34977c529402539f4133bbb68de 100644 (file)
@@ -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, ...);
index d31dcbaca50396adba1f0e6bf086bce3e9a32b76..8099168bbfd5e0c773b12a9c546ef18459b6dbce 100644 (file)
@@ -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;
index 8d7e42385e92dbd6f1f14a25f7b8a8107197bfcb..96bf193a8d11ef6714965c157409de84bc5cf0b0 100644 (file)
@@ -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,
index 8639a5198ba2d8464738978221e30397d07d424d..8ee1711833f46b4e35edf3c719185c739dface6d 100644 (file)
@@ -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 ();
 
index 6b1113a96bbbfdc5e198eab42662be439155cedc..42a03521a013381c2efabe28cbb5b681777618a1 100644 (file)
@@ -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
index beab1e129cdb879070c1065d05ccf4d886e16e42..1b8c33d15a4956d32806e1777cbbe75bebfff9f6 100644 (file)
@@ -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 ();