B08002 - win32gui: message window sizing (from <Someone>)
>>> - When I set font and font size of the message window, the >>> message window size doesn't calculate correctly to show the >>> number of message lines specified. For example, I set the font >>> size to 6, and the number of messages to display to 8. Now >>> there is whitespace at the top of my message window. When I >>> set the font size to 14 now, I see only 5.5 message lines. >>> This is unintuitive: the interface should recalculate the >>> window size needed to display the correct number of lines. >>> >> I agree, especially since the message window size is >> recalculated correctly if you save and restore. An easy way out >> would be to set those options to DISP_IN_GAME. > > That seems like a good work-around until the proper fix is done. The patch is attached. I moved the code that was computing the font size to mswin_message_window_size(). This will cause the message window to resize properly if the message font size changes. There are also 2 minor bits in mswproc.c to invalidate the message window when the font changes.
This commit is contained in:
@@ -60,7 +60,6 @@ static void onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam);
|
|||||||
static COLORREF setMsgTextColor(HDC hdc, int gray);
|
static COLORREF setMsgTextColor(HDC hdc, int gray);
|
||||||
static void onPaint(HWND hWnd);
|
static void onPaint(HWND hWnd);
|
||||||
static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam);
|
static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam);
|
||||||
static HDC prepareDC( HDC hdc );
|
|
||||||
|
|
||||||
HWND mswin_init_message_window () {
|
HWND mswin_init_message_window () {
|
||||||
static int run_once = 0;
|
static int run_once = 0;
|
||||||
@@ -679,10 +678,8 @@ void onPaint(HWND hWnd)
|
|||||||
|
|
||||||
void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
HDC hdc;
|
|
||||||
TEXTMETRIC tm;
|
|
||||||
PNHMessageWindow data;
|
PNHMessageWindow data;
|
||||||
HGDIOBJ saveFont;
|
SIZE dummy;
|
||||||
|
|
||||||
/* set window data */
|
/* set window data */
|
||||||
data = (PNHMessageWindow)malloc(sizeof(NHMessageWindow));
|
data = (PNHMessageWindow)malloc(sizeof(NHMessageWindow));
|
||||||
@@ -691,8 +688,24 @@ void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
|||||||
data->max_text = MAXWINDOWTEXT;
|
data->max_text = MAXWINDOWTEXT;
|
||||||
SetWindowLong(hWnd, GWL_USERDATA, (LONG)data);
|
SetWindowLong(hWnd, GWL_USERDATA, (LONG)data);
|
||||||
|
|
||||||
|
/* re-calculate window size (+ font size) */
|
||||||
|
mswin_message_window_size(hWnd, &dummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mswin_message_window_size (HWND hWnd, LPSIZE sz)
|
||||||
|
{
|
||||||
|
HDC hdc;
|
||||||
|
HGDIOBJ saveFont;
|
||||||
|
TEXTMETRIC tm;
|
||||||
|
PNHMessageWindow data;
|
||||||
|
RECT rt, client_rt;
|
||||||
|
|
||||||
|
data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA);
|
||||||
|
if( !data ) return;
|
||||||
|
|
||||||
|
/* -- Calculate the font size -- */
|
||||||
/* Get the handle to the client area's device context. */
|
/* Get the handle to the client area's device context. */
|
||||||
hdc = prepareDC( GetDC(hWnd) );
|
hdc = GetDC(hWnd);
|
||||||
saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE));
|
saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE));
|
||||||
|
|
||||||
/* Extract font dimensions from the text metrics. */
|
/* Extract font dimensions from the text metrics. */
|
||||||
@@ -705,31 +718,15 @@ void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
|||||||
/* Free the device context. */
|
/* Free the device context. */
|
||||||
SelectObject(hdc, saveFont);
|
SelectObject(hdc, saveFont);
|
||||||
ReleaseDC (hWnd, hdc);
|
ReleaseDC (hWnd, hdc);
|
||||||
}
|
|
||||||
|
|
||||||
HDC prepareDC( HDC hdc )
|
|
||||||
{
|
|
||||||
// set font here
|
|
||||||
return hdc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void mswin_message_window_size (HWND hWnd, LPSIZE sz)
|
|
||||||
{
|
|
||||||
PNHMessageWindow data;
|
|
||||||
RECT rt, client_rt;
|
|
||||||
|
|
||||||
|
/* -- calculate window size -- */
|
||||||
GetWindowRect(hWnd, &rt);
|
GetWindowRect(hWnd, &rt);
|
||||||
|
|
||||||
sz->cx = rt.right - rt.left;
|
sz->cx = rt.right - rt.left;
|
||||||
sz->cy = rt.bottom - rt.top;
|
sz->cy = rt.bottom - rt.top;
|
||||||
|
|
||||||
data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA);
|
/* set size to accomodate MSG_VISIBLE_LINES and
|
||||||
if(data) {
|
horizontal scroll bar (difference between window rect and client rect */
|
||||||
/* set size to accomodate MSG_VISIBLE_LINES, highligh rectangle and
|
GetClientRect(hWnd, &client_rt);
|
||||||
horizontal scroll bar (difference between window rect and client rect */
|
sz->cy = sz->cy - (client_rt.bottom - client_rt.top) +
|
||||||
GetClientRect(hWnd, &client_rt);
|
data->yChar * MSG_VISIBLE_LINES;
|
||||||
sz->cy = sz->cy-(client_rt.bottom - client_rt.top) +
|
|
||||||
data->yChar * MSG_VISIBLE_LINES + 4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1782,6 +1782,7 @@ void mswin_preference_update(const char *pref)
|
|||||||
mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE);
|
mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE);
|
||||||
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
||||||
|
|
||||||
|
InvalidateRect(mswin_hwnd_from_winid(WIN_STATUS), NULL, TRUE);
|
||||||
mswin_layout_main_window(NULL);
|
mswin_layout_main_window(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1802,6 +1803,7 @@ void mswin_preference_update(const char *pref)
|
|||||||
mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE);
|
mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE);
|
||||||
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
||||||
|
|
||||||
|
InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE);
|
||||||
mswin_layout_main_window(NULL);
|
mswin_layout_main_window(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user