From 3d8145af65afd0445ae9416906cffad0750007de Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 26 Jan 2019 01:31:58 +1000 Subject: [PATCH] RenderWidget: Fix mouse position for imgui on hidpi screens --- Source/Core/DolphinQt/RenderWidget.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt/RenderWidget.cpp b/Source/Core/DolphinQt/RenderWidget.cpp index 6953de0798..3dc4a8fa75 100644 --- a/Source/Core/DolphinQt/RenderWidget.cpp +++ b/Source/Core/DolphinQt/RenderWidget.cpp @@ -284,8 +284,13 @@ void RenderWidget::PassEventToImGui(const QEvent* event) case QEvent::MouseMove: { auto lock = g_renderer->GetImGuiLock(); - ImGui::GetIO().MousePos.x = static_cast(event)->x(); - ImGui::GetIO().MousePos.y = static_cast(event)->y(); + + // Qt multiplies all coordinates by the scaling factor in highdpi mode, giving us "scaled" mouse + // coordinates (as if the screen was standard dpi). We need to update the mouse position in + // native coordinates, as the UI (and game) is rendered at native resolution. + const float scale = devicePixelRatio(); + ImGui::GetIO().MousePos.x = static_cast(event)->x() * scale; + ImGui::GetIO().MousePos.y = static_cast(event)->y() * scale; } break;