From 1da045450803831c01984116a2be02fdd7f326f2 Mon Sep 17 00:00:00 2001 From: The Dax Date: Mon, 5 Aug 2013 23:17:26 -0400 Subject: [PATCH] Add support for changing the InputBox's title to the description text provided by the game(or the emulator itself). If none is provided(empty string), fall back to a default string. --- Core/Dialog/PSPOskDialog.cpp | 23 ++++++++++++++++------- UI/MenuScreens.cpp | 2 +- Windows/InputBox.cpp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Core/Dialog/PSPOskDialog.cpp b/Core/Dialog/PSPOskDialog.cpp index b057ccc84a..7256d7b61f 100755 --- a/Core/Dialog/PSPOskDialog.cpp +++ b/Core/Dialog/PSPOskDialog.cpp @@ -760,19 +760,28 @@ int PSPOskDialog::NativeKeyboard() std::string initial_text; ConvertUCS2ToUTF8(initial_text, oskParams->fields[0].intext); - const size_t buf_len = 512; - char buf[buf_len]; + const size_t defaultText_len = 512; + char defaultText[defaultText_len]; - memset(buf, 0, sizeof(buf)); + memset(defaultText, 0, sizeof(defaultText)); - if(initial_text.length() < buf_len) - sprintf(buf, initial_text.c_str()); + if(initial_text.length() < defaultText_len) + sprintf(defaultText, initial_text.c_str()); else { ERROR_LOG(HLE, "NativeKeyboard: initial text length is too long"); - sprintf(buf, "VALUE"); + sprintf(defaultText, "VALUE"); } - if(!InputBox_GetString(0, MainWindow::hwndMain, NULL, buf, input, FieldMaxLength())) { + char windowTitle[defaultText_len]; + memset(windowTitle, 0, sizeof(windowTitle)); + + std::string description_text; + ConvertUCS2ToUTF8(description_text, oskParams->fields[0].desc); + + if(description_text.length() < defaultText_len) + sprintf(windowTitle, description_text.c_str()); + + if(!InputBox_GetString(0, MainWindow::hwndMain, windowTitle, defaultText, input, FieldMaxLength())) { sprintf(input, ""); } #endif diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index c6a9da8bdc..45d828a67a 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -1552,7 +1552,7 @@ void SystemScreen::render() { char name[name_len]; memset(name, 0, sizeof(name)); - if(InputBox_GetString(MainWindow::GetHInstance(), MainWindow::hwndMain, NULL, "PPSSPP", name, name_len)) + if(InputBox_GetString(MainWindow::GetHInstance(), MainWindow::hwndMain, "Enter a new PSP nickname", "PPSSPP", name, name_len)) g_Config.sNickName.assign(name); else g_Config.sNickName.assign("PPSSPP"); diff --git a/Windows/InputBox.cpp b/Windows/InputBox.cpp index e76a28f7ac..a2d54882e9 100644 --- a/Windows/InputBox.cpp +++ b/Windows/InputBox.cpp @@ -4,12 +4,14 @@ static TCHAR textBoxContents[256]; static TCHAR out[256]; +static TCHAR windowTitle[256]; static INT_PTR CALLBACK InputBoxFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: SetWindowText(GetDlgItem(hDlg,IDC_INPUTBOX),textBoxContents); + SetWindowText(hDlg, windowTitle); return TRUE; case WM_COMMAND: switch (wParam) @@ -51,11 +53,21 @@ bool InputBox_GetString(HINSTANCE hInst, HWND hParent, TCHAR *title, TCHAR *defa bool InputBox_GetString(HINSTANCE hInst, HWND hParent, TCHAR *title, TCHAR *defaultvalue, TCHAR *outvalue, u32 outlength) { + const char *defaultTitle = "Input value"; + if (defaultvalue && strlen(defaultvalue)<255) strcpy(textBoxContents,defaultvalue); else strcpy(textBoxContents,""); + + if(title && strlen(title) <= 0) + strcpy(windowTitle, defaultTitle); + else if(title && strlen(title) < 255) + strcpy(windowTitle, title); + else + strcpy(windowTitle, defaultTitle); + if (IDOK==DialogBox(hInst,(LPCSTR)IDD_INPUTBOX,hParent,InputBoxFunc)) { strncpy(outvalue, out, outlength);