Fix mouse coordinates conversion

Now you can actually click singleplayer in the launcher and then watch the game insta-crash
This commit is contained in:
UnknownShadow200 2019-09-15 18:45:06 +10:00
parent ddd81db6e2
commit 98f3b73c0a
2 changed files with 18 additions and 11 deletions

View File

@ -21,7 +21,8 @@ static void Window_RefreshBounds(void) {
NSRect rect;
view = [winHandle contentView];
rect = [view frame];
rect = [view bounds];
rect = [winHandle convertRectToScreen: rect];
windowX = (int)rect.origin.x;
windowY = (int)rect.origin.y;
@ -137,6 +138,8 @@ void Window_ProcessEvents1(void) {
mouseX = (int)loc.x - windowX;
mouseY = (int)loc.y - windowY;
/* need to flip Y coordinates because cocoa has window origin at bottom left */
mouseY = Window_Height - mouseY;
Pointer_SetPosition(0, mouseX, mouseY);
if (Input_RawMode) Event_RaiseMove(&PointerEvents.RawMoved, 0, dx, dy);

View File

@ -3675,13 +3675,14 @@ static void Window_RefreshBounds(void) {
CGRect rect;
view = objc_msgSend(winHandle, sel_registerName("contentView"));
rect = ((CGRect(*)(id, SEL))(void *)objc_msgSend_stret)(view, sel_registerName("frame"));
rect = ((CGRect(*)(id, SEL))(void *)objc_msgSend_stret)(view, sel_registerName("bounds"));
rect = ((CGRect(*)(id, SEL, CGRect))(void *)objc_msgSend_stret)(winHandle, sel_registerName("convertRectToScreen:"), rect);
windowX = (int)rect.origin.x;
windowY = (int)rect.origin.y;
Window_Width = (int)rect.size.width;
Window_Height = (int)rect.size.height;
Platform_Log2("WINPOS: %i, %i", &windowX, &windowY);
Platform_Log4("WINPOS: %i, %i (%i, %i)", &windowX, &windowY, &Window_Width, &Window_Height);
}
void Window_Init(void) {
@ -3774,7 +3775,7 @@ void Window_ProcessEvents(void) {
case 4: /* NSRightMouseUp */
case 26: /* NSOtherMouseUp */
key = Window_MapMouse((int)objc_msgSend(ev, sel_registerName("buttonNumber")));
if (key) Input_SetPressed(key, true);
if (key) Input_SetPressed(key, false);
break;
case 10: /* NSKeyDown */
@ -3796,16 +3797,19 @@ void Window_ProcessEvents(void) {
case 7: /* NSRightMouseDragged */
case 27: /* NSOtherMouseDragged */
loc = Send_CGPoint((id)objc_getClass("NSEvent"), sel_registerName("mouseLocation"));
mouseX = (int)loc.x - windowX;
mouseY = (int)loc.y - windowY;
/* need to flip Y coordinates because cocoa has window origin at bottom left */
mouseY = Window_Height - mouseY;
Platform_Log2("MOUSE: %i, %i", &mouseX, &mouseY);
Pointer_SetPosition(0, mouseX, mouseY);
if (Input_RawMode) {
dx = Send_CGFloat(ev, sel_registerName("deltaX"));
dy = Send_CGFloat(ev, sel_registerName("deltaY"));
if (Input_RawMode) Event_RaiseMove(&PointerEvents.RawMoved, 0, dx, dy);
Event_RaiseMove(&PointerEvents.RawMoved, 0, dx, dy);
}
break;
}