Started work to support per monitor DPI. Using DPI to scale tiles

appropriately.

Renamed ntassert to nhassert.  (Naming mistake caused by using ntassert
at work).

Re-ordered a few more includes to get window headers included before
nethack headers.
This commit is contained in:
Bart House
2018-11-12 17:45:22 -08:00
parent f3bc4af242
commit 3bb759a9ab
9 changed files with 166 additions and 126 deletions

View File

@@ -242,8 +242,8 @@ static void back_buffer_flip()
void buffer_fill_to_end(cell_t * buffer, cell_t * fill, int x, int y)
{
ntassert(x >= 0 && x < console.width);
ntassert(y >= 0 && ((y < console.height) || (y == console.height &&
nhassert(x >= 0 && x < console.width);
nhassert(y >= 0 && ((y < console.height) || (y == console.height &&
x == 0)));
cell_t * dst = buffer + console.width * y + x;
@@ -257,8 +257,8 @@ void buffer_fill_to_end(cell_t * buffer, cell_t * fill, int x, int y)
static void buffer_clear_to_end_of_line(cell_t * buffer, int x, int y)
{
ntassert(x >= 0 && x < console.width);
ntassert(y >= 0 && ((y < console.height) || (y == console.height &&
nhassert(x >= 0 && x < console.width);
nhassert(y >= 0 && ((y < console.height) || (y == console.height &&
x == 0)));
cell_t * dst = buffer + console.width * y + x;
cell_t *sentinel = buffer + console.width * (y + 1);
@@ -272,8 +272,8 @@ static void buffer_clear_to_end_of_line(cell_t * buffer, int x, int y)
void buffer_write(cell_t * buffer, cell_t * cell, COORD pos)
{
ntassert(pos.X >= 0 && pos.X < console.width);
ntassert(pos.Y >= 0 && pos.Y < console.height);
nhassert(pos.X >= 0 && pos.X < console.width);
nhassert(pos.Y >= 0 && pos.Y < console.height);
cell_t * dst = buffer + (console.width * pos.Y) + pos.X;
*dst = *cell;
@@ -465,8 +465,8 @@ int *x, *y, *mod;
static void set_console_cursor(int x, int y)
{
ntassert(x >= 0 && x < console.width);
ntassert(y >= 0 && y < console.height);
nhassert(x >= 0 && x < console.width);
nhassert(y >= 0 && y < console.height);
console.cursor.X = max(0, min(console.width - 1, x));
console.cursor.Y = max(0, min(console.height - 1, y));
@@ -547,8 +547,8 @@ void
xputc_core(ch)
char ch;
{
ntassert(console.cursor.X >= 0 && console.cursor.X < console.width);
ntassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
boolean inverse = FALSE;
cell_t cell;
@@ -596,8 +596,8 @@ char ch;
}
}
ntassert(console.cursor.X >= 0 && console.cursor.X < console.width);
ntassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
}
/*
@@ -982,7 +982,7 @@ register char *op;
void unload_keyboard_handler()
{
ntassert(keyboard_handler.hLibrary != NULL);
nhassert(keyboard_handler.hLibrary != NULL);
FreeLibrary(keyboard_handler.hLibrary);
memset(&keyboard_handler, 0, sizeof(keyboard_handler_t));
@@ -1619,10 +1619,10 @@ set_known_good_console_font()
L"Consolas");
success = SetConsoleOutputCP(437);
ntassert(success);
nhassert(success);
success = SetCurrentConsoleFontEx(console.hConOut, FALSE, &console_font_info);
ntassert(success);
nhassert(success);
}
/* restore_original_console_font will restore the console font and code page
@@ -1665,7 +1665,7 @@ void set_cp_map()
char c = (char)i;
int count = MultiByteToWideChar(codePage, 0, &c, 1,
&console.cpMap[i], 1);
ntassert(count == 1);
nhassert(count == 1);
}
}
@@ -1685,8 +1685,8 @@ void early_raw_print(const char *s)
if (console.hConOut == NULL)
return;
ntassert(console.cursor.X >= 0 && console.cursor.X < console.width);
ntassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
WORD attribute = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE;
DWORD unused;
@@ -1725,8 +1725,8 @@ void early_raw_print(const char *s)
s++;
}
ntassert(console.cursor.X >= 0 && console.cursor.X < console.width);
ntassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
SetConsoleCursorPosition(console.hConOut, console.cursor);
@@ -1762,7 +1762,7 @@ void nethack_enter_nttty()
windowprocs.win_raw_print = early_raw_print;
console.hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
ntassert(console.hConOut != NULL); // NOTE: this assert will not print
nhassert(console.hConOut != NULL); // NOTE: this assert will not print
GetConsoleScreenBufferInfo(console.hConOut, &console.origcsbi);
@@ -1803,7 +1803,7 @@ void nethack_enter_nttty()
/* At this point early_raw_print will work */
console.hConIn = GetStdHandle(STD_INPUT_HANDLE);
ntassert(console.hConIn != NULL);
nhassert(console.hConIn != NULL);
/* grow the size of the console buffer if it is not wide enough */
if (console.origcsbi.dwSize.X < console.width) {

View File

@@ -2,12 +2,12 @@
/* Copyright (C) 2018 by Bart House */
/* NetHack may be freely redistributed. See license for details. */
#include <process.h>
#include "winMS.h"
#include "hack.h"
#include "win10.h"
#include <process.h>
#include <VersionHelpers.h>
#include "hack.h"
Win10 gWin10 = { 0 };
void win10_init()
@@ -27,6 +27,10 @@ void win10_init()
if (gWin10.AreDpiAwarenessContextsEqual == NULL)
panic("Unable to get address of AreDpiAwarenessContextsEqual");
gWin10.GetDpiForWindow = (GetDpiForWindowProc) GetProcAddress(hUser32, "GetDpiForWindow");
if (gWin10.GetDpiForWindow == NULL)
panic("Unable to get address of GetDpiForWindow");
FreeLibrary(hUser32);
gWin10.Valid = TRUE;
@@ -35,7 +39,7 @@ void win10_init()
if (gWin10.Valid) {
if (!gWin10.AreDpiAwarenessContextsEqual(
gWin10.GetThreadDpiAwarenessContext(),
DPI_AWARENESS_CONTEXT_UNAWARE))
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2))
panic("Unexpected DpiAwareness state");
}

View File

@@ -2,16 +2,25 @@
/* Copyright (C) 2018 by Bart House */
/* NetHack may be freely redistributed. See license for details. */
typedef DPI_AWARENESS_CONTEXT(WINAPI * GetThreadDpiAwarenessContextProc)(VOID);
typedef BOOL (WINAPI *AreDpiAwarenessContextsEqualProc)(DPI_AWARENESS_CONTEXT dpiContextA, DPI_AWARENESS_CONTEXT dpiContextB);
#ifndef WIN10_H
#define WIN10_H
#include "win32api.h"
typedef DPI_AWARENESS_CONTEXT(WINAPI *GetThreadDpiAwarenessContextProc)(VOID);
typedef BOOL(WINAPI *AreDpiAwarenessContextsEqualProc)(
DPI_AWARENESS_CONTEXT dpiContextA, DPI_AWARENESS_CONTEXT dpiContextB);
typedef UINT(WINAPI *GetDpiForWindowProc)(HWND hwnd);
typedef struct {
BOOL Valid;
GetThreadDpiAwarenessContextProc GetThreadDpiAwarenessContext;
AreDpiAwarenessContextsEqualProc AreDpiAwarenessContextsEqual;
GetDpiForWindowProc GetDpiForWindow;
} Win10;
extern Win10 gWin10;
void win10_init();
#endif // WIN10_H

View File

@@ -468,8 +468,8 @@ char *buf;
}
#endif /* RUNTIME_PORT_ID */
/* ntassert_failed is called when an ntassert's condition is false */
void ntassert_failed(const char * exp, const char * file, int line)
/* nhassert_failed is called when an nhassert's condition is false */
void nhassert_failed(const char * exp, const char * file, int line)
{
char message[128];
_snprintf(message, sizeof(message),