From 1ed57a9fdfb35e81f96d33a30a112bb31ec0cb44 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 13 Jul 2020 02:36:20 +1000 Subject: [PATCH] Qt: Hook up mouse events to ImGui --- src/duckstation-qt/qthostinterface.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index b638c7b90..ed7340bd2 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -268,13 +268,35 @@ void QtHostInterface::onDisplayWindowMouseMoveEvent(int x, int y) { // display might be null here if the event happened after shutdown DebugAssert(isOnWorkerThread()); - if (m_display) - m_display->SetMousePosition(x, y); + if (!m_display) + return; + + m_display->SetMousePosition(x, y); + + if (ImGui::GetCurrentContext()) + { + ImGuiIO& io = ImGui::GetIO(); + io.MousePos[0] = static_cast(x); + io.MousePos[1] = static_cast(y); + } } void QtHostInterface::onDisplayWindowMouseButtonEvent(int button, bool pressed) { DebugAssert(isOnWorkerThread()); + + if (ImGui::GetCurrentContext() && (button > 0 && button <= countof(ImGuiIO::MouseDown))) + { + ImGuiIO& io = ImGui::GetIO(); + io.MouseDown[button - 1] = pressed; + + if (io.WantCaptureMouse) + { + // don't consume input events if it's hitting the UI instead + return; + } + } + HandleHostMouseEvent(button, pressed); }