Added monitor dpi awareness to NetHackW splash dialog.
This commit is contained in:
@@ -45,6 +45,17 @@ void win10_init()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void win10_monitor_size(HWND hWnd, int * width, int * height)
|
||||||
|
{
|
||||||
|
HMONITOR monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
|
||||||
|
MONITORINFO info;
|
||||||
|
info.cbSize = sizeof(MONITORINFO);
|
||||||
|
BOOL success = GetMonitorInfo(monitor, &info);
|
||||||
|
nhassert(success);
|
||||||
|
*width = info.rcMonitor.right - info.rcMonitor.left;
|
||||||
|
*height = info.rcMonitor.bottom - info.rcMonitor.top;
|
||||||
|
}
|
||||||
|
|
||||||
int win10_monitor_dpi(HWND hWnd)
|
int win10_monitor_dpi(HWND hWnd)
|
||||||
{
|
{
|
||||||
UINT monitorDpi = 96;
|
UINT monitorDpi = 96;
|
||||||
@@ -64,3 +75,9 @@ double win10_monitor_scale(HWND hWnd)
|
|||||||
{
|
{
|
||||||
return (double) win10_monitor_dpi(hWnd) / 96.0;
|
return (double) win10_monitor_dpi(hWnd) / 96.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo)
|
||||||
|
{
|
||||||
|
monitorInfo->scale = win10_monitor_scale(hWnd);
|
||||||
|
win10_monitor_size(hWnd, &monitorInfo->width, &monitorInfo->height);
|
||||||
|
}
|
||||||
@@ -19,11 +19,19 @@ typedef struct {
|
|||||||
GetDpiForWindowProc GetDpiForWindow;
|
GetDpiForWindowProc GetDpiForWindow;
|
||||||
} Win10;
|
} Win10;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
double scale; // dpi of monitor / 96
|
||||||
|
int width; // in pixels
|
||||||
|
int height; // in pixels
|
||||||
|
} MonitorInfo;
|
||||||
|
|
||||||
extern Win10 gWin10;
|
extern Win10 gWin10;
|
||||||
|
|
||||||
void win10_init();
|
void win10_init();
|
||||||
int win10_monitor_dpi(HWND hWnd);
|
int win10_monitor_dpi(HWND hWnd);
|
||||||
double win10_monitor_scale(HWND hWnd);
|
double win10_monitor_scale(HWND hWnd);
|
||||||
|
void win10_monitor_size(HWND hWnd, int * width, int * height);
|
||||||
|
void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo);
|
||||||
|
|
||||||
|
|
||||||
#endif // WIN10_H
|
#endif // WIN10_H
|
||||||
+3
-1
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
/* font management and such */
|
/* font management and such */
|
||||||
|
|
||||||
|
#include "win10.h"
|
||||||
#include "winos.h"
|
#include "winos.h"
|
||||||
#include "mhfont.h"
|
#include "mhfont.h"
|
||||||
|
|
||||||
@@ -26,9 +27,10 @@ void
|
|||||||
mswin_init_splashfonts(HWND hWnd)
|
mswin_init_splashfonts(HWND hWnd)
|
||||||
{
|
{
|
||||||
HDC hdc = GetDC(hWnd);
|
HDC hdc = GetDC(hWnd);
|
||||||
|
double scale = win10_monitor_scale(hWnd);
|
||||||
LOGFONT lgfnt;
|
LOGFONT lgfnt;
|
||||||
ZeroMemory(&lgfnt, sizeof(lgfnt));
|
ZeroMemory(&lgfnt, sizeof(lgfnt));
|
||||||
lgfnt.lfHeight = -80; // height of font
|
lgfnt.lfHeight = -(int)(80 * scale); // height of font
|
||||||
lgfnt.lfWidth = 0; // average character width
|
lgfnt.lfWidth = 0; // average character width
|
||||||
lgfnt.lfEscapement = 0; // angle of escapement
|
lgfnt.lfEscapement = 0; // angle of escapement
|
||||||
lgfnt.lfOrientation = 0; // base-line orientation angle
|
lgfnt.lfOrientation = 0; // base-line orientation angle
|
||||||
|
|||||||
+53
-24
@@ -2,6 +2,7 @@
|
|||||||
/* Copyright (C) 2001 by Alex Kompel */
|
/* Copyright (C) 2001 by Alex Kompel */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
|
#include "win10.h"
|
||||||
#include "winMS.h"
|
#include "winMS.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "mhsplash.h"
|
#include "mhsplash.h"
|
||||||
@@ -17,15 +18,24 @@ PNHWinApp GetNHApp(void);
|
|||||||
|
|
||||||
INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
|
INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
|
||||||
#define SPLASH_WIDTH 440
|
#define SPLASH_WIDTH_96DPI 440
|
||||||
#define SPLASH_HEIGHT 322
|
#define SPLASH_HEIGHT_96DPI 322
|
||||||
#define SPLASH_VERSION_X 290
|
#define SPLASH_OFFSET_X_96DPI 10
|
||||||
#define SPLASH_VERSION_Y 10
|
#define SPLASH_OFFSET_Y_96DPI 10
|
||||||
#define SPLASH_OFFSET_X 10
|
#define SPLASH_VERSION_X_96DPI 280
|
||||||
#define SPLASH_OFFSET_Y 10
|
#define SPLASH_VERSION_Y_96DPI 0
|
||||||
|
|
||||||
extern HFONT version_splash_font;
|
extern HFONT version_splash_font;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int offsetX;
|
||||||
|
int offsetY;
|
||||||
|
int versionX;
|
||||||
|
int versionY;
|
||||||
|
} SplashData;
|
||||||
|
|
||||||
void
|
void
|
||||||
mswin_display_splash_window(BOOL show_ver)
|
mswin_display_splash_window(BOOL show_ver)
|
||||||
{
|
{
|
||||||
@@ -34,16 +44,30 @@ mswin_display_splash_window(BOOL show_ver)
|
|||||||
RECT splashrt;
|
RECT splashrt;
|
||||||
RECT clientrt;
|
RECT clientrt;
|
||||||
RECT controlrt;
|
RECT controlrt;
|
||||||
HWND hWnd;
|
|
||||||
int buttop;
|
int buttop;
|
||||||
strbuf_t strbuf;
|
strbuf_t strbuf;
|
||||||
|
|
||||||
strbuf_init(&strbuf);
|
strbuf_init(&strbuf);
|
||||||
|
|
||||||
hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
|
HWND hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
|
||||||
GetNHApp()->hMainWnd, NHSplashWndProc);
|
GetNHApp()->hMainWnd, NHSplashWndProc);
|
||||||
if (!hWnd)
|
if (!hWnd)
|
||||||
panic("Cannot create Splash window");
|
panic("Cannot create Splash window");
|
||||||
|
|
||||||
|
MonitorInfo monitorInfo;
|
||||||
|
win10_monitor_info(hWnd, &monitorInfo);
|
||||||
|
|
||||||
|
SplashData splashData;
|
||||||
|
|
||||||
|
splashData.width = (int) (monitorInfo.scale * SPLASH_WIDTH_96DPI);
|
||||||
|
splashData.height = (int) (monitorInfo.scale * SPLASH_HEIGHT_96DPI);
|
||||||
|
splashData.offsetX = (int) (monitorInfo.scale * SPLASH_OFFSET_X_96DPI);
|
||||||
|
splashData.offsetY = (int) (monitorInfo.scale * SPLASH_OFFSET_Y_96DPI);
|
||||||
|
splashData.versionX = (int) (monitorInfo.scale * SPLASH_VERSION_X_96DPI);
|
||||||
|
splashData.versionY = (int) (monitorInfo.scale * SPLASH_VERSION_Y_96DPI);
|
||||||
|
|
||||||
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) &splashData);
|
||||||
|
|
||||||
mswin_init_splashfonts(hWnd);
|
mswin_init_splashfonts(hWnd);
|
||||||
GetNHApp()->hPopupWnd = hWnd;
|
GetNHApp()->hPopupWnd = hWnd;
|
||||||
/* Get control size */
|
/* Get control size */
|
||||||
@@ -57,30 +81,32 @@ mswin_display_splash_window(BOOL show_ver)
|
|||||||
splashrt.right -= splashrt.left;
|
splashrt.right -= splashrt.left;
|
||||||
splashrt.bottom -= splashrt.top;
|
splashrt.bottom -= splashrt.top;
|
||||||
/* Get difference between requested client area and current value */
|
/* Get difference between requested client area and current value */
|
||||||
splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right;
|
splashrt.right += splashData.width + splashData.offsetX * 2
|
||||||
splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3
|
- clientrt.right;
|
||||||
- clientrt.bottom;
|
splashrt.bottom += splashData.height + controlrt.bottom
|
||||||
|
+ splashData.offsetY * 3
|
||||||
|
- clientrt.bottom;
|
||||||
/* Place the window centered */
|
/* Place the window centered */
|
||||||
/* On the screen, not on the parent window */
|
/* On the screen, not on the parent window */
|
||||||
left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2;
|
left = (monitorInfo.width - splashrt.right) / 2;
|
||||||
top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2;
|
top = (monitorInfo.height - splashrt.bottom) / 2;
|
||||||
MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
|
MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
|
||||||
/* Place the OK control */
|
/* Place the OK control */
|
||||||
GetClientRect(hWnd, &clientrt);
|
GetClientRect(hWnd, &clientrt);
|
||||||
MoveWindow(GetDlgItem(hWnd, IDOK),
|
MoveWindow(GetDlgItem(hWnd, IDOK),
|
||||||
(clientrt.right - clientrt.left - controlrt.right) / 2,
|
(clientrt.right - clientrt.left - controlrt.right) / 2,
|
||||||
clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y,
|
clientrt.bottom - controlrt.bottom - splashData.offsetY,
|
||||||
controlrt.right, controlrt.bottom, TRUE);
|
controlrt.right, controlrt.bottom, TRUE);
|
||||||
buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y;
|
buttop = clientrt.bottom - controlrt.bottom - splashData.offsetY;
|
||||||
/* Place the text control */
|
/* Place the text control */
|
||||||
GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
|
GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
|
||||||
controlrt.right -= controlrt.left;
|
controlrt.right -= controlrt.left;
|
||||||
controlrt.bottom -= controlrt.top;
|
controlrt.bottom -= controlrt.top;
|
||||||
GetClientRect(hWnd, &clientrt);
|
GetClientRect(hWnd, &clientrt);
|
||||||
MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO),
|
MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO),
|
||||||
clientrt.left + SPLASH_OFFSET_X,
|
clientrt.left + splashData.offsetX,
|
||||||
buttop - controlrt.bottom - SPLASH_OFFSET_Y,
|
buttop - controlrt.bottom - splashData.offsetY,
|
||||||
clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
|
clientrt.right - 2 * splashData.offsetX, controlrt.bottom, TRUE);
|
||||||
|
|
||||||
/* Fill the text control */
|
/* Fill the text control */
|
||||||
strbuf_reserve(&strbuf, BUFSIZ);
|
strbuf_reserve(&strbuf, BUFSIZ);
|
||||||
@@ -168,16 +194,19 @@ NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
HANDLE OldFont;
|
HANDLE OldFont;
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
|
|
||||||
|
SplashData *splashData = (SplashData *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||||
|
|
||||||
hdc = BeginPaint(hWnd, &ps);
|
hdc = BeginPaint(hWnd, &ps);
|
||||||
/* Show splash graphic */
|
/* Show splash graphic */
|
||||||
|
|
||||||
hdcBitmap = CreateCompatibleDC(hdc);
|
hdcBitmap = CreateCompatibleDC(hdc);
|
||||||
SetBkMode(hdc, OPAQUE);
|
SetBkMode(hdc, OPAQUE);
|
||||||
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
|
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
|
||||||
(*GetNHApp()->lpfnTransparentBlt)(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
|
(*GetNHApp()->lpfnTransparentBlt)(hdc,
|
||||||
SPLASH_WIDTH, SPLASH_HEIGHT, hdcBitmap, 0,
|
splashData->offsetX, splashData->offsetY,
|
||||||
0, SPLASH_WIDTH, SPLASH_HEIGHT,
|
splashData->width, splashData->height, hdcBitmap,
|
||||||
TILE_BK_COLOR);
|
0, 0, SPLASH_WIDTH_96DPI, SPLASH_HEIGHT_96DPI,
|
||||||
|
TILE_BK_COLOR);
|
||||||
|
|
||||||
SelectObject(hdcBitmap, OldBitmap);
|
SelectObject(hdcBitmap, OldBitmap);
|
||||||
DeleteDC(hdcBitmap);
|
DeleteDC(hdcBitmap);
|
||||||
@@ -186,8 +215,8 @@ NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
/* Print version number */
|
/* Print version number */
|
||||||
|
|
||||||
SetTextColor(hdc, RGB(0, 0, 0));
|
SetTextColor(hdc, RGB(0, 0, 0));
|
||||||
rt.right = rt.left = SPLASH_VERSION_X;
|
rt.right = rt.left = splashData->offsetX + splashData->versionX;
|
||||||
rt.bottom = rt.top = SPLASH_VERSION_Y;
|
rt.bottom = rt.top = splashData->offsetY + splashData->versionY;
|
||||||
Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
|
Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
|
||||||
PATCHLEVEL);
|
PATCHLEVEL);
|
||||||
OldFont = SelectObject(hdc, version_splash_font);
|
OldFont = SelectObject(hdc, version_splash_font);
|
||||||
|
|||||||
Reference in New Issue
Block a user