From 5bb740c3739d7d2b7f347844cfce1545ba50bb77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 9 Nov 2025 22:02:40 +0100 Subject: [PATCH] Control mapping: Remove some old uses of std::bind, and an unnecessary enum. --- UI/ControlMappingScreen.cpp | 95 ++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 54 deletions(-) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 87ca89afa9..dc75458cec 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -72,21 +72,11 @@ private: void OnReplace(UI::EventParams ¶ms); void OnReplaceAll(UI::EventParams ¶ms); - void MappedCallback(const MultiInputMapping &kdf); - - enum Action { - NONE, - REPLACEONE, - REPLACEALL, - ADD, - }; + int pspKey_; UI::Choice *addButton_ = nullptr; UI::Choice *replaceAllButton_ = nullptr; std::vector rows_; - Action action_ = NONE; - int actionIndex_ = 0; - int pspKey_; std::string keyName_; ScreenManager *scrm_; }; @@ -167,73 +157,67 @@ void SingleControlMapper::Refresh() { } } -void SingleControlMapper::MappedCallback(const MultiInputMapping &kdf) { - if (kdf.empty()) { - // Don't want to try to add this. - return; - } - - switch (action_) { - case ADD: - KeyMap::SetInputMapping(pspKey_, kdf, false); - addButton_->SetFocus(); - break; - case REPLACEALL: - KeyMap::SetInputMapping(pspKey_, kdf, true); - replaceAllButton_->SetFocus(); - break; - case REPLACEONE: - { - bool success = KeyMap::ReplaceSingleKeyMapping(pspKey_, actionIndex_, kdf); +void SingleControlMapper::OnReplace(UI::EventParams ¶ms) { + const int index = atoi(params.v->Tag().c_str()); + scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, [this, index](KeyMap::MultiInputMapping mapping) { + if (mapping.empty()) + return; + bool success = KeyMap::ReplaceSingleKeyMapping(pspKey_, index, mapping); if (!success) { replaceAllButton_->SetFocus(); // Last got removed as a duplicate - } else if (actionIndex_ < (int)rows_.size()) { - rows_[actionIndex_]->SetFocus(); + } else if (index < (int)rows_.size()) { + rows_[index]->SetFocus(); } else { SetFocus(); } - break; - } - default: - SetFocus(); - break; - } - KeyMap::UpdateNativeMenuKeys(); - g_IsMappingMouseInput = false; -} - -void SingleControlMapper::OnReplace(UI::EventParams ¶ms) { - actionIndex_ = atoi(params.v->Tag().c_str()); - action_ = REPLACEONE; - scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, std::bind(&SingleControlMapper::MappedCallback, this, std::placeholders::_1), I18NCat::KEYMAPPING)); + KeyMap::UpdateNativeMenuKeys(); + g_IsMappingMouseInput = false; + }, I18NCat::KEYMAPPING)); } void SingleControlMapper::OnReplaceAll(UI::EventParams ¶ms) { - action_ = REPLACEALL; - scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, std::bind(&SingleControlMapper::MappedCallback, this, std::placeholders::_1), I18NCat::KEYMAPPING)); + scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, [this](KeyMap::MultiInputMapping mapping) { + if (mapping.empty()) + return; + KeyMap::SetInputMapping(pspKey_, mapping, true); + replaceAllButton_->SetFocus(); + KeyMap::UpdateNativeMenuKeys(); + g_IsMappingMouseInput = false; + }, I18NCat::KEYMAPPING)); } void SingleControlMapper::OnAdd(UI::EventParams ¶ms) { - action_ = ADD; - scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, std::bind(&SingleControlMapper::MappedCallback, this, std::placeholders::_1), I18NCat::KEYMAPPING)); + scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, [this](KeyMap::MultiInputMapping mapping) { + if (mapping.empty()) + return; + KeyMap::SetInputMapping(pspKey_, mapping, false); + addButton_->SetFocus(); + KeyMap::UpdateNativeMenuKeys(); + g_IsMappingMouseInput = false; + }, I18NCat::KEYMAPPING)); } + void SingleControlMapper::OnAddMouse(UI::EventParams ¶ms) { - action_ = ADD; g_IsMappingMouseInput = true; - scrm_->push(new KeyMappingNewMouseKeyDialog(pspKey_, true, std::bind(&SingleControlMapper::MappedCallback, this, std::placeholders::_1), I18NCat::KEYMAPPING)); + scrm_->push(new KeyMappingNewMouseKeyDialog(pspKey_, true, [this](KeyMap::MultiInputMapping mapping) { + if (mapping.empty()) + return; + KeyMap::SetInputMapping(pspKey_, mapping, false); + addButton_->SetFocus(); + KeyMap::UpdateNativeMenuKeys(); + g_IsMappingMouseInput = false; + }, I18NCat::KEYMAPPING)); } void SingleControlMapper::OnDelete(UI::EventParams ¶ms) { int index = atoi(params.v->Tag().c_str()); KeyMap::DeleteNthMapping(pspKey_, index); - if (index + 1 < (int)rows_.size()) rows_[index]->SetFocus(); else SetFocus(); } - struct BindingCategory { const char *catName; int firstKey; @@ -1030,7 +1014,10 @@ void VisualMappingScreen::MapNext(bool successive) { } else { psp_->SelectButton(nextKey_); } - auto dialog = new KeyMappingNewKeyDialog(nextKey_, true, std::bind(&VisualMappingScreen::HandleKeyMapping, this, std::placeholders::_1), I18NCat::KEYMAPPING); + + auto dialog = new KeyMappingNewKeyDialog(nextKey_, true, [this](KeyMap::MultiInputMapping mapping) { + HandleKeyMapping(mapping); + }, I18NCat::KEYMAPPING); Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds(); dialog->SetPopupOffset(psp_->GetPopupOffset() * bounds.h);