From 7bd72959a3d686d1f586eacf563adeaaa1a2f3f7 Mon Sep 17 00:00:00 2001 From: Tim Clem Date: Wed, 19 Jan 2022 11:40:26 -0800 Subject: [PATCH] winemac.drv: Factor common cursor clipping methods into functions. Signed-off-by: Tim Clem Signed-off-by: Alexandre Julliard --- dlls/winemac.drv/cocoa_cursorclipping.m | 46 ++++++++++++++++--------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/dlls/winemac.drv/cocoa_cursorclipping.m b/dlls/winemac.drv/cocoa_cursorclipping.m index 7c0b53e47d9..eaa243ae1a5 100644 --- a/dlls/winemac.drv/cocoa_cursorclipping.m +++ b/dlls/winemac.drv/cocoa_cursorclipping.m @@ -67,6 +67,29 @@ @implementation WarpRecord @end; +static void clip_cursor_location(CGRect cursorClipRect, CGPoint *location) +{ + if (location->x < CGRectGetMinX(cursorClipRect)) + location->x = CGRectGetMinX(cursorClipRect); + if (location->y < CGRectGetMinY(cursorClipRect)) + location->y = CGRectGetMinY(cursorClipRect); + if (location->x > CGRectGetMaxX(cursorClipRect) - 1) + location->x = CGRectGetMaxX(cursorClipRect) - 1; + if (location->y > CGRectGetMaxY(cursorClipRect) - 1) + location->y = CGRectGetMaxY(cursorClipRect) - 1; +} + + +static void scale_rect_for_retina_mode(int mode, CGRect *cursorClipRect) +{ + double scale = mode ? 0.5 : 2.0; + cursorClipRect->origin.x *= scale; + cursorClipRect->origin.y *= scale; + cursorClipRect->size.width *= scale; + cursorClipRect->size.height *= scale; +} + + @implementation WineEventTapClipCursorHandler @synthesize clippingCursor, cursorClipRect; @@ -88,18 +111,6 @@ - (void) dealloc [super dealloc]; } - - (void) clipCursorLocation:(CGPoint*)location - { - if (location->x < CGRectGetMinX(cursorClipRect)) - location->x = CGRectGetMinX(cursorClipRect); - if (location->y < CGRectGetMinY(cursorClipRect)) - location->y = CGRectGetMinY(cursorClipRect); - if (location->x > CGRectGetMaxX(cursorClipRect) - 1) - location->x = CGRectGetMaxX(cursorClipRect) - 1; - if (location->y > CGRectGetMaxY(cursorClipRect) - 1) - location->y = CGRectGetMaxY(cursorClipRect) - 1; - } - - (BOOL) warpCursorTo:(CGPoint*)newLocation from:(const CGPoint*)currentLocation { CGPoint oldLocation; @@ -341,13 +352,14 @@ - (BOOL) stopClippingCursor return TRUE; } + - (void) clipCursorLocation:(CGPoint*)location + { + clip_cursor_location(cursorClipRect, location); + } + - (void) setRetinaMode:(int)mode { - double scale = mode ? 0.5 : 2.0; - cursorClipRect.origin.x *= scale; - cursorClipRect.origin.y *= scale; - cursorClipRect.size.width *= scale; - cursorClipRect.size.height *= scale; + scale_rect_for_retina_mode(mode, &cursorClipRect); } @end