mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
Codechange: [OSX] Use relative mouse handling during scrolling.
This commit is contained in:
parent
43326d11d8
commit
649ff5f9f9
@ -524,22 +524,25 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||||||
|
|
||||||
- (void)internalMouseMoveEvent:(NSEvent *)event
|
- (void)internalMouseMoveEvent:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
if (_cursor.fix_at) {
|
||||||
|
_cursor.UpdateCursorPositionRelative(event.deltaX, event.deltaY);
|
||||||
|
} else {
|
||||||
NSPoint pt = [ self mousePositionFromEvent:event ];
|
NSPoint pt = [ self mousePositionFromEvent:event ];
|
||||||
|
_cursor.UpdateCursorPosition(pt.x, pt.y, false);
|
||||||
if (_cursor.UpdateCursorPosition(pt.x, pt.y, false) && [ NSApp isActive ]) {
|
|
||||||
/* Warping cursor when in foreground */
|
|
||||||
NSPoint warp = [ self convertPoint:NSMakePoint(_cursor.pos.x, self.bounds.size.height - _cursor.pos.y) toView:nil ];
|
|
||||||
warp = [ self.window convertRectToScreen:NSMakeRect(warp.x, warp.y, 0, 0) ].origin;
|
|
||||||
warp.y = NSScreen.screens[0].frame.size.height - warp.y;
|
|
||||||
|
|
||||||
/* Do the actual warp */
|
|
||||||
CGWarpMouseCursorPosition(NSPointToCGPoint(warp));
|
|
||||||
/* this is the magic call that fixes cursor "freezing" after warp */
|
|
||||||
CGAssociateMouseAndMouseCursorPosition(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleMouseEvents();
|
HandleMouseEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)internalMouseButtonEvent
|
||||||
|
{
|
||||||
|
bool cur_fix = _cursor.fix_at;
|
||||||
|
HandleMouseEvents();
|
||||||
|
|
||||||
|
/* Cursor fix mode was changed, synchronize with OS. */
|
||||||
|
if (cur_fix != _cursor.fix_at) CGAssociateMouseAndMouseCursorPosition(!_cursor.fix_at);
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)emulateRightButton:(NSEvent *)event
|
- (BOOL)emulateRightButton:(NSEvent *)event
|
||||||
{
|
{
|
||||||
uint32 keymask = 0;
|
uint32 keymask = 0;
|
||||||
@ -564,7 +567,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||||||
[ self rightMouseDown:event ];
|
[ self rightMouseDown:event ];
|
||||||
} else {
|
} else {
|
||||||
_left_button_down = true;
|
_left_button_down = true;
|
||||||
[ self internalMouseMoveEvent:event ];
|
[ self internalMouseButtonEvent ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
- (void)mouseUp:(NSEvent *)event
|
- (void)mouseUp:(NSEvent *)event
|
||||||
@ -574,7 +577,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||||||
} else {
|
} else {
|
||||||
_left_button_down = false;
|
_left_button_down = false;
|
||||||
_left_button_clicked = false;
|
_left_button_clicked = false;
|
||||||
[ self internalMouseMoveEvent:event ];
|
[ self internalMouseButtonEvent ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,12 +589,12 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||||||
{
|
{
|
||||||
_right_button_down = true;
|
_right_button_down = true;
|
||||||
_right_button_clicked = true;
|
_right_button_clicked = true;
|
||||||
[ self internalMouseMoveEvent:event ];
|
[ self internalMouseButtonEvent ];
|
||||||
}
|
}
|
||||||
- (void)rightMouseUp:(NSEvent *)event
|
- (void)rightMouseUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
_right_button_down = false;
|
_right_button_down = false;
|
||||||
[ self internalMouseMoveEvent:event ];
|
[ self internalMouseButtonEvent ];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrollWheel:(NSEvent *)event
|
- (void)scrollWheel:(NSEvent *)event
|
||||||
|
Loading…
Reference in New Issue
Block a user