From caf27a5c0ddbf1aca59e822a19cc1258664bdbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 4 Nov 2024 23:33:03 +0100 Subject: [PATCH] Add a mappable key for toggling the imgui interface. For now it's called Toggle debugger. --- Core/KeyMap.cpp | 1 + Core/KeyMap.h | 1 + Core/KeyMapDefaults.cpp | 1 + UI/EmuScreen.cpp | 32 ++++++++++++++++++++++---------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index f58f136536..178a2ca843 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -436,6 +436,7 @@ const KeyMap_IntStrPair psp_button_names[] = { #if !defined(MOBILE_DEVICE) {VIRTKEY_TOGGLE_FULLSCREEN, "Toggle Fullscreen"}, #endif + {VIRTKEY_TOGGLE_DEBUGGER, "Toggle Debugger"}, {VIRTKEY_OPENCHAT, "OpenChat" }, diff --git a/Core/KeyMap.h b/Core/KeyMap.h index 6f98207551..ec9c00722a 100644 --- a/Core/KeyMap.h +++ b/Core/KeyMap.h @@ -77,6 +77,7 @@ enum { VIRTKEY_TOGGLE_MOUSE = 0x40000030, VIRTKEY_TOGGLE_TOUCH_CONTROLS = 0x40000031, VIRTKEY_RESET_EMULATION = 0x40000032, + VIRTKEY_TOGGLE_DEBUGGER = 0x40000033, VIRTKEY_LAST, VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST }; diff --git a/Core/KeyMapDefaults.cpp b/Core/KeyMapDefaults.cpp index 0857e25985..df9ada7ef7 100644 --- a/Core/KeyMapDefaults.cpp +++ b/Core/KeyMapDefaults.cpp @@ -45,6 +45,7 @@ static const DefMappingStruct defaultQwertyKeyboardKeyMap[] = { {VIRTKEY_PAUSE , NKCODE_ESCAPE}, {VIRTKEY_REWIND , NKCODE_DEL}, {VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT}, + {VIRTKEY_TOGGLE_DEBUGGER, NKCODE_F12}, }; static const DefMappingStruct defaultAzertyKeyboardKeyMap[] = { diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index aa53bede26..019ec72735 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -670,6 +670,11 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) { auto mc = GetI18NCategory(I18NCat::MAPPABLECONTROLS); switch (virtualKeyCode) { + case VIRTKEY_TOGGLE_DEBUGGER: + if (down) { + imguiVisible_ = !imguiVisible_; + } + break; case VIRTKEY_FASTFORWARD: if (down) { if (coreState == CORE_STEPPING) { @@ -946,13 +951,23 @@ void EmuScreen::onVKeyAnalog(int virtualKeyCode, float value) { bool EmuScreen::UnsyncKey(const KeyInput &key) { System_Notify(SystemNotification::ACTIVITY); - - if ((key.flags & KEY_DOWN) && key.keyCode == NKCODE_GRAVE) { // The key to the left of '1' on a standard keyboard. - // it's ok that this is unsynchronized. - imguiVisible_ = !imguiVisible_; - } - if (UI::IsFocusMovementEnabled() || (imguiVisible_ && imguiInited_)) { + // Note: Allow some Vkeys through, so we can toggle the imgui for example (since we actually block the control mapper otherwise in imgui mode). + // We need to manually implement it here :/ + if (imguiVisible_ && imguiInited_ && (key.flags & KEY_DOWN)) { + InputMapping mapping(key.deviceId, key.keyCode); + std::vector pspButtons; + bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons); + if (mappingFound) { + for (auto b : pspButtons) { + if (b == VIRTKEY_TOGGLE_DEBUGGER) { + imguiVisible_ = false; + return true; + } + } + } + } + return UIScreen::UnsyncKey(key); } return controlMapper_.Key(key, &pauseTrigger_); @@ -1613,12 +1628,9 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { ImGui_ImplPlatform_NewFrame(); ImGui_ImplThin3d_NewFrame(draw, ui_draw2d.GetDrawMatrix()); - // Draw imgui on top + // Draw imgui on top. For now, all we have is the demo window. ImGui::NewFrame(); ImGui::ShowDemoWindow(nullptr); - ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. - ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) - ImGui::End(); ImGui::Render(); ImGui_ImplThin3d_RenderDrawData(ImGui::GetDrawData(), draw);