Main UI: HiDPI support
This commit is contained in:
@@ -1,21 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
<assemblyIdentity
|
<assemblyIdentity
|
||||||
version="1.20.0.0"
|
version="1.20.0.0"
|
||||||
processorArchitecture="*"
|
processorArchitecture="*"
|
||||||
name="86Box.exe"
|
name="86Box.exe"
|
||||||
type="win32"
|
type="win32"
|
||||||
/>
|
/>
|
||||||
<dependency>
|
<dependency>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity
|
<assemblyIdentity
|
||||||
type="win32"
|
type="win32"
|
||||||
name="Microsoft.Windows.Common-Controls"
|
name="Microsoft.Windows.Common-Controls"
|
||||||
version="6.0.0.0"
|
version="6.0.0.0"
|
||||||
processorArchitecture="*"
|
processorArchitecture="*"
|
||||||
publicKeyToken="6595b64144ccf1df"
|
publicKeyToken="6595b64144ccf1df"
|
||||||
language="*"
|
language="*"
|
||||||
/>
|
/>
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<application>
|
||||||
|
<windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2</dpiAwareness>
|
||||||
|
</windowsSettings>
|
||||||
|
</application>
|
||||||
</assembly>
|
</assembly>
|
||||||
|
136
src/win/win_ui.c
136
src/win/win_ui.c
@@ -70,6 +70,8 @@ static wchar_t wTitle[512];
|
|||||||
static HHOOK hKeyboardHook;
|
static HHOOK hKeyboardHook;
|
||||||
static int hook_enabled = 0, manager_wm = 0;
|
static int hook_enabled = 0, manager_wm = 0;
|
||||||
static int save_window_pos = 0, pause_state = 0;
|
static int save_window_pos = 0, pause_state = 0;
|
||||||
|
static int dpi = 96;
|
||||||
|
static int padded_frame = 0;
|
||||||
|
|
||||||
|
|
||||||
static int vis = -1;
|
static int vis = -1;
|
||||||
@@ -111,6 +113,24 @@ int win_get_system_metrics(int index, int dpi) {
|
|||||||
return GetSystemMetrics(index);
|
return GetSystemMetrics(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ResizeWindowByClientArea(HWND hwnd, int width, int height)
|
||||||
|
{
|
||||||
|
if (vid_resize || padded_frame) {
|
||||||
|
int padding = win_get_system_metrics(SM_CXPADDEDBORDER, dpi);
|
||||||
|
width += (win_get_system_metrics(SM_CXFRAME, dpi) + padding) * 2;
|
||||||
|
height += (win_get_system_metrics(SM_CYFRAME, dpi) + padding) * 2;
|
||||||
|
} else {
|
||||||
|
width += win_get_system_metrics(SM_CXFIXEDFRAME, dpi) * 2;
|
||||||
|
height += win_get_system_metrics(SM_CYFIXEDFRAME, dpi) * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
height += win_get_system_metrics(SM_CYCAPTION, dpi);
|
||||||
|
height += win_get_system_metrics(SM_CYBORDER, dpi) + win_get_system_metrics(SM_CYMENUSIZE, dpi);
|
||||||
|
|
||||||
|
SetWindowPos(hwnd, NULL, 0, 0, width, height, SWP_NOMOVE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set host cursor visible or not. */
|
/* Set host cursor visible or not. */
|
||||||
void
|
void
|
||||||
show_cursor(int val)
|
show_cursor(int val)
|
||||||
@@ -328,8 +348,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
HMENU hmenu;
|
HMENU hmenu;
|
||||||
|
|
||||||
int i, sb_borders[3];
|
int i;
|
||||||
RECT rect;
|
RECT rect, *rect_p;
|
||||||
|
|
||||||
int temp_x, temp_y;
|
int temp_x, temp_y;
|
||||||
|
|
||||||
@@ -430,42 +450,20 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
if (vid_resize)
|
if (vid_resize)
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW) | WS_VISIBLE);
|
SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW) | WS_VISIBLE);
|
||||||
else
|
else
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX) | WS_VISIBLE);
|
SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_MAXIMIZEBOX) | WS_VISIBLE);
|
||||||
|
|
||||||
SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders);
|
|
||||||
|
|
||||||
GetWindowRect(hwnd, &rect);
|
|
||||||
|
|
||||||
/* Main Window. */
|
/* Main Window. */
|
||||||
if (GetSystemMetrics(SM_CXPADDEDBORDER) == 0) {
|
ResizeWindowByClientArea(hwnd, unscaled_size_x, unscaled_size_y + sbar_height);
|
||||||
/* For platforms that subsystem version < 6.0 (default on mingw/msys2) */
|
|
||||||
/* In this case, border sizes are different between resizable and non-resizable window */
|
|
||||||
MoveWindow(hwnd, rect.left, rect.top,
|
|
||||||
unscaled_size_x + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2),
|
|
||||||
unscaled_size_y + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + (GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYMENUSIZE)) + GetSystemMetrics(SM_CYCAPTION) + sbar_height,
|
|
||||||
TRUE);
|
|
||||||
} else {
|
|
||||||
/* For platforms that subsystem version >= 6.0 (default on llvm-mingw, mainly for Windows/ARM) */
|
|
||||||
/* In this case, border sizes are the same between resizable and non-resizable window */
|
|
||||||
MoveWindow(hwnd, rect.left, rect.top,
|
|
||||||
unscaled_size_x + ((GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)) * 2),
|
|
||||||
unscaled_size_y + ((GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)) * 2) + (GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYMENUSIZE)) + GetSystemMetrics(SM_CYCAPTION) + sbar_height,
|
|
||||||
TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Render window. */
|
/* Render window. */
|
||||||
MoveWindow(hwndRender, 0, 0, unscaled_size_x, unscaled_size_y, TRUE);
|
MoveWindow(hwndRender, 0, 0, unscaled_size_x, unscaled_size_y, TRUE);
|
||||||
GetWindowRect(hwndRender, &rect);
|
GetWindowRect(hwndRender, &rect);
|
||||||
|
|
||||||
/* Status bar. */
|
/* Status bar. */
|
||||||
MoveWindow(hwndSBAR,
|
MoveWindow(hwndSBAR, 0, rect.bottom, unscaled_size_x, 17, TRUE);
|
||||||
0, rect.bottom + GetSystemMetrics(SM_CYEDGE),
|
|
||||||
unscaled_size_x, 17, TRUE);
|
|
||||||
|
|
||||||
if (mouse_capture) {
|
if (mouse_capture) {
|
||||||
GetWindowRect(hwndRender, &rect);
|
|
||||||
|
|
||||||
ClipCursor(&rect);
|
ClipCursor(&rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,6 +476,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
EnableMenuItem(hmenu, IDM_VID_SCALE_2X, vid_resize ? MF_GRAYED : MF_ENABLED);
|
EnableMenuItem(hmenu, IDM_VID_SCALE_2X, vid_resize ? MF_GRAYED : MF_ENABLED);
|
||||||
EnableMenuItem(hmenu, IDM_VID_SCALE_3X, vid_resize ? MF_GRAYED : MF_ENABLED);
|
EnableMenuItem(hmenu, IDM_VID_SCALE_3X, vid_resize ? MF_GRAYED : MF_ENABLED);
|
||||||
EnableMenuItem(hmenu, IDM_VID_SCALE_4X, vid_resize ? MF_GRAYED : MF_ENABLED);
|
EnableMenuItem(hmenu, IDM_VID_SCALE_4X, vid_resize ? MF_GRAYED : MF_ENABLED);
|
||||||
|
|
||||||
|
scrnsz_x = unscaled_size_x;
|
||||||
|
scrnsz_y = unscaled_size_y;
|
||||||
doresize = 1;
|
doresize = 1;
|
||||||
config_save();
|
config_save();
|
||||||
break;
|
break;
|
||||||
@@ -662,12 +663,22 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_ENTERMENULOOP:
|
case WM_ENTERMENULOOP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM_DPICHANGED:
|
||||||
|
dpi = HIWORD(wParam);
|
||||||
|
GetWindowRect(hwndSBAR, &rect);
|
||||||
|
sbar_height = rect.bottom - rect.top;
|
||||||
|
rect_p = (RECT*)lParam;
|
||||||
|
if (vid_resize) {
|
||||||
|
MoveWindow(hwnd, rect_p->left, rect_p->top, rect_p->right - rect_p->left, rect_p->bottom - rect_p->top, TRUE);
|
||||||
|
} else if (!user_resize) {
|
||||||
|
doresize = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
if (user_resize && !vid_resize)
|
if (user_resize && !vid_resize)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders);
|
|
||||||
|
|
||||||
temp_x = (lParam & 0xFFFF);
|
temp_x = (lParam & 0xFFFF);
|
||||||
temp_y = (lParam >> 16);
|
temp_y = (lParam >> 16);
|
||||||
|
|
||||||
@@ -684,26 +695,22 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
if (temp_y < 1)
|
if (temp_y < 1)
|
||||||
temp_y = 1;
|
temp_y = 1;
|
||||||
|
|
||||||
if ((temp_x != scrnsz_x) || (temp_y != scrnsz_y))
|
if (vid_resize && ((temp_x != scrnsz_x) || (temp_y != scrnsz_y))) {
|
||||||
|
scrnsz_x = temp_x;
|
||||||
|
scrnsz_y = temp_y;
|
||||||
doresize = 1;
|
doresize = 1;
|
||||||
|
}
|
||||||
|
|
||||||
scrnsz_x = temp_x;
|
MoveWindow(hwndRender, 0, 0, temp_x, temp_y, TRUE);
|
||||||
scrnsz_y = temp_y;
|
|
||||||
|
|
||||||
MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE);
|
|
||||||
|
|
||||||
GetWindowRect(hwndRender, &rect);
|
GetWindowRect(hwndRender, &rect);
|
||||||
|
|
||||||
/* Status bar. */
|
/* Status bar. */
|
||||||
MoveWindow(hwndSBAR,
|
MoveWindow(hwndSBAR, 0, rect.bottom, temp_x, 17, TRUE);
|
||||||
0, rect.bottom + GetSystemMetrics(SM_CYEDGE),
|
|
||||||
scrnsz_x, 17, TRUE);
|
|
||||||
|
|
||||||
plat_vidsize(scrnsz_x, scrnsz_y);
|
plat_vidsize(temp_x, temp_y);
|
||||||
|
|
||||||
if (mouse_capture) {
|
if (mouse_capture) {
|
||||||
GetWindowRect(hwndRender, &rect);
|
|
||||||
|
|
||||||
ClipCursor(&rect);
|
ClipCursor(&rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1014,6 +1021,19 @@ ui_init(int nCmdShow)
|
|||||||
|
|
||||||
ui_window_title(title);
|
ui_window_title(title);
|
||||||
|
|
||||||
|
/* Get the current DPI */
|
||||||
|
dpi = win_get_dpi(hwndMain);
|
||||||
|
|
||||||
|
/* Check if we have a padded window frame */
|
||||||
|
padded_frame = (GetSystemMetrics(SM_CXPADDEDBORDER) != 0);
|
||||||
|
|
||||||
|
/* Create the status bar window. */
|
||||||
|
StatusBarCreate(hwndMain, IDC_STATUS, hinstance);
|
||||||
|
|
||||||
|
/* Get the actual height of the status bar */
|
||||||
|
GetWindowRect(hwndSBAR, &sbar_rect);
|
||||||
|
sbar_height = sbar_rect.bottom - sbar_rect.top;
|
||||||
|
|
||||||
/* Set up main window for resizing if configured. */
|
/* Set up main window for resizing if configured. */
|
||||||
if (vid_resize)
|
if (vid_resize)
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE,
|
SetWindowLongPtr(hwnd, GWL_STYLE,
|
||||||
@@ -1060,15 +1080,6 @@ ui_init(int nCmdShow)
|
|||||||
/* Initialize the mouse module. */
|
/* Initialize the mouse module. */
|
||||||
win_mouse_init();
|
win_mouse_init();
|
||||||
|
|
||||||
/* Create the status bar window. */
|
|
||||||
StatusBarCreate(hwndMain, IDC_STATUS, hinstance);
|
|
||||||
|
|
||||||
/* Get the actual height of the statusbar,
|
|
||||||
* since that is not something we can change.
|
|
||||||
*/
|
|
||||||
GetWindowRect(hwndSBAR, &sbar_rect);
|
|
||||||
sbar_height = sbar_rect.bottom - sbar_rect.top;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Before we can create the Render window, we first have
|
* Before we can create the Render window, we first have
|
||||||
* to prepare some other things that it depends on.
|
* to prepare some other things that it depends on.
|
||||||
@@ -1262,42 +1273,21 @@ plat_pause(int p)
|
|||||||
void
|
void
|
||||||
plat_resize(int x, int y)
|
plat_resize(int x, int y)
|
||||||
{
|
{
|
||||||
int sb_borders[3];
|
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
/* First, see if we should resize the UI window. */
|
/* First, see if we should resize the UI window. */
|
||||||
if (!vid_resize) {
|
if (!vid_resize) {
|
||||||
video_wait_for_blit();
|
video_wait_for_blit();
|
||||||
|
|
||||||
SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders);
|
|
||||||
|
|
||||||
GetWindowRect(hwndMain, &r);
|
ResizeWindowByClientArea(hwndMain, x, y + sbar_height);
|
||||||
|
|
||||||
if (GetSystemMetrics(SM_CXPADDEDBORDER) == 0) {
|
|
||||||
/* For platforms that subsystem version < 6.0 (gcc on mingw/msys2) */
|
|
||||||
/* In this case, border sizes are different between resizable and non-resizable window */
|
|
||||||
MoveWindow(hwndMain, r.left, r.top,
|
|
||||||
x + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2),
|
|
||||||
y + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + (GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYMENUSIZE)) + GetSystemMetrics(SM_CYCAPTION) + sbar_height,
|
|
||||||
TRUE);
|
|
||||||
} else {
|
|
||||||
/* For platforms that subsystem version >= 6.0 (clang/llvm on llvm-mingw, mainly for Windows/ARM) */
|
|
||||||
/* In this case, border sizes are the same between resizable and non-resizable window */
|
|
||||||
MoveWindow(hwndMain, r.left, r.top,
|
|
||||||
x + ((GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)) * 2),
|
|
||||||
y + ((GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)) * 2) + (GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYMENUSIZE)) + GetSystemMetrics(SM_CYCAPTION) + sbar_height,
|
|
||||||
TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
MoveWindow(hwndRender, 0, 0, x, y, TRUE);
|
MoveWindow(hwndRender, 0, 0, x, y, TRUE);
|
||||||
GetWindowRect(hwndRender, &r);
|
GetWindowRect(hwndRender, &r);
|
||||||
|
|
||||||
MoveWindow(hwndSBAR,
|
MoveWindow(hwndSBAR, 0, y, x, 17, TRUE);
|
||||||
0, r.bottom + GetSystemMetrics(SM_CYEDGE),
|
|
||||||
x, 17, TRUE);
|
|
||||||
|
|
||||||
if (mouse_capture) {
|
if (mouse_capture) {
|
||||||
GetWindowRect(hwndRender, &r);
|
|
||||||
ClipCursor(&r);
|
ClipCursor(&r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user