From 19f4b22a56701a8cada6d50cf222c8e09ed069f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 5 Nov 2024 01:03:21 +0100 Subject: [PATCH] Cleanup, add right-click support to UI framework --- Common/Input/InputState.h | 4 ++- Common/UI/View.cpp | 5 +++ UI/EmuScreen.cpp | 7 ++-- Windows/MainWindow.cpp | 53 +++++++++++++++++++++++++------ ext/imgui/imgui_impl_platform.cpp | 10 ++++-- 5 files changed, 62 insertions(+), 17 deletions(-) diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index b4e0d8e074..4a0a5a331e 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -134,8 +134,9 @@ enum { TOUCH_UP = 1 << 2, TOUCH_CANCEL = 1 << 3, // Sent by scrollviews to their children when they detect a scroll TOUCH_WHEEL = 1 << 4, // Scrollwheel event. Usually only affects Y but can potentially affect X. - TOUCH_MOUSE = 1 << 5, // Identifies that this touch event came from a mouse + TOUCH_MOUSE = 1 << 5, // Identifies that this touch event came from a mouse. Id is now set to the mouse button for DOWN/UP commands. TOUCH_RELEASE_ALL = 1 << 6, // Useful for app focus switches when events may be lost. + TOUCH_HOVER = 1 << 7, // These are the Android getToolType() codes, shifted by 10. TOUCH_TOOL_MASK = 7 << 10, @@ -153,6 +154,7 @@ struct TouchInput { float x; float y; int id; // Needs to be <= GestureDetector::MAX_PTRS (10.) + int buttons; // bit mask int flags; double timestamp; }; diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index f7e8959a93..db720f7062 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -249,6 +249,11 @@ bool Clickable::Touch(const TouchInput &input) { return contains; } + // Ignore buttons other than the left one. + if ((input.flags & TOUCH_MOUSE) && input.id != 0) { + return contains; + } + if (input.flags & TOUCH_DOWN) { if (bounds_.Contains(input.x, input.y)) { if (IsFocusMovementEnabled()) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 019ec72735..55dc05b96e 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -954,15 +954,14 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { 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)) { + if (imguiVisible_ && imguiInited_) { 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; + if (b == VIRTKEY_TOGGLE_DEBUGGER || b == VIRTKEY_PAUSE) { + return controlMapper_.Key(key, &pauseTrigger_); } } } diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index ffffb557f4..d78bba0079 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -632,9 +632,9 @@ namespace MainWindow float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y; WindowsRawInput::SetMousePos(x, y); - TouchInput touch; - touch.id = 0; - touch.flags = TOUCH_DOWN; + TouchInput touch{}; + touch.flags = TOUCH_DOWN | TOUCH_MOUSE; + touch.buttons = 1; touch.x = x; touch.y = y; NativeTouch(touch); @@ -680,10 +680,15 @@ namespace MainWindow float y = (float)cursorY * g_display.dpi_scale_y; WindowsRawInput::SetMousePos(x, y); - if (wParam & MK_LBUTTON) { - TouchInput touch; - touch.id = 0; - touch.flags = TOUCH_MOVE; + if (wParam & (MK_LBUTTON | MK_RBUTTON)) { + TouchInput touch{}; + touch.flags = TOUCH_MOVE | TOUCH_MOUSE; + if (wParam & MK_LBUTTON) { + touch.buttons |= 1; + } + if (wParam & MK_RBUTTON) { + touch.buttons |= 2; + } touch.x = x; touch.y = y; NativeTouch(touch); @@ -702,9 +707,9 @@ namespace MainWindow float y = (float)GET_Y_LPARAM(lParam) * g_display.dpi_scale_y; WindowsRawInput::SetMousePos(x, y); - TouchInput touch; - touch.id = 0; - touch.flags = TOUCH_UP; + TouchInput touch{}; + touch.buttons = 1; + touch.flags = TOUCH_UP | TOUCH_MOUSE; touch.x = x; touch.y = y; NativeTouch(touch); @@ -716,6 +721,34 @@ namespace MainWindow touchHandler.handleTouchEvent(hWnd, message, wParam, lParam); return 0; + case WM_RBUTTONDOWN: + { + float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x; + float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y; + + TouchInput touch{}; + touch.buttons = 2; + touch.flags = TOUCH_DOWN | TOUCH_MOUSE; + touch.x = x; + touch.y = y; + NativeTouch(touch); + break; + } + + case WM_RBUTTONUP: + { + float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x; + float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y; + + TouchInput touch{}; + touch.buttons = 2; + touch.flags = TOUCH_UP | TOUCH_MOUSE; + touch.x = x; + touch.y = y; + NativeTouch(touch); + break; + } + default: return DefWindowProc(hWnd, message, wParam, lParam); } diff --git a/ext/imgui/imgui_impl_platform.cpp b/ext/imgui/imgui_impl_platform.cpp index 3169fef975..bf4589be50 100644 --- a/ext/imgui/imgui_impl_platform.cpp +++ b/ext/imgui/imgui_impl_platform.cpp @@ -42,11 +42,17 @@ void ImGui_ImplPlatform_TouchEvent(const TouchInput &touch) { } if (touch.flags & TOUCH_DOWN) { io.AddMousePosEvent(x, y); - io.AddMouseButtonEvent(0, true); + if (touch.buttons & 1) + io.AddMouseButtonEvent(0, true); + if (touch.buttons & 2) + io.AddMouseButtonEvent(1, true); } if (touch.flags & TOUCH_UP) { io.AddMousePosEvent(x, y); - io.AddMouseButtonEvent(0, false); + if (touch.buttons & 1) + io.AddMouseButtonEvent(0, false); + if (touch.buttons & 2) + io.AddMouseButtonEvent(1, false); } }