Add Unicode support to the map
This commit is contained in:
+19
-3
@@ -543,10 +543,26 @@ winos_ascii_to_wide_str(const unsigned char * src, WCHAR * dst, size_t dstLength
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
WCHAR
|
void
|
||||||
winos_ascii_to_wide(const unsigned char c)
|
winos_ascii_to_wide(WCHAR dst[3], UINT32 c)
|
||||||
{
|
{
|
||||||
return cp437[c];
|
#ifdef ENHANCED_SYMBOLS
|
||||||
|
if (SYMHANDLING(H_UTF8)) {
|
||||||
|
if (c <= 0xFFFF) {
|
||||||
|
dst[0] = (WCHAR) c;
|
||||||
|
dst[1] = L'\0';
|
||||||
|
} else {
|
||||||
|
/* UTF-16 surrogate pair */
|
||||||
|
dst[0] = (WCHAR) ((c >> 10) + 0xD7C0);
|
||||||
|
dst[1] = (WCHAR) ((c & 0x3FF) + 0xDC00);
|
||||||
|
dst[2] = L'\0';
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
dst[0] = cp437[c];
|
||||||
|
dst[1] = L'\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL winos_font_support_cp437(HFONT hFont)
|
BOOL winos_font_support_cp437(HFONT hFont)
|
||||||
|
|||||||
+2
-2
@@ -12,8 +12,8 @@ extern const WCHAR cp437[256];
|
|||||||
WCHAR *
|
WCHAR *
|
||||||
winos_ascii_to_wide_str(const unsigned char * src, WCHAR * dst, size_t dstLength);
|
winos_ascii_to_wide_str(const unsigned char * src, WCHAR * dst, size_t dstLength);
|
||||||
|
|
||||||
WCHAR
|
void
|
||||||
winos_ascii_to_wide(const unsigned char c);
|
winos_ascii_to_wide(WCHAR dst[3], UINT32 c);
|
||||||
|
|
||||||
BOOL winos_font_support_cp437(HFONT hFont);
|
BOOL winos_font_support_cp437(HFONT hFont);
|
||||||
|
|
||||||
|
|||||||
+45
-18
@@ -49,6 +49,7 @@ typedef struct mswin_nethack_map_window {
|
|||||||
POINT map_orig; /* map origin point */
|
POINT map_orig; /* map origin point */
|
||||||
|
|
||||||
HFONT hMapFont; /* font for ASCII mode */
|
HFONT hMapFont; /* font for ASCII mode */
|
||||||
|
HFONT hMapFontUnicode; /* font for Unicode mode */
|
||||||
boolean bUnicodeFont; /* font supports unicode page 437 */
|
boolean bUnicodeFont; /* font supports unicode page 437 */
|
||||||
|
|
||||||
int tileWidth; /* width of tile in pixels at 96 dpi */
|
int tileWidth; /* width of tile in pixels at 96 dpi */
|
||||||
@@ -252,6 +253,12 @@ mswin_map_layout(HWND hWnd, LPSIZE map_size)
|
|||||||
|
|
||||||
data->bUnicodeFont = winos_font_support_cp437(data->hMapFont);
|
data->bUnicodeFont = winos_font_support_cp437(data->hMapFont);
|
||||||
|
|
||||||
|
// Same as above, but with ANSI_CHARSET for IBM and Unicode modes
|
||||||
|
lgfnt.lfCharSet = ANSI_CHARSET;
|
||||||
|
if (data->hMapFontUnicode)
|
||||||
|
DeleteObject(data->hMapFontUnicode);
|
||||||
|
data->hMapFontUnicode = CreateFontIndirect(&lgfnt);
|
||||||
|
|
||||||
// set tile size to match font metrics
|
// set tile size to match font metrics
|
||||||
|
|
||||||
data->xBackTile = textMetrics.tmAveCharWidth;
|
data->xBackTile = textMetrics.tmAveCharWidth;
|
||||||
@@ -626,6 +633,8 @@ MapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
if (data->hMapFont)
|
if (data->hMapFont)
|
||||||
DeleteObject(data->hMapFont);
|
DeleteObject(data->hMapFont);
|
||||||
|
if (data->hMapFontUnicode)
|
||||||
|
DeleteObject(data->hMapFontUnicode);
|
||||||
if (data->hBackBuffer)
|
if (data->hBackBuffer)
|
||||||
DeleteBitmap(data->hBackBuffer);
|
DeleteBitmap(data->hBackBuffer);
|
||||||
if (data->backBufferDC)
|
if (data->backBufferDC)
|
||||||
@@ -911,9 +920,11 @@ paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
|
|||||||
{
|
{
|
||||||
if (data->map[i][j].glyph >= 0) {
|
if (data->map[i][j].glyph >= 0) {
|
||||||
|
|
||||||
char ch;
|
glyph_info *glyphinfo;
|
||||||
WCHAR wch;
|
uint32 ch;
|
||||||
|
WCHAR wch[3];
|
||||||
int color;
|
int color;
|
||||||
|
uint32 rgbcolor;
|
||||||
// unsigned special;
|
// unsigned special;
|
||||||
// int mgch;
|
// int mgch;
|
||||||
HBRUSH back_brush;
|
HBRUSH back_brush;
|
||||||
@@ -925,12 +936,23 @@ paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
|
|||||||
FillRect(data->backBufferDC, rect, blackBrush);
|
FillRect(data->backBufferDC, rect, blackBrush);
|
||||||
DeleteObject(blackBrush);
|
DeleteObject(blackBrush);
|
||||||
|
|
||||||
#if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2)
|
glyphinfo = &data->map[i][j];
|
||||||
nhglyph2charcolor(data->map[i][j], &ch, &color);
|
ch = glyphinfo->ttychar;
|
||||||
OldFg = SetTextColor(hDC, nhcolor_to_RGB(color));
|
color = (int) glyphinfo->gm.sym.color;
|
||||||
#else
|
rgbcolor = nhcolor_to_RGB(color);
|
||||||
ch = (char) data->map[i][j].ttychar;
|
#ifdef ENHANCED_SYMBOLS
|
||||||
color = (int) data->map[i][j].gm.sym.color;
|
if (SYMHANDLING(H_UTF8)
|
||||||
|
&& glyphinfo->gm.u
|
||||||
|
&& glyphinfo->gm.u->utf8str) {
|
||||||
|
ch = glyphinfo->gm.u->utf32ch;
|
||||||
|
if (glyphinfo->gm.u->ucolor != 0) {
|
||||||
|
rgbcolor = RGB(
|
||||||
|
(glyphinfo->gm.u->ucolor >> 16) & 0xFF,
|
||||||
|
(glyphinfo->gm.u->ucolor >> 8) & 0xFF,
|
||||||
|
(glyphinfo->gm.u->ucolor >> 0) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (((data->map[i][j].gm.glyphflags & MG_PET) && iflags.hilite_pet)
|
if (((data->map[i][j].gm.glyphflags & MG_PET) && iflags.hilite_pet)
|
||||||
|| ((data->map[i][j].gm.glyphflags & (MG_DETECT | MG_BW_LAVA))
|
|| ((data->map[i][j].gm.glyphflags & (MG_DETECT | MG_BW_LAVA))
|
||||||
&& iflags.use_inverse)) {
|
&& iflags.use_inverse)) {
|
||||||
@@ -946,21 +968,23 @@ paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
OldFg =
|
OldFg =
|
||||||
SetTextColor(data->backBufferDC, nhcolor_to_RGB(color));
|
SetTextColor(data->backBufferDC, rgbcolor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
OldFg = SetTextColor(data->backBufferDC, nhcolor_to_RGB(color));
|
OldFg = SetTextColor(data->backBufferDC, rgbcolor);
|
||||||
}
|
}
|
||||||
#endif
|
if (data->bUnicodeFont || SYMHANDLING(H_UTF8)) {
|
||||||
if (data->bUnicodeFont) {
|
winos_ascii_to_wide(wch, ch);
|
||||||
wch = winos_ascii_to_wide(ch);
|
if (wch[0] == 0x2591 || wch[0] == 0x2592) {
|
||||||
if (wch == 0x2591 || wch == 0x2592) {
|
|
||||||
int intensity = 80;
|
int intensity = 80;
|
||||||
HBRUSH brush = CreateSolidBrush(RGB(intensity, intensity, intensity));
|
HBRUSH brush = CreateSolidBrush(RGB(intensity, intensity, intensity));
|
||||||
FillRect(data->backBufferDC, rect, brush);
|
FillRect(data->backBufferDC, rect, brush);
|
||||||
DeleteObject(brush);
|
DeleteObject(brush);
|
||||||
intensity = (wch == 0x2591 ? 100 : 200);
|
intensity = (wch[0] == 0x2591 ? 1 : 2);
|
||||||
brush = CreateSolidBrush(RGB(intensity, intensity, intensity));
|
brush = CreateSolidBrush(RGB(
|
||||||
|
GetRValue(rgbcolor)*intensity/2,
|
||||||
|
GetGValue(rgbcolor)*intensity/2,
|
||||||
|
GetBValue(rgbcolor)*intensity/2));
|
||||||
RECT smallRect = {0};
|
RECT smallRect = {0};
|
||||||
smallRect.left = rect->left + 1;
|
smallRect.left = rect->left + 1;
|
||||||
smallRect.top = rect->top + 1;
|
smallRect.top = rect->top + 1;
|
||||||
@@ -969,12 +993,15 @@ paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
|
|||||||
FillRect(data->backBufferDC, &smallRect, brush);
|
FillRect(data->backBufferDC, &smallRect, brush);
|
||||||
DeleteObject(brush);
|
DeleteObject(brush);
|
||||||
} else {
|
} else {
|
||||||
DrawTextW(data->backBufferDC, &wch, 1, rect,
|
SelectObject(data->backBufferDC, data->hMapFontUnicode);
|
||||||
|
DrawTextW(data->backBufferDC, wch, -1, rect,
|
||||||
DT_CENTER | DT_VCENTER | DT_NOPREFIX
|
DT_CENTER | DT_VCENTER | DT_NOPREFIX
|
||||||
| DT_SINGLELINE);
|
| DT_SINGLELINE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DrawTextA(data->backBufferDC, &ch, 1, rect,
|
char ch8 = (char) ch;
|
||||||
|
SelectObject(data->backBufferDC, data->hMapFont);
|
||||||
|
DrawTextA(data->backBufferDC, &ch8, 1, rect,
|
||||||
DT_CENTER | DT_VCENTER | DT_NOPREFIX
|
DT_CENTER | DT_VCENTER | DT_NOPREFIX
|
||||||
| DT_SINGLELINE);
|
| DT_SINGLELINE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ struct window_procs mswin_procs = {
|
|||||||
| WC_SPLASH_SCREEN | WC_POPUP_DIALOG | WC_MOUSE_SUPPORT,
|
| WC_SPLASH_SCREEN | WC_POPUP_DIALOG | WC_MOUSE_SUPPORT,
|
||||||
#ifdef STATUS_HILITES
|
#ifdef STATUS_HILITES
|
||||||
WC2_HITPOINTBAR | WC2_FLUSH_STATUS | WC2_RESET_STATUS | WC2_HILITE_STATUS |
|
WC2_HITPOINTBAR | WC2_FLUSH_STATUS | WC2_RESET_STATUS | WC2_HILITE_STATUS |
|
||||||
|
#endif
|
||||||
|
#ifdef ENHANCED_SYMBOLS
|
||||||
|
WC2_U_UTF8STR | WC2_U_24BITCOLOR |
|
||||||
#endif
|
#endif
|
||||||
0L,
|
0L,
|
||||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* color availability */
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* color availability */
|
||||||
|
|||||||
Reference in New Issue
Block a user