From d6e43a32ecaff6119b975e6be73f1e5f542e6e40 Mon Sep 17 00:00:00 2001 From: Alex Kompel Date: Sun, 18 Mar 2018 21:57:38 -0700 Subject: [PATCH] win32-gui: fix truncated status fields call to get dimensions of the text bounding rectangle needs to be made after the font is set in order to get the accurate reading --- win/win32/mhstatus.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/win/win32/mhstatus.c b/win/win32/mhstatus.c index a362c60bd..52d24621a 100644 --- a/win/win32/mhstatus.c +++ b/win/win32/mhstatus.c @@ -2,6 +2,7 @@ /* Copyright (C) 2001 by Alex Kompel */ /* NetHack may be freely redistributed. See license for details. */ +#include #include "winMS.h" #include "mhstatus.h" #include "mhmsg.h" @@ -352,16 +353,21 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam) : status_fg_color)); nBg = status_bg_color; - GetTextExtentPoint32(hdc, wbuf, vlen, &sz); + sz.cy = -1; if (*f == BL_TITLE && iflags.wc2_hitpointbar) { HBRUSH back_brush = CreateSolidBrush(nhcolor_to_RGB(hpbar_color)); RECT barrect; - /* first draw title normally */ + /* prepare for drawing */ SelectObject(hdc, fnt); SetBkMode(hdc, OPAQUE); SetBkColor(hdc, status_bg_color); SetTextColor(hdc, nhcolor_to_RGB(hpbar_color)); + + /* get bounding rectangle */ + GetTextExtentPoint32(hdc, wbuf, vlen, &sz); + + /* first draw title normally */ DrawText(hdc, wbuf, vlen, &rt, DT_LEFT); /* calc bar length */ @@ -386,12 +392,20 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam) nFg = nBg; nBg = tmp; } + + /* prepare for drawing */ SelectObject(hdc, fnt); SetBkMode(hdc, OPAQUE); SetBkColor(hdc, nBg); SetTextColor(hdc, nFg); + + /* get bounding rectangle */ + GetTextExtentPoint32(hdc, wbuf, vlen, &sz); + + /* draw */ DrawText(hdc, wbuf, vlen, &rt, DT_LEFT); } + assert(sz.cy >= 0); rt.left += sz.cx; cy = max(cy, sz.cy);