Codechange: use string/fmt instead of printf for ShowInfo(F)

This commit is contained in:
Rubidium
2023-04-18 19:41:29 +02:00
committed by rubidium42
parent 8f24901843
commit f5f6306af3
15 changed files with 35 additions and 49 deletions

View File

@@ -386,7 +386,7 @@ void LoadCoreTextFont(FontSize fs)
font_ref.reset((CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0));
CFRetain(font_ref.get());
} else {
ShowInfoF("Unable to load file '%s' for %s font, using default OS font selection instead", settings->font.c_str(), FontSizeToName(fs));
ShowInfo("Unable to load file '{}' for {} font, using default OS font selection instead", settings->font, FontSizeToName(fs));
}
}
}
@@ -410,7 +410,7 @@ void LoadCoreTextFont(FontSize fs)
}
if (!font_ref) {
ShowInfoF("Unable to use '%s' for %s font, using sprite font instead", settings->font.c_str(), FontSizeToName(fs));
ShowInfo("Unable to use '{}' for {} font, using sprite font instead", settings->font, FontSizeToName(fs));
return;
}

View File

@@ -133,7 +133,7 @@ bool FiosIsHiddenFile(const struct dirent *ent)
return ent->d_name[0] == '.';
}
void ShowInfo(const char *str)
void ShowInfoI(const std::string &str)
{
HAB hab;
HMQ hmq;
@@ -143,7 +143,7 @@ void ShowInfo(const char *str)
hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
/* display the box */
rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (const unsigned char *)str, (const unsigned char *)"OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_INFORMATION);
rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (const unsigned char *)str.c_str(), (const unsigned char *)"OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_INFORMATION);
/* terminate PM env. */
WinDestroyMsgQueue(hmq);

View File

@@ -30,7 +30,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
FT_Error err = FT_Err_Cannot_Open_Resource;
if (!FcInit()) {
ShowInfoF("Unable to load font configuration");
ShowInfo("Unable to load font configuration");
} else {
FcPattern *match;
FcPattern *pat;

View File

@@ -210,9 +210,9 @@ std::string FS2OTTD(const std::string &name)
#endif /* WITH_ICONV */
void ShowInfo(const char *str)
void ShowInfoI(const std::string &str)
{
fprintf(stderr, "%s\n", str);
fprintf(stderr, "%s\n", str.c_str());
}
#if !defined(__APPLE__)

View File

@@ -609,7 +609,7 @@ void LoadWin32Font(FontSize fs)
logfont.lfWeight = strcasestr(font_name, " bold") != nullptr || strcasestr(font_name, "-bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
}
} else {
ShowInfoF("Unable to load file '%s' for %s font, using default windows font selection instead", font_name, FontSizeToName(fs));
ShowInfo("Unable to load file '{}' for {} font, using default windows font selection instead", font_name, FontSizeToName(fs));
}
}
}
@@ -621,7 +621,7 @@ void LoadWin32Font(FontSize fs)
HFONT font = CreateFontIndirect(&logfont);
if (font == nullptr) {
ShowInfoF("Unable to use '%s' for %s font, Win32 reported error 0x%lX, using sprite font instead", font_name, FontSizeToName(fs), GetLastError());
ShowInfo("Unable to use '{}' for {} font, Win32 reported error 0x{:X}, using sprite font instead", font_name, FontSizeToName(fs), GetLastError());
return;
}
DeleteObject(font);

View File

@@ -318,27 +318,27 @@ static INT_PTR CALLBACK HelpDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARAM
return FALSE;
}
void ShowInfo(const char *str)
void ShowInfoI(const std::string &str)
{
if (_has_console) {
fprintf(stderr, "%s\n", str);
fprintf(stderr, "%s\n", str.c_str());
} else {
bool old;
ReleaseCapture();
_left_button_clicked = _left_button_down = false;
old = MyShowCursor(true);
if (strlen(str) > 2048) {
if (str.size() > 2048) {
/* The minimum length of the help message is 2048. Other messages sent via
* ShowInfo are much shorter, or so long they need this way of displaying
* them anyway. */
_help_msg = str;
_help_msg = str.c_str();
DialogBox(GetModuleHandle(nullptr), MAKEINTRESOURCE(101), nullptr, HelpDialogFunc);
} else {
/* We need to put the text in a separate buffer because the default
* buffer in OTTD2FS might not be large enough (512 chars). */
wchar_t help_msg_buf[8192];
MessageBox(GetActiveWindow(), convert_to_fs(str, help_msg_buf, lengthof(help_msg_buf)), L"OpenTTD", MB_ICONINFORMATION | MB_OK);
MessageBox(GetActiveWindow(), convert_to_fs(str.c_str(), help_msg_buf, lengthof(help_msg_buf)), L"OpenTTD", MB_ICONINFORMATION | MB_OK);
}
MyShowCursor(old);
}