Adjust menu item rendering based on monitor dpi.

This commit is contained in:
Bart House
2018-11-12 22:40:36 -08:00
parent f67e7c0614
commit 8069659912
4 changed files with 41 additions and 22 deletions
+20
View File
@@ -44,3 +44,23 @@ void win10_init()
} }
} }
int win10_monitor_dpi(HWND hWnd)
{
UINT monitorDpi = 96;
if (gWin10.Valid) {
monitorDpi = gWin10.GetDpiForWindow(hWnd);
if (monitorDpi == 0)
monitorDpi = 96;
}
monitorDpi = max(96, monitorDpi);
return monitorDpi;
}
double win10_monitor_scale(HWND hWnd)
{
return (double) win10_monitor_dpi(hWnd) / 96.0;
}
+3
View File
@@ -22,5 +22,8 @@ typedef struct {
extern Win10 gWin10; extern Win10 gWin10;
void win10_init(); void win10_init();
int win10_monitor_dpi(HWND hWnd);
double win10_monitor_scale(HWND hWnd);
#endif // WIN10_H #endif // WIN10_H
+2 -11
View File
@@ -129,17 +129,8 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw)
wnd_size.cx = client_rt.right - client_rt.left; wnd_size.cx = client_rt.right - client_rt.left;
wnd_size.cy = client_rt.bottom - client_rt.top; wnd_size.cy = client_rt.bottom - client_rt.top;
/* calculate monitor dpi and monitor scale */ // calculate back buffer scale
UINT monitorDpi = 96; data->monitorScale = win10_monitor_scale(hWnd);
if (gWin10.Valid) {
monitorDpi = gWin10.GetDpiForWindow(hWnd);
if (monitorDpi == 0)
monitorDpi = 96;
}
monitorDpi = max(96, monitorDpi);
data->monitorScale = (double) monitorDpi / 96.0;
if (data->bAsciiMode) { if (data->bAsciiMode) {
data->backScale = data->monitorScale; data->backScale = data->monitorScale;
+16 -11
View File
@@ -2,6 +2,7 @@
/* Copyright (c) Alex Kompel, 2002 */ /* Copyright (c) Alex Kompel, 2002 */
/* 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 <assert.h> #include <assert.h>
#include "resource.h" #include "resource.h"
@@ -975,6 +976,9 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
int color = NO_COLOR, attr; int color = NO_COLOR, attr;
boolean menucolr = FALSE; boolean menucolr = FALSE;
double monitorScale = win10_monitor_scale(hWnd);
int tileXScaled = (int) (TILE_X * monitorScale);
int tileYScaled = (int) (TILE_Y * monitorScale);
UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(wParam);
@@ -1024,15 +1028,15 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
break; break;
} }
y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; y = (lpdis->rcItem.bottom + lpdis->rcItem.top - tileYScaled) / 2;
SetBrushOrgEx(lpdis->hDC, x, y, NULL); SetBrushOrgEx(lpdis->hDC, x, y, NULL);
saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); saveBrush = SelectObject(lpdis->hDC, hbrCheckMark);
PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); PatBlt(lpdis->hDC, x, y, tileXScaled, tileYScaled, PATCOPY);
SelectObject(lpdis->hDC, saveBrush); SelectObject(lpdis->hDC, saveBrush);
DeleteObject(hbrCheckMark); DeleteObject(hbrCheckMark);
} }
x += TILE_X + spacing; x += tileXScaled + spacing;
if (item->accelerator != 0) { if (item->accelerator != 0) {
buf[0] = item->accelerator; buf[0] = item->accelerator;
@@ -1053,13 +1057,14 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
} }
x += tm.tmAveCharWidth + tm.tmOverhang + spacing; x += tm.tmAveCharWidth + tm.tmOverhang + spacing;
} else { } else {
x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 2 * spacing; x += tileXScaled + tm.tmAveCharWidth + tm.tmOverhang + 2 * spacing;
} }
/* print glyph if present */ /* print glyph if present */
if (NHMENU_HAS_GLYPH(*item)) { if (NHMENU_HAS_GLYPH(*item)) {
if (!IS_MAP_ASCII(iflags.wc_map_mode)) { if (!IS_MAP_ASCII(iflags.wc_map_mode)) {
HGDIOBJ saveBmp; HGDIOBJ saveBmp;
double monitorScale = win10_monitor_scale(hWnd);
saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles);
ntile = glyph2tile[item->glyph]; ntile = glyph2tile[item->glyph];
@@ -1068,21 +1073,21 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
t_y = t_y =
(ntile / GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_Y; (ntile / GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_Y;
y = (lpdis->rcItem.bottom + lpdis->rcItem.top y = (lpdis->rcItem.bottom + lpdis->rcItem.top - tileYScaled) / 2;
- GetNHApp()->mapTile_Y) / 2;
if (GetNHApp()->bmpMapTiles == GetNHApp()->bmpTiles) { if (GetNHApp()->bmpMapTiles == GetNHApp()->bmpTiles) {
/* using original nethack tiles - apply image transparently */ /* using original nethack tiles - apply image transparently */
(*GetNHApp()->lpfnTransparentBlt)(lpdis->hDC, x, y, TILE_X, TILE_Y, (*GetNHApp()->lpfnTransparentBlt)(lpdis->hDC, x, y,
tileXScaled, tileYScaled,
tileDC, t_x, t_y, TILE_X, TILE_Y, tileDC, t_x, t_y, TILE_X, TILE_Y,
TILE_BK_COLOR); TILE_BK_COLOR);
} else { } else {
/* using custom tiles - simple blt */ /* using custom tiles - simple blt */
BitBlt(lpdis->hDC, x, y, GetNHApp()->mapTile_X, StretchBlt(lpdis->hDC, x, y, tileXScaled, tileYScaled,
GetNHApp()->mapTile_Y, tileDC, t_x, t_y, SRCCOPY); tileDC, t_x, t_y, GetNHApp()->mapTile_X, GetNHApp()->mapTile_Y, SRCCOPY);
} }
SelectObject(tileDC, saveBmp); SelectObject(tileDC, saveBmp);
x += GetNHApp()->mapTile_X; x += tileXScaled;
} else { } else {
const char *sel_ind; const char *sel_ind;
switch (item->count) { switch (item->count) {
@@ -1106,7 +1111,7 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
} }
} else { } else {
/* no glyph - need to adjust so help window won't look to cramped */ /* no glyph - need to adjust so help window won't look to cramped */
x += TILE_X; x += tileXScaled;
} }
x += spacing; x += spacing;