21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_COCOA
31 #include "../../events/SDL_mouse_c.h"
35 #ifdef DEBUG_COCOAMOUSE
36 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
38 #define DLog(...) do { } while (0)
47 static unsigned char cursorBytes[] = {
48 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
50 0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
51 0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
52 0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
55 NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
56 length:sizeof(cursorBytes)
58 NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
69 Cocoa_CreateDefaultCursor()
75 nscursor = [NSCursor arrowCursor];
93 NSCursor *nscursor =
NULL;
98 nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
117 NSCursor *nscursor =
NULL;
122 nscursor = [NSCursor arrowCursor];
125 nscursor = [NSCursor IBeamCursor];
128 nscursor = [NSCursor arrowCursor];
131 nscursor = [NSCursor crosshairCursor];
134 nscursor = [NSCursor arrowCursor];
138 nscursor = [NSCursor closedHandCursor];
141 nscursor = [NSCursor resizeLeftRightCursor];
144 nscursor = [NSCursor resizeUpDownCursor];
147 nscursor = [NSCursor closedHandCursor];
150 nscursor = [NSCursor operationNotAllowedCursor];
153 nscursor = [NSCursor pointingHandCursor];
191 [driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
192 withObject:[driverdata->nswindow contentView]
200 SDL_FindWindowAtPoint(
const int x,
const int y)
215 Cocoa_WarpMouseGlobal(
int x,
int y)
220 if ([
data->listener isMoving]) {
221 DLog(
"Postponing warp, window being moved.");
222 [data->listener setPendingMoveX:x Y:y];
226 const CGPoint point = CGPointMake((
float)
x, (
float)
y);
230 CGWarpMouseCursorPosition(point);
237 CGAssociateMouseAndMouseCursorPosition(YES);
276 if ([
data->listener isMoving]) {
283 result = CGAssociateMouseAndMouseCursorPosition(NO);
285 DLog(
"Turning off.");
286 result = CGAssociateMouseAndMouseCursorPosition(YES);
288 if (
result != kCGErrorSuccess) {
289 return SDL_SetError(
"CGAssociateMouseAndMouseCursorPosition() failed");
312 Cocoa_GetGlobalMouseState(
int *
x,
int *
y)
314 const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
315 const NSPoint cocoaLocation = [NSEvent mouseLocation];
318 *
x = (int) cocoaLocation.x;
319 *
y = (
int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.
y);
335 if (driverdata ==
NULL) {
354 const NSPoint
location = [NSEvent mouseLocation];
364 case NSEventTypeMouseMoved:
365 case NSEventTypeLeftMouseDragged:
366 case NSEventTypeRightMouseDragged:
367 case NSEventTypeOtherMouseDragged:
385 const NSPoint
location = [NSEvent mouseLocation];
386 const CGFloat lastMoveX = driverdata->
lastMoveX;
387 const CGFloat lastMoveY = driverdata->
lastMoveY;
399 NSRect windowRect = [[[event window] contentView] frame];
400 if (!NSMouseInRect([
event locationInWindow], windowRect, NO)) {
405 float deltaX = [event deltaX];
406 float deltaY = [event deltaY];
409 deltaX += (lastMoveX - driverdata->lastWarpX);
410 deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
412 DLog(
"Motion was (%g, %g), offset to (%g, %g)", [
event deltaX], [
event deltaY], deltaX, deltaY);
427 CGFloat
x = -[
event deltaX];
428 CGFloat
y = [event deltaY];
431 if ([
event respondsToSelector:
@selector(isDirectionInvertedFromDevice)]) {
432 if ([
event isDirectionInvertedFromDevice] == YES) {
462 DLog(
"(%g, %g)",
x,
y);