From: nethack.allison Date: Wed, 6 Feb 2002 00:15:47 +0000 (+0000) Subject: Fixes from X-Git-Tag: MOVE2GIT~3251 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02e2c671ed1fdac2abfb02f0c34ac444143cdfc2;p=nethack Fixes from - added support for new options - fixed couple of typos in options.c - added sunken edge around message window - added capability to replace font in the font table (if we will want to change font sizes dynamically later) --- diff --git a/src/options.c b/src/options.c index 85356b098..40f4cd812 100644 --- a/src/options.c +++ b/src/options.c @@ -1904,6 +1904,7 @@ goodfruit: iflags.wc_tile_file = (char *)alloc(strlen(op) + 1); Strcpy(iflags.wc_tile_file, op); } + return; } /* WINCAP * tile_height:nn */ @@ -2531,10 +2532,10 @@ char *buf; iflags.wc_align_message == ALIGN_RIGHT ? "right" : "unknown"); else if (!strcmp(optname,"align_status")) - Sprintf(buf, "%s", iflags.wc_align_message == ALIGN_TOP ? "top" : - iflags.wc_align_message == ALIGN_LEFT ? "left" : - iflags.wc_align_message == ALIGN_BOTTOM ? "bottom" : - iflags.wc_align_message == ALIGN_RIGHT ? "right" : + Sprintf(buf, "%s", iflags.wc_align_status == ALIGN_TOP ? "top" : + iflags.wc_align_status == ALIGN_LEFT ? "left" : + iflags.wc_align_status == ALIGN_BOTTOM ? "bottom" : + iflags.wc_align_status == ALIGN_RIGHT ? "right" : "unknown"); else if (!strcmp(optname,"align")) Sprintf(buf, "%s", rolestring(flags.initalign, aligns, adj)); diff --git a/win/win32/mhfont.c b/win/win32/mhfont.c index 3d0c77902..3e3d86eca 100644 --- a/win/win32/mhfont.c +++ b/win/win32/mhfont.c @@ -16,28 +16,36 @@ static int font_table_size = 0; #define NHFONT_CODE(win, attr) (((attr&0xFF)<<8)|(win_type&0xFF)) +static void __cdecl font_table_cleanup(void); /* create font based on window type, charater attributes and window device context */ -HGDIOBJ mswin_create_font(int win_type, int attr, HDC hdc) +HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace) { HFONT fnt = NULL; LOGFONT lgfnt; int font_size; - int i; + int font_index; + static BOOL once = FALSE; + + if( !once ) { + once = TRUE; + atexit(font_table_cleanup); + } ZeroMemory( &lgfnt, sizeof(lgfnt) ); /* try find font in the table */ - for(i=0; i=MAXFONTS ) panic( "font table overflow!" ); - - font_table[font_table_size].code = NHFONT_CODE(win_type, attr); - font_table[font_table_size].hFont = fnt; - font_table_size++; + if( font_index==font_table_size ) { + if( font_table_size>=MAXFONTS ) panic( "font table overflow!" ); + font_table_size++; + } else { + DeleteObject(font_table[font_index].hFont); + } + font_table[font_index].code = NHFONT_CODE(win_type, attr); + font_table[font_index].hFont = fnt; return fnt; } -/* dispose the font object */ -void mswin_destroy_font( HGDIOBJ fnt ) +void __cdecl font_table_cleanup(void) { - /* do nothing - we are going to reuse the font, - then it will destroyed when application exits - (at least I hope it will) */ - - /* if(fnt) DeleteObject(fnt); */ + int i; + for(i=0; iwindowlist[msg_param->wid].type == NHW_MAP ) - select_map_mode(GetNHApp()->mapDisplayMode); + select_map_mode(iflags.wc_map_mode); child = GetNHApp()->windowlist[msg_param->wid].win; if( child ) mswin_layout_main_window(child); @@ -347,8 +347,8 @@ void mswin_layout_main_window(HWND changed_child) /* set window positions */ SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, client_rt.bottom); - switch(GetNHApp()->winStatusAlign) { - case NHWND_ALIGN_LEFT: + switch(iflags.wc_align_status) { + case ALIGN_LEFT: status_size.cx = (wnd_rect.right-wnd_rect.left)/4; status_size.cy = (wnd_rect.bottom-wnd_rect.top); // that won't look good status_org.x = wnd_rect.left; @@ -356,7 +356,7 @@ void mswin_layout_main_window(HWND changed_child) wnd_rect.left += status_size.cx; break; - case NHWND_ALIGN_RIGHT: + case ALIGN_RIGHT: status_size.cx = (wnd_rect.right-wnd_rect.left)/4; status_size.cy = (wnd_rect.bottom-wnd_rect.top); // that won't look good status_org.x = wnd_rect.right - status_size.cx; @@ -364,14 +364,14 @@ void mswin_layout_main_window(HWND changed_child) wnd_rect.right -= status_size.cx; break; - case NHWND_ALIGN_TOP: + case ALIGN_TOP: status_size.cx = (wnd_rect.right-wnd_rect.left); status_org.x = wnd_rect.left; status_org.y = wnd_rect.top; wnd_rect.top += status_size.cy; break; - case NHWND_ALIGN_BOTTOM: + case ALIGN_BOTTOM: default: status_size.cx = (wnd_rect.right-wnd_rect.left); status_org.x = wnd_rect.left; @@ -380,8 +380,8 @@ void mswin_layout_main_window(HWND changed_child) break; } - switch(GetNHApp()->winMessageAlign) { - case NHWND_ALIGN_LEFT: + switch(iflags.wc_align_message) { + case ALIGN_LEFT: msg_size.cx = (wnd_rect.right-wnd_rect.left)/4; msg_size.cy = (wnd_rect.bottom-wnd_rect.top); msg_org.x = wnd_rect.left; @@ -389,7 +389,7 @@ void mswin_layout_main_window(HWND changed_child) wnd_rect.left += msg_size.cx; break; - case NHWND_ALIGN_RIGHT: + case ALIGN_RIGHT: msg_size.cx = (wnd_rect.right-wnd_rect.left)/4; msg_size.cy = (wnd_rect.bottom-wnd_rect.top); msg_org.x = wnd_rect.right - msg_size.cx; @@ -397,14 +397,14 @@ void mswin_layout_main_window(HWND changed_child) wnd_rect.right -= msg_size.cx; break; - case NHWND_ALIGN_TOP: + case ALIGN_TOP: msg_size.cx = (wnd_rect.right-wnd_rect.left); msg_org.x = wnd_rect.left; msg_org.y = wnd_rect.top; wnd_rect.top += msg_size.cy; break; - case NHWND_ALIGN_BOTTOM: + case ALIGN_BOTTOM: default: msg_size.cx = (wnd_rect.right-wnd_rect.left); msg_org.x = wnd_rect.left; @@ -615,7 +615,7 @@ void select_map_mode(int mode) if( Is_rogue_level(&u.uz) ) return; #endif - GetNHApp()->mapDisplayMode = mode; + iflags.wc_map_mode = mode; mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), mode); } @@ -624,17 +624,17 @@ static struct t_menu2mapmode { int mapMode; } _menu2mapmode[] = { - { IDM_MAP_TILES, NHMAP_VIEW_TILES }, - { IDM_MAP_ASCII4X6, NHMAP_VIEW_ASCII4x6 }, - { IDM_MAP_ASCII6X8, NHMAP_VIEW_ASCII6x8 }, - { IDM_MAP_ASCII8X8, NHMAP_VIEW_ASCII8x8 }, - { IDM_MAP_ASCII16X8, NHMAP_VIEW_ASCII16x8 }, - { IDM_MAP_ASCII7X12, NHMAP_VIEW_ASCII7x12 }, - { IDM_MAP_ASCII8X12, NHMAP_VIEW_ASCII8x12 }, - { IDM_MAP_ASCII12X16, NHMAP_VIEW_ASCII12x16 }, - { IDM_MAP_ASCII16X12, NHMAP_VIEW_ASCII16x12 }, - { IDM_MAP_ASCII10X18, NHMAP_VIEW_ASCII10x18 }, - { IDM_MAP_FIT_TO_SCREEN, NHMAP_VIEW_FIT_TO_SCREEN }, + { IDM_MAP_TILES, MAP_MODE_TILES }, + { IDM_MAP_ASCII4X6, MAP_MODE_ASCII4x6 }, + { IDM_MAP_ASCII6X8, MAP_MODE_ASCII6x8 }, + { IDM_MAP_ASCII8X8, MAP_MODE_ASCII8x8 }, + { IDM_MAP_ASCII16X8, MAP_MODE_ASCII16x8 }, + { IDM_MAP_ASCII7X12, MAP_MODE_ASCII7x12 }, + { IDM_MAP_ASCII8X12, MAP_MODE_ASCII8x12 }, + { IDM_MAP_ASCII12X16, MAP_MODE_ASCII16x12 }, + { IDM_MAP_ASCII16X12, MAP_MODE_ASCII12x16 }, + { IDM_MAP_ASCII10X18, MAP_MODE_ASCII10x18 }, + { IDM_MAP_FIT_TO_SCREEN, MAP_MODE_ASCII_FIT_TO_SCREEN }, { -1, -1 } }; diff --git a/win/win32/mhmain.h b/win/win32/mhmain.h index 21e941063..a993db822 100644 --- a/win/win32/mhmain.h +++ b/win/win32/mhmain.h @@ -8,11 +8,6 @@ #include "winMS.h" -#define NHWND_ALIGN_LEFT 0 -#define NHWND_ALIGN_RIGHT 1 -#define NHWND_ALIGN_TOP 2 -#define NHWND_ALIGN_BOTTOM 3 - HWND mswin_init_main_window (void); void mswin_layout_main_window(HWND changed_child); diff --git a/win/win32/mhmap.c b/win/win32/mhmap.c index 58d94e203..c6f6e53c4 100644 --- a/win/win32/mhmap.c +++ b/win/win32/mhmap.c @@ -91,8 +91,8 @@ void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) /* set new screen tile size */ data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA); - data->xScrTile = ((data->mapMode==NHMAP_VIEW_FIT_TO_SCREEN)? wnd_size.cx : lpsz->cx) / COLNO; - data->yScrTile = ((data->mapMode==NHMAP_VIEW_FIT_TO_SCREEN)? wnd_size.cy : lpsz->cy) / ROWNO; + data->xScrTile = ((data->mapMode==MAP_MODE_ASCII_FIT_TO_SCREEN)? wnd_size.cx : lpsz->cx) / COLNO; + data->yScrTile = ((data->mapMode==MAP_MODE_ASCII_FIT_TO_SCREEN)? wnd_size.cy : lpsz->cy) / ROWNO; /* set map origin point */ data->map_orig.x = max(0, client_rt.left + (wnd_size.cx - data->xScrTile*COLNO)/2 ); @@ -102,7 +102,7 @@ void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) data->map_orig.y -= data->map_orig.y % data->yScrTile; /* adjust horizontal scroll bar */ - if( data->mapMode==NHMAP_VIEW_FIT_TO_SCREEN ) + if( data->mapMode==MAP_MODE_ASCII_FIT_TO_SCREEN ) data->xPageSize = COLNO+1; /* disable scroll bar */ else data->xPageSize = wnd_size.cx/data->xScrTile; @@ -124,7 +124,7 @@ void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); /* adjust vertical scroll bar */ - if( data->mapMode==NHMAP_VIEW_FIT_TO_SCREEN ) + if( data->mapMode==MAP_MODE_ASCII_FIT_TO_SCREEN ) data->yPageSize = ROWNO+1; /* disable scroll bar */ else data->yPageSize = wnd_size.cy/data->yScrTile; @@ -184,61 +184,61 @@ int mswin_map_mode(HWND hWnd, int mode) switch( data->mapMode ) { - case NHMAP_VIEW_ASCII4x6: + case MAP_MODE_ASCII4x6: data->bAsciiMode = TRUE; mapSize.cx = 4*COLNO; mapSize.cy = 6*ROWNO; break; - case NHMAP_VIEW_ASCII6x8: + case MAP_MODE_ASCII6x8: data->bAsciiMode = TRUE; mapSize.cx = 6*COLNO; mapSize.cy = 8*ROWNO; break; - case NHMAP_VIEW_ASCII8x8: + case MAP_MODE_ASCII8x8: data->bAsciiMode = TRUE; mapSize.cx = 8*COLNO; mapSize.cy = 8*ROWNO; break; - case NHMAP_VIEW_ASCII16x8: + case MAP_MODE_ASCII16x8: data->bAsciiMode = TRUE; mapSize.cx = 16*COLNO; mapSize.cy = 8*ROWNO; break; - case NHMAP_VIEW_ASCII7x12: + case MAP_MODE_ASCII7x12: data->bAsciiMode = TRUE; mapSize.cx = 7*COLNO; mapSize.cy = 12*ROWNO; break; - case NHMAP_VIEW_ASCII8x12: + case MAP_MODE_ASCII8x12: data->bAsciiMode = TRUE; mapSize.cx = 8*COLNO; mapSize.cy = 12*ROWNO; break; - case NHMAP_VIEW_ASCII16x12: + case MAP_MODE_ASCII16x12: data->bAsciiMode = TRUE; mapSize.cx = 16*COLNO; mapSize.cy = 12*ROWNO; break; - case NHMAP_VIEW_ASCII12x16: + case MAP_MODE_ASCII12x16: data->bAsciiMode = TRUE; mapSize.cx = 12*COLNO; mapSize.cy = 16*ROWNO; break; - case NHMAP_VIEW_ASCII10x18: + case MAP_MODE_ASCII10x18: data->bAsciiMode = TRUE; mapSize.cx = 10*COLNO; mapSize.cy = 18*ROWNO; break; - case NHMAP_VIEW_FIT_TO_SCREEN: { + case MAP_MODE_ASCII_FIT_TO_SCREEN: { RECT client_rt; GetClientRect(hWnd, &client_rt); mapSize.cx = client_rt.right - client_rt.left; @@ -247,11 +247,11 @@ int mswin_map_mode(HWND hWnd, int mode) data->bAsciiMode = TRUE; } break; - case NHMAP_VIEW_TILES: + case MAP_MODE_TILES: default: data->bAsciiMode = FALSE; - mapSize.cx = TILE_X*COLNO; - mapSize.cy = TILE_Y*ROWNO; + mapSize.cx = GetNHApp()->mapTile_X*COLNO; + mapSize.cy = GetNHApp()->mapTile_Y*ROWNO; break; } @@ -320,7 +320,7 @@ LRESULT CALLBACK MapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara { SIZE size; - if( data->mapMode == NHMAP_VIEW_FIT_TO_SCREEN ) { + if( data->mapMode == MAP_MODE_ASCII_FIT_TO_SCREEN ) { size.cx = LOWORD(lParam); size.cy = HIWORD(lParam); } else { @@ -384,7 +384,7 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) PMSNHMsgClipAround msg_data = (PMSNHMsgClipAround)lParam; int x, y; BOOL scroll_x, scroll_y; - int mcam = GetNHApp()->mapCliparoundMargin; + int mcam = iflags.wc_scroll_margin; /* calculate if you should clip around */ scroll_x = @@ -481,8 +481,8 @@ void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) data->bAsciiMode = FALSE; - data->xScrTile = TILE_X; - data->yScrTile = TILE_Y; + data->xScrTile = GetNHApp()->mapTile_X; + data->yScrTile = GetNHApp()->mapTile_Y; SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); } @@ -554,7 +554,7 @@ void onPaint(HWND hWnd) } else { /* prepare tiles DC for mapping */ tileDC = CreateCompatibleDC(hDC); - saveBmp = SelectObject(tileDC, GetNHApp()->bmpTiles); + saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); /* draw the map */ for(i=paint_rt.left; imap[i][j] ]; - t_x = (ntile % TILES_PER_LINE)*TILE_X; - t_y = (ntile / TILES_PER_LINE)*TILE_Y; + t_x = (ntile % GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_X; + t_y = (ntile / GetNHApp()->mapTilesPerLine)*GetNHApp()->mapTile_Y; nhcoord2display(data, i, j, &glyph_rect); @@ -579,11 +579,11 @@ void onPaint(HWND hWnd) tileDC, t_x, t_y, - TILE_X, - TILE_Y, + GetNHApp()->mapTile_X, + GetNHApp()->mapTile_Y, SRCCOPY ); - if( glyph_is_pet(data->map[i][j]) && iflags.hilite_pet ) { + if( glyph_is_pet(data->map[i][j]) && iflags.wc_hilite_pet ) { /* apply pet mark transparently over pet image */ HDC hdcPetMark; diff --git a/win/win32/mhmap.h b/win/win32/mhmap.h index 5c4d438d5..4490ca018 100644 --- a/win/win32/mhmap.h +++ b/win/win32/mhmap.h @@ -12,21 +12,9 @@ HWND mswin_init_map_window (void); void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw); -#define NHMAP_VIEW_TILES 0 -#define NHMAP_VIEW_ASCII4x6 1 -#define NHMAP_VIEW_ASCII6x8 2 -#define NHMAP_VIEW_ASCII8x8 3 -#define NHMAP_VIEW_ASCII16x8 4 -#define NHMAP_VIEW_ASCII7x12 5 -#define NHMAP_VIEW_ASCII8x12 6 -#define NHMAP_VIEW_ASCII16x12 7 -#define NHMAP_VIEW_ASCII12x16 8 -#define NHMAP_VIEW_ASCII10x18 9 -#define NHMAP_VIEW_FIT_TO_SCREEN 10 - int mswin_map_mode(HWND hWnd, int mode); -#define ROGUE_LEVEL_MAP_MODE NHMAP_VIEW_ASCII12x16 +#define ROGUE_LEVEL_MAP_MODE MAP_MODE_ASCII12x16 #define DEF_CLIPAROUND_MARGIN 5 diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 3c1fe47af..5ccad265c 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -223,6 +223,8 @@ int mswin_menu_window_select_menu (HWND hWnd, int how, MENU_ITEM_P ** _selected) BOOL CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PNHMenuWindow data; + HWND control; + HDC hdc; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); switch (message) @@ -239,9 +241,15 @@ BOOL CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) data->bmpNotChecked = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_UNSEL)); SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); + /* set font for the text cotrol */ + control = GetDlgItem(hWnd, IDC_MENU_TEXT); + hdc = GetDC(control); + SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE), (LPARAM)0); + ReleaseDC(control, hdc); + /* subclass edit control */ - editControlWndProc = (WNDPROC)GetWindowLong(GetDlgItem(hWnd, IDC_MENU_TEXT), GWL_WNDPROC); - SetWindowLong(GetDlgItem(hWnd, IDC_MENU_TEXT), GWL_WNDPROC, (LONG)NHMenuTextWndProc); + editControlWndProc = (WNDPROC)GetWindowLong(control, GWL_WNDPROC); + SetWindowLong(control, GWL_WNDPROC, (LONG)NHMenuTextWndProc); break; case WM_MSNH_COMMAND: @@ -667,14 +675,14 @@ BOOL onMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam) GetClientRect(GetMenuControl(hWnd), &list_rect); hdc = GetDC(GetMenuControl(hWnd)); - saveFont = SelectObject(hdc, mswin_create_font(NHW_MENU, ATR_INVERSE, hdc)); + saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, FALSE)); GetTextMetrics(hdc, &tm); /* Set the height of the list box items. */ lpmis->itemHeight = max(tm.tmHeight, TILE_Y)+2; lpmis->itemWidth = list_rect.right - list_rect.left; - mswin_destroy_font(SelectObject(hdc, saveFont)); + SelectObject(hdc, saveFont); ReleaseDC(GetMenuControl(hWnd), hdc); return TRUE; } @@ -703,7 +711,7 @@ BOOL onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) item = &data->menu.items[lpdis->itemID]; tileDC = CreateCompatibleDC(lpdis->hDC); - saveFont = SelectObject(lpdis->hDC, mswin_create_font(NHW_MENU, item->attr, lpdis->hDC)); + saveFont = SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); GetTextMetrics(lpdis->hDC, &tm); x = lpdis->rcItem.left + 1; @@ -776,7 +784,7 @@ BOOL onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) _stprintf(wbuf, TEXT("Count: %d"), data->menu.items[lpdis->itemID].count ); } - SelectObject(lpdis->hDC, mswin_create_font(NHW_MENU, ATR_BLINK, lpdis->hDC)); + SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, lpdis->hDC, FALSE)); /* calculate text rectangle */ SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); @@ -800,7 +808,7 @@ BOOL onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) DrawFocusRect(lpdis->hDC, &drawRect); } - mswin_destroy_font(SelectObject(lpdis->hDC, saveFont)); + SelectObject(lpdis->hDC, saveFont); DeleteDC(tileDC); return TRUE; } @@ -1075,30 +1083,43 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) void mswin_menu_window_size (HWND hWnd, LPSIZE sz) { TEXTMETRIC tm; + HWND control; HGDIOBJ saveFont; HDC hdc; PNHMenuWindow data; int i; RECT rt; - GetWindowRect(hWnd, &rt); + GetClientRect(hWnd, &rt); sz->cx = rt.right - rt.left; sz->cy = rt.bottom - rt.top; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); - if(data && data->type==MENU_TYPE_MENU ) { - hdc = GetDC(GetMenuControl(hWnd)); - saveFont = SelectObject(hdc, mswin_create_font(NHW_MENU, ATR_NONE, hdc)); - GetTextMetrics(hdc, &tm); - - /* Set the height of the list box items. */ - for(i=0; imenu.size; i++ ) { - sz->cx = max(sz->cx, - (LONG)(2*TILE_X + tm.tmMaxCharWidth*(strlen(data->menu.items[i].str)+10))); + if(data) { + control = GetMenuControl(hWnd); + hdc = GetDC(control); + + if( data->type==MENU_TYPE_MENU ) { + /* Set the height of the list box items. */ + saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); + GetTextMetrics(hdc, &tm); + for(i=0; imenu.size; i++ ) { + sz->cx = max(sz->cx, + (LONG)(2*TILE_X + tm.tmAveCharWidth*(strlen(data->menu.items[i].str)+12) + tm.tmOverhang)); + } + SelectObject(hdc, saveFont); + } else { + RECT text_rt; + saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); + GetTextMetrics(hdc, &tm); + SetRect(&text_rt, 0, 0, sz->cx, sz->cy); + DrawText(hdc, data->text.text, _tcslen(data->text.text), &text_rt, DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX); + sz->cx = max(sz->cx, text_rt.right - text_rt.left + 5*tm.tmAveCharWidth + tm.tmOverhang); + SelectObject(hdc, saveFont); } + sz->cx += GetSystemMetrics(SM_CXVSCROLL) + 2*GetSystemMetrics(SM_CXSIZEFRAME); - mswin_destroy_font(SelectObject(hdc, saveFont)); - ReleaseDC(GetMenuControl(hWnd), hdc); + ReleaseDC(control, hdc); } } diff --git a/win/win32/mhmsgwnd.c b/win/win32/mhmsgwnd.c index 5906f33a7..5dddd58cd 100644 --- a/win/win32/mhmsgwnd.c +++ b/win/win32/mhmsgwnd.c @@ -61,7 +61,8 @@ HWND mswin_init_message_window () { style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL; #endif - ret = CreateWindow( + ret = CreateWindowEx( + WS_EX_CLIENTEDGE, szMessageWindowClass, /* registered class name */ NULL, /* window name */ style, /* window style */ @@ -422,7 +423,6 @@ void onPaint(HWND hWnd) x = data->xChar * (4 - data->xPos); } - if( strlen(data->window_text[i].text)>0 ) { /* convert to UNICODE */ NH_A2W(data->window_text[i].text, wbuf, sizeof(wbuf)); @@ -434,7 +434,7 @@ void onPaint(HWND hWnd) draw_rt.top = y - data->yChar; draw_rt.bottom = y; - oldFont = SelectObject(hdc, mswin_create_font(NHW_MESSAGE, data->window_text[i].attr, hdc)); + oldFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, data->window_text[i].attr, hdc, FALSE)); #ifdef MSG_WRAP_TEXT DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); @@ -444,7 +444,7 @@ void onPaint(HWND hWnd) #else DrawText(hdc, wbuf, wlen, &draw_rt, DT_NOPREFIX ); #endif - mswin_destroy_font(SelectObject(hdc, oldFont)); + SelectObject(hdc, oldFont); y -= draw_rt.bottom - draw_rt.top; } else { @@ -487,7 +487,7 @@ void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) /* Get the handle to the client area's device context. */ hdc = prepareDC( GetDC(hWnd) ); - saveFont = SelectObject(hdc, mswin_create_font(NHW_MESSAGE, ATR_NONE, hdc)); + saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); /* Extract font dimensions from the text metrics. */ GetTextMetrics (hdc, &tm); @@ -497,7 +497,7 @@ void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) data->xPage = 1; /* Free the device context. */ - mswin_destroy_font(SelectObject(hdc, saveFont)); + SelectObject(hdc, saveFont); ReleaseDC (hWnd, hdc); } diff --git a/win/win32/mhstatus.c b/win/win32/mhstatus.c index 4b521c28e..e9a141666 100644 --- a/win/win32/mhstatus.c +++ b/win/win32/mhstatus.c @@ -111,7 +111,7 @@ LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rt); - oldFont = SelectObject(hdc, mswin_create_font(NHW_STATUS, ATR_NONE, hdc)); + oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); for(i=0; iwindow_text[i], wbuf, sizeof(wbuf)), strlen(data->window_text[i]), &sz); @@ -120,7 +120,7 @@ LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP rt.top += sz.cy; } - mswin_destroy_font(SelectObject(hdc, oldFont)); + SelectObject(hdc, oldFont); EndPaint(hWnd, &ps); } break; @@ -154,12 +154,12 @@ void mswin_status_window_size (HWND hWnd, LPSIZE sz) data = (PNHStatusWindow)GetWindowLong(hWnd, GWL_USERDATA); if(data) { hdc = GetDC(hWnd); - saveFont = SelectObject(hdc, mswin_create_font(NHW_STATUS, ATR_NONE, hdc)); + saveFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); GetTextMetrics(hdc, &tm); sz->cy = tm.tmHeight * NHSW_LINES; - mswin_destroy_font(SelectObject(hdc, saveFont)); + SelectObject(hdc, saveFont); ReleaseDC(hWnd, hdc); } } \ No newline at end of file diff --git a/win/win32/mhtext.c b/win/win32/mhtext.c index 527d11783..0ca9b72e1 100644 --- a/win/win32/mhtext.c +++ b/win/win32/mhtext.c @@ -92,7 +92,7 @@ BOOL CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara } hdc = GetDC(control); - SendMessage(control, WM_SETFONT, (WPARAM)mswin_create_font(NHW_TEXT, ATR_NONE, hdc), 0); + SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); ReleaseDC(control, hdc); /* subclass edit control */ diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index fbb93945e..d1e65ed2d 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -34,7 +34,10 @@ static void mswin_main_loop(void); struct window_procs mswin_procs = { "MSWIN", WC_COLOR|WC_HILITE_PET|WC_ALIGN_MESSAGE|WC_ALIGN_STATUS| - WC_INVERSE|WC_SCROLL_MARGIN|WC_MAP_MODE, + WC_INVERSE|WC_SCROLL_MARGIN|WC_MAP_MODE| + WC_FONT_MESSAGE|WC_FONT_STATUS|WC_FONT_MENU|WC_FONT_TEXT| + WC_FONTSIZ_MESSAGE|WC_FONTSIZ_STATUS|WC_FONTSIZ_MENU|WC_FONTSIZ_TEXT| + WC_TILE_WIDTH|WC_TILE_HEIGHT|WC_TILE_FILE, mswin_init_nhwindows, mswin_player_selection, mswin_askname, @@ -268,7 +271,7 @@ void mswin_clear_nhwindow(winid wid) if( Is_rogue_level(&u.uz) ) mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), ROGUE_LEVEL_MAP_MODE); else - mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), GetNHApp()->mapDisplayMode); + mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), iflags.wc_map_mode); #endif } @@ -869,7 +872,7 @@ char mswin_yn_function(const char *question, const char *choices, ((def == 'y') ? MB_DEFBUTTON1 : (def == 'n') ? MB_DEFBUTTON2 : MB_DEFBUTTON3)); free(text); - GetNHApp()->saved_text = strdup(TEXT("")); + GetNHApp()->saved_text = strdup(""); return box_result == IDYES ? 'y' : box_result == IDNO ? 'n' : '\033'; } diff --git a/win/win32/winMS.h b/win/win32/winMS.h index 7645e0de0..e4ff79d73 100644 --- a/win/win32/winMS.h +++ b/win/win32/winMS.h @@ -28,6 +28,11 @@ /* tile background color */ #define TILE_BK_COLOR RGB(71, 108, 108) +/* minimum/maximum font size (in points - 1/72 inch) */ +#define NHFONT_DEFAULT_SIZE 9 +#define NHFONT_SIZE_MIN 3 +#define NHFONT_SIZE_MAX 20 + typedef struct mswin_nhwindow_data { HWND win; int type; @@ -44,16 +49,15 @@ typedef struct mswin_nhwindow_app { HBITMAP bmpTiles; HBITMAP bmpPetMark; + HBITMAP bmpMapTiles; /* custom tiles bitmap */ + int mapTile_X; /* tile width */ + int mapTile_Y; /* tile height */ + int mapTilesPerLine; /* number of tile per row in the bitmap */ boolean bNoHScroll; /* disable cliparound for horizontal grid (map) */ boolean bNoVScroll; /* disable cliparound for vertical grid (map) */ - int mapDisplayMode; /* regular map display mode */ int mapDisplayModeSave; /* saved map display mode */ - int mapCliparoundMargin; /* when to scroll display */ - - int winStatusAlign; /* alignment of the status window */ - int winMessageAlign; /* alignment of the status window */ char* saved_text; } NHWinApp, *PNHWinApp; diff --git a/win/win32/winhack.c b/win/win32/winhack.c index 87c84dfeb..41495fbf7 100644 --- a/win/win32/winhack.c +++ b/win/win32/winhack.c @@ -31,6 +31,7 @@ BOOL InitInstance(HINSTANCE, int); extern void FDECL(pcmain, (int,char **)); static void __cdecl mswin_moveloop(void *); +static BOOL initMapTiles(void); #define MAX_CMDLINE_PARAM 255 @@ -56,13 +57,14 @@ int APIENTRY WinMain(HINSTANCE hInstance, if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap"); _nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK)); if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap"); + _nethack_app.bmpMapTiles = _nethack_app.bmpTiles; + _nethack_app.mapTile_X = TILE_X; + _nethack_app.mapTile_Y = TILE_Y; + _nethack_app.mapTilesPerLine = TILES_PER_LINE; + _nethack_app.bNoHScroll = FALSE; _nethack_app.bNoVScroll = FALSE; - _nethack_app.mapDisplayMode = NHMAP_VIEW_TILES; - _nethack_app.winStatusAlign = NHWND_ALIGN_BOTTOM; - _nethack_app.winMessageAlign = NHWND_ALIGN_TOP; - _nethack_app.mapCliparoundMargin = DEF_CLIPAROUND_MARGIN; - _nethack_app.saved_text = strdup(TEXT("")); + _nethack_app.saved_text = strdup(""); // init controls ZeroMemory(&InitCtrls, sizeof(InitCtrls)); @@ -92,6 +94,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, pcmain(argc,argv); + /* initialize map tiles bitmap */ + initMapTiles(); + moveloop(); return 0; @@ -131,70 +136,66 @@ PNHWinApp GetNHApp() return &_nethack_app; } -/* options */ -struct t_win32_opt_int { - const char* val; - int opt; -}; -static struct t_win32_opt_int _win32_map_mode[] = -{ - { "tiles", NHMAP_VIEW_TILES }, - { "ascii4x6", NHMAP_VIEW_ASCII4x6 }, - { "ascii6x8", NHMAP_VIEW_ASCII6x8 }, - { "ascii8x8", NHMAP_VIEW_ASCII8x8 }, - { "ascii16x8", NHMAP_VIEW_ASCII16x8 }, - { "ascii7x12", NHMAP_VIEW_ASCII7x12 }, - { "ascii8x12", NHMAP_VIEW_ASCII8x12 }, - { "ascii16x12", NHMAP_VIEW_ASCII16x12 }, - { "ascii12x16", NHMAP_VIEW_ASCII12x16 }, - { "ascii10x18", NHMAP_VIEW_ASCII10x18 }, - { "fit_to_screen", NHMAP_VIEW_FIT_TO_SCREEN }, - { NULL, -1 } -}; - -static struct t_win32_opt_int _win32_align[] = +BOOL initMapTiles(void) { - { "left", NHWND_ALIGN_LEFT }, - { "right", NHWND_ALIGN_RIGHT }, - { "top", NHWND_ALIGN_TOP }, - { "bottom", NHWND_ALIGN_BOTTOM }, - { NULL, -1 } -}; - -int set_win32_option( const char * name, const char * val) -{ - struct t_win32_opt_int* p; - if( _stricmp(name, "win32_map_mode")==0 ) { - for( p=_win32_map_mode; p->val; p++ ) { - if( _stricmp(p->val, val)==0 ){ - GetNHApp()->mapDisplayMode = p->opt; - return 1; - } - } - return 0; - } else if( _stricmp(name, "win32_align_status")==0 ) { - for( p=_win32_align; p->val; p++ ) { - if( _stricmp(p->val, val)==0 ) { - GetNHApp()->winStatusAlign = p->opt; - return 1; - } - } - return 0; - } else if( _stricmp(name, "win32_align_message")==0 ) { - for( p=_win32_align; p->val; p++ ) { - if( _stricmp(p->val, val)==0 ) { - GetNHApp()->winMessageAlign = p->opt; - return 1; - } - } - return 0; - } else if( _stricmp(name, "win32_map_cliparound_margin")==0 ) { - int tmp = atoi(val); - /* Alex, this range should be revisited and groundtruthed */ - if( tmp >= DEF_CLIPAROUND_MARGIN && tmp < COLNO/2) { - GetNHApp()->mapCliparoundMargin = tmp; - return 1; - } + HBITMAP hBmp; + BITMAP bm; + TCHAR wbuf[MAX_PATH]; + int tl_num; + SIZE map_size; + extern int total_tiles_used; + + /* no file - no tile */ + if( !(iflags.wc_tile_file && *iflags.wc_tile_file) ) + return TRUE; + + /* load bitmap */ + hBmp = LoadImage( + GetNHApp()->hApp, + NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH), + IMAGE_BITMAP, + 0, + 0, + LR_LOADFROMFILE | LR_DEFAULTSIZE + ); + if( hBmp==NULL ) { + raw_print("Cannot load tiles from the file. Reverting back to default."); + return FALSE; } - return 0; + + /* calculate tile dimensions */ + GetObject(hBmp, sizeof(BITMAP), (LPVOID)&bm); + if( bm.bmWidth%iflags.wc_tile_width || + bm.bmHeight%iflags.wc_tile_height ) { + DeleteObject(hBmp); + raw_print("Tiles bitmap does not match tile_width and tile_height options. Reverting back to default."); + return FALSE; + } + + tl_num = (bm.bmWidth/iflags.wc_tile_width)* + (bm.bmHeight/iflags.wc_tile_height); + if( tl_numbmpMapTiles!=GetNHApp()->bmpTiles ) { + DeleteObject(GetNHApp()->bmpMapTiles); + } + + GetNHApp()->bmpMapTiles = hBmp; + GetNHApp()->mapTile_X = iflags.wc_tile_width; + GetNHApp()->mapTile_Y = iflags.wc_tile_height; + GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width; + + map_size.cx = GetNHApp()->mapTile_X * COLNO; + map_size.cy = GetNHApp()->mapTile_Y * ROWNO; + mswin_map_stretch( + mswin_hwnd_from_winid(WIN_MAP), + &map_size, + TRUE + ); + return TRUE; }