Win32GUI: Gather raw_print text and display it all in single dialog
Defined strbuf_t and related routines to support dynamically sized strings. Modified strip_newline() to strip the last newline in a string instead of the first. Simplified splash window code using new strbuf_t. Prior to exiting game, re-enable getreturn and call wait_synch() in case there is buffered raw prints that must be displayed to user.
This commit is contained in:
committed by
Pasi Kallinen
parent
b02dae91a1
commit
a588541a27
@@ -75,6 +75,8 @@ COLORREF status_fg_color = RGB(0xFF, 0xFF, 0xFF);
|
||||
COLORREF message_bg_color = RGB(0, 0, 0);
|
||||
COLORREF message_fg_color = RGB(0xFF, 0xFF, 0xFF);
|
||||
|
||||
strbuf_t raw_print_strbuf = { 0 };
|
||||
|
||||
/* Interface definition, for windows.c */
|
||||
struct window_procs mswin_procs = {
|
||||
"MSWIN",
|
||||
@@ -717,8 +719,7 @@ mswin_exit_nhwindows(const char *str)
|
||||
|
||||
/* Write Window settings to the registry */
|
||||
mswin_write_reg();
|
||||
while (max_brush)
|
||||
DeleteObject(brush_table[--max_brush]);
|
||||
|
||||
}
|
||||
|
||||
/* Prepare the window to be suspended. */
|
||||
@@ -1238,6 +1239,7 @@ void
|
||||
mswin_wait_synch()
|
||||
{
|
||||
logDebug("mswin_wait_synch()\n");
|
||||
mswin_raw_print_flush();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1293,6 +1295,40 @@ mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph, int bkglyph)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* mswin_raw_print_accumulate() accumulate the given text into
|
||||
* raw_print_strbuf.
|
||||
*/
|
||||
void
|
||||
mswin_raw_print_accumulate(const char * str, boolean bold)
|
||||
{
|
||||
bold; // ignored for now
|
||||
|
||||
if (raw_print_strbuf.str != NULL) strbuf_append(&raw_print_strbuf, "\n");
|
||||
strbuf_append(&raw_print_strbuf, str);
|
||||
}
|
||||
|
||||
/*
|
||||
* mswin_raw_print_flush() - display any text found in raw_print_strbuf in a
|
||||
* dialog box and clear raw_print_strbuf.
|
||||
*/
|
||||
void
|
||||
mswin_raw_print_flush()
|
||||
{
|
||||
if (raw_print_strbuf.str != NULL) {
|
||||
int wlen = strlen(raw_print_strbuf.str) + 1;
|
||||
TCHAR * wbuf = (TCHAR *) alloc(wlen * sizeof(TCHAR));
|
||||
if (wbuf != NULL) {
|
||||
NHMessageBox(GetNHApp()->hMainWnd,
|
||||
NH_A2W(raw_print_strbuf.str, wbuf, wlen),
|
||||
MB_ICONINFORMATION | MB_OK);
|
||||
free(wbuf);
|
||||
}
|
||||
strbuf_empty(&raw_print_strbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
raw_print(str) -- Print directly to a screen, or otherwise guarantee that
|
||||
the user sees str. raw_print() appends a newline to str.
|
||||
@@ -1305,14 +1341,12 @@ raw_print(str) -- Print directly to a screen, or otherwise guarantee that
|
||||
void
|
||||
mswin_raw_print(const char *str)
|
||||
{
|
||||
TCHAR wbuf[255];
|
||||
logDebug("mswin_raw_print(%s)\n", str);
|
||||
|
||||
if (str && *str) {
|
||||
extern int redirect_stdout;
|
||||
if (!redirect_stdout)
|
||||
NHMessageBox(GetNHApp()->hMainWnd,
|
||||
NH_A2W(str, wbuf, sizeof(wbuf)),
|
||||
MB_ICONINFORMATION | MB_OK);
|
||||
mswin_raw_print_accumulate(str, FALSE);
|
||||
else
|
||||
fprintf(stdout, "%s", str);
|
||||
}
|
||||
@@ -1326,11 +1360,14 @@ possible).
|
||||
void
|
||||
mswin_raw_print_bold(const char *str)
|
||||
{
|
||||
TCHAR wbuf[255];
|
||||
logDebug("mswin_raw_print_bold(%s)\n", str);
|
||||
if (str && *str)
|
||||
NHMessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)),
|
||||
MB_ICONINFORMATION | MB_OK);
|
||||
if (str && *str) {
|
||||
extern int redirect_stdout;
|
||||
if (!redirect_stdout)
|
||||
mswin_raw_print_accumulate(str, TRUE);
|
||||
else
|
||||
fprintf(stdout, "%s", str);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user