mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
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:
parent
ddd81db6e2
commit
98f3b73c0a
@ -21,7 +21,8 @@ static void Window_RefreshBounds(void) {
|
|||||||
NSRect rect;
|
NSRect rect;
|
||||||
|
|
||||||
view = [winHandle contentView];
|
view = [winHandle contentView];
|
||||||
rect = [view frame];
|
rect = [view bounds];
|
||||||
|
rect = [winHandle convertRectToScreen: rect];
|
||||||
|
|
||||||
windowX = (int)rect.origin.x;
|
windowX = (int)rect.origin.x;
|
||||||
windowY = (int)rect.origin.y;
|
windowY = (int)rect.origin.y;
|
||||||
@ -137,6 +138,8 @@ void Window_ProcessEvents1(void) {
|
|||||||
|
|
||||||
mouseX = (int)loc.x - windowX;
|
mouseX = (int)loc.x - windowX;
|
||||||
mouseY = (int)loc.y - windowY;
|
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);
|
Pointer_SetPosition(0, mouseX, mouseY);
|
||||||
|
|
||||||
if (Input_RawMode) Event_RaiseMove(&PointerEvents.RawMoved, 0, dx, dy);
|
if (Input_RawMode) Event_RaiseMove(&PointerEvents.RawMoved, 0, dx, dy);
|
||||||
|
24
src/Window.c
24
src/Window.c
@ -3675,13 +3675,14 @@ static void Window_RefreshBounds(void) {
|
|||||||
CGRect rect;
|
CGRect rect;
|
||||||
|
|
||||||
view = objc_msgSend(winHandle, sel_registerName("contentView"));
|
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;
|
windowX = (int)rect.origin.x;
|
||||||
windowY = (int)rect.origin.y;
|
windowY = (int)rect.origin.y;
|
||||||
Window_Width = (int)rect.size.width;
|
Window_Width = (int)rect.size.width;
|
||||||
Window_Height = (int)rect.size.height;
|
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) {
|
void Window_Init(void) {
|
||||||
@ -3774,7 +3775,7 @@ void Window_ProcessEvents(void) {
|
|||||||
case 4: /* NSRightMouseUp */
|
case 4: /* NSRightMouseUp */
|
||||||
case 26: /* NSOtherMouseUp */
|
case 26: /* NSOtherMouseUp */
|
||||||
key = Window_MapMouse((int)objc_msgSend(ev, sel_registerName("buttonNumber")));
|
key = Window_MapMouse((int)objc_msgSend(ev, sel_registerName("buttonNumber")));
|
||||||
if (key) Input_SetPressed(key, true);
|
if (key) Input_SetPressed(key, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 10: /* NSKeyDown */
|
case 10: /* NSKeyDown */
|
||||||
@ -3795,17 +3796,20 @@ void Window_ProcessEvents(void) {
|
|||||||
case 6: /* NSLeftMouseDragged */
|
case 6: /* NSLeftMouseDragged */
|
||||||
case 7: /* NSRightMouseDragged */
|
case 7: /* NSRightMouseDragged */
|
||||||
case 27: /* NSOtherMouseDragged */
|
case 27: /* NSOtherMouseDragged */
|
||||||
loc = Send_CGPoint((id)objc_getClass("NSEvent"), sel_registerName("mouseLocation"));
|
loc = Send_CGPoint((id)objc_getClass("NSEvent"), sel_registerName("mouseLocation"));
|
||||||
|
mouseX = (int)loc.x - windowX;
|
||||||
mouseX = (int)loc.x - windowX;
|
|
||||||
mouseY = (int)loc.y - windowY;
|
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);
|
Platform_Log2("MOUSE: %i, %i", &mouseX, &mouseY);
|
||||||
Pointer_SetPosition(0, mouseX, mouseY);
|
Pointer_SetPosition(0, mouseX, mouseY);
|
||||||
|
|
||||||
dx = Send_CGFloat(ev, sel_registerName("deltaX"));
|
if (Input_RawMode) {
|
||||||
dy = Send_CGFloat(ev, sel_registerName("deltaY"));
|
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;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user