winemac.drv: Factor common cursor clipping methods into functions.

Signed-off-by: Tim Clem <tclem@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Tim Clem 2022-01-19 11:40:26 -08:00 committed by Alexandre Julliard
parent 2e25ba489a
commit 7bd72959a3
1 changed files with 29 additions and 17 deletions

View File

@ -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