From f8f1148c59460ab136e30ad887017ceaae8b892e Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Jun 2018 17:45:02 +0300 Subject: [PATCH] - fixed mouse cursor positioning in menu for Cocoa backend With video resolution scaling enabled engine coordinates of mouse cursor were wrong --- src/posix/cocoa/i_input.mm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/posix/cocoa/i_input.mm b/src/posix/cocoa/i_input.mm index 745b0c6dca..78841d9064 100644 --- a/src/posix/cocoa/i_input.mm +++ b/src/posix/cocoa/i_input.mm @@ -484,11 +484,14 @@ void NSEventToGameMousePosition(NSEvent* inEvent, event_t* outEvent) const NSPoint viewPos = [view convertPointToBacking:windowRect.origin]; const CGFloat frameHeight = I_GetContentViewSize(window).height; - const CGFloat posX = ( viewPos.x - rbOpts.shiftX) / rbOpts.pixelScale; - const CGFloat posY = (frameHeight - viewPos.y - rbOpts.shiftY) / rbOpts.pixelScale; + outEvent->data1 = static_cast( viewPos.x); + outEvent->data2 = static_cast(frameHeight - viewPos.y); - outEvent->data1 = static_cast(posX); - outEvent->data2 = static_cast(posY); + // Compensate letterbox adjustment done by cross-platform code + // More elegant solution is a bit problematic due to HiDPI/Retina support + outEvent->data2 += (screen->GetTrueHeight() - screen->VideoHeight) / 2; + + screen->ScaleCoordsFromWindow(outEvent->data1, outEvent->data2); } void ProcessMouseMoveInMenu(NSEvent* theEvent)