@@ -2415,19 +2415,25 @@ static void DrawImGui()
24152415 // we can adjust the mouse events before ImGui processes them.
24162416 uint32_t width = g_swapChain->getWidth ();
24172417 uint32_t height = g_swapChain->getHeight ();
2418-
2419- if (width != Video::s_viewportWidth || height != Video::s_viewportHeight)
2418+ float mousePosScaleX = float (width) / float (GameWindow::s_width);
2419+ float mousePosScaleY = float (height) / float (GameWindow::s_height);
2420+ float mousePosOffsetX = (width - Video::s_viewportWidth) / 2 .0f ;
2421+ float mousePosOffsetY = (height - Video::s_viewportHeight) / 2 .0f ;
2422+ for (int i = 0 ; i < io.Ctx ->InputEventsQueue .Size ; i++)
24202423 {
2421- float mousePosOffsetX = (width - Video::s_viewportWidth) / 2 .0f ;
2422- float mousePosOffsetY = (height - Video::s_viewportHeight) / 2 .0f ;
2423-
2424- for (int i = 0 ; i < io.Ctx ->InputEventsQueue .Size ; i++)
2424+ auto & e = io.Ctx ->InputEventsQueue [i];
2425+ if (e.Type == ImGuiInputEventType_MousePos)
24252426 {
2426- auto & e = io.Ctx ->InputEventsQueue [i];
2427- if (e.Type == ImGuiInputEventType_MousePos)
2427+ if (e.MousePos .PosX != -FLT_MAX )
2428+ {
2429+ e.MousePos .PosX *= mousePosScaleX;
2430+ e.MousePos .PosX -= mousePosOffsetX;
2431+ }
2432+
2433+ if (e.MousePos .PosY != -FLT_MAX )
24282434 {
2429- if ( e.MousePos .PosX != - FLT_MAX ) e. MousePos . PosX -= mousePosOffsetX ;
2430- if (e. MousePos . PosY != - FLT_MAX ) e.MousePos .PosY -= mousePosOffsetY;
2435+ e.MousePos .PosY *= mousePosScaleY ;
2436+ e.MousePos .PosY -= mousePosOffsetY;
24312437 }
24322438 }
24332439 }
0 commit comments