1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 20:22:30 +01:00

overlays/osk: Clear text properly in continuous mode

This commit is contained in:
Megamouse 2023-01-24 00:13:14 +01:00
parent 9b6d7a5275
commit d3dbf9e83f
6 changed files with 37 additions and 6 deletions

View File

@ -247,7 +247,7 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dia
// Get init text and prepare return value // Get init text and prepare return value
osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK; osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
std::memset(osk->osk_text, 0, sizeof(osk->osk_text)); osk->osk_text = {};
// Also clear the info text just to be sure (it should be zeroed at this point anyway) // Also clear the info text just to be sure (it should be zeroed at this point anyway)
{ {
@ -605,7 +605,7 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dia
osk->Create({ osk->Create({
.title = get_localized_string(localized_string_id::CELL_OSK_DIALOG_TITLE), .title = get_localized_string(localized_string_id::CELL_OSK_DIALOG_TITLE),
.message = message, .message = message,
.init_text = osk->osk_text, .init_text = osk->osk_text.data(),
.charlimit = maxLength, .charlimit = maxLength,
.prohibit_flags = prohibitFlgs, .prohibit_flags = prohibitFlgs,
.panel_flag = allowOskPanelFlg, .panel_flag = allowOskPanelFlg,
@ -741,8 +741,14 @@ error_code getText(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo, bool is
case CELL_SYSUTIL_OSKDIALOG_UNLOADED: case CELL_SYSUTIL_OSKDIALOG_UNLOADED:
case CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED: case CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED:
case CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED: case CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED:
{
auto& info = g_fxo->get<osk_info>();
std::lock_guard lock(info.text_mtx);
info.valid_text = {}; info.valid_text = {};
osk->Clear();
break; break;
}
default: default:
break; break;
} }

View File

@ -301,6 +301,7 @@ public:
}; };
virtual void Create(const osk_params& params) = 0; virtual void Create(const osk_params& params) = 0;
virtual void Clear() = 0;
// Closes the dialog. // Closes the dialog.
// Set status to CELL_OSKDIALOG_CLOSE_CONFIRM or CELL_OSKDIALOG_CLOSE_CANCEL for user input. // Set status to CELL_OSKDIALOG_CLOSE_CONFIRM or CELL_OSKDIALOG_CLOSE_CANCEL for user input.
@ -321,7 +322,7 @@ public:
atomic_t<bool> ignore_device_events{ false }; // Determines if the OSK ignores device events. atomic_t<bool> ignore_device_events{ false }; // Determines if the OSK ignores device events.
atomic_t<CellOskDialogInputFieldResult> osk_input_result{ CellOskDialogInputFieldResult::CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK }; atomic_t<CellOskDialogInputFieldResult> osk_input_result{ CellOskDialogInputFieldResult::CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK };
char16_t osk_text[CELL_OSKDIALOG_STRING_SIZE]{}; std::array<char16_t, CELL_OSKDIALOG_STRING_SIZE> osk_text{};
}; };
struct osk_info struct osk_info

View File

@ -69,6 +69,15 @@ namespace rsx
fade_animation.active = true; fade_animation.active = true;
} }
void osk_dialog::Clear()
{
std::lock_guard lock(m_preview_mutex);
m_preview.caret_position = 0;
m_preview.value.clear();
on_text_changed();
}
void osk_dialog::add_panel(const osk_panel& panel) void osk_dialog::add_panel(const osk_panel& panel)
{ {
// On PS3 apparently only 7 panels are added, the rest is ignored // On PS3 apparently only 7 panels are added, the rest is ignored
@ -582,6 +591,8 @@ namespace rsx
update_panel(); update_panel();
} }
std::lock_guard lock(m_preview_mutex);
const u32 grid_size = num_columns * num_rows; const u32 grid_size = num_columns * num_rows;
const auto on_accept = [this]() const auto on_accept = [this]()
@ -943,8 +954,8 @@ namespace rsx
void osk_dialog::on_text_changed() void osk_dialog::on_text_changed()
{ {
const auto ws = u32string_to_utf16(m_preview.value); const auto ws = u32string_to_utf16(m_preview.value);
const auto length = (ws.length() + 1) * sizeof(char16_t); const usz length = std::min(osk_text.size(), ws.length() + 1) * sizeof(char16_t);
memcpy(osk_text, ws.c_str(), length); memcpy(osk_text.data(), ws.c_str(), length);
// Muted contrast for placeholder text // Muted contrast for placeholder text
m_preview.fore_color.a = m_preview.value.empty() ? 0.5f : 1.f; m_preview.fore_color.a = m_preview.value.empty() ? 0.5f : 1.f;

View File

@ -38,6 +38,9 @@ namespace rsx
callback_t callback; callback_t callback;
}; };
// Mutex for interaction between overlay and cellOskDialog
shared_mutex m_preview_mutex;
// Base UI configuration // Base UI configuration
bool m_use_separate_windows = false; bool m_use_separate_windows = false;
bool m_show_panel = true; bool m_show_panel = true;
@ -104,6 +107,7 @@ namespace rsx
void Create(const osk_params& params) override; void Create(const osk_params& params) override;
void Close(s32 status) override; void Close(s32 status) override;
void Clear() override;
void initialize_layout(const std::u32string& title, const std::u32string& initial_text); void initialize_layout(const std::u32string& title, const std::u32string& initial_text);
void add_panel(const osk_panel& panel); void add_panel(const osk_panel& panel);

View File

@ -182,7 +182,7 @@ void osk_dialog_frame::Create(const osk_params& params)
void osk_dialog_frame::SetOskText(const QString& text) void osk_dialog_frame::SetOskText(const QString& text)
{ {
std::memcpy(osk_text, utils::bless<char16_t>(text.constData()), (text.size() + 1u) * sizeof(char16_t)); std::memcpy(osk_text.data(), utils::bless<char16_t>(text.constData()), std::min(osk_text.size(), text.size() + 1ull) * sizeof(char16_t));
} }
void osk_dialog_frame::Close(s32 status) void osk_dialog_frame::Close(s32 status)
@ -203,3 +203,11 @@ void osk_dialog_frame::Close(s32 status)
} }
} }
} }
void osk_dialog_frame::Clear()
{
if (m_dialog)
{
SetOskText("");
}
}

View File

@ -18,6 +18,7 @@ public:
~osk_dialog_frame(); ~osk_dialog_frame();
void Create(const osk_params& params) override; void Create(const osk_params& params) override;
void Close(s32 status) override; void Close(s32 status) override;
void Clear() override;
private: private:
void SetOskText(const QString& text); void SetOskText(const QString& text);