21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_COCOA 30 #include "../../events/SDL_mouse_c.h" 34 #ifdef DEBUG_COCOAMOUSE 35 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__) 37 #define DLog(...) do { } while (0) 46 static unsigned char cursorBytes[] = {
47 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
49 0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
50 0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
51 0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
54 NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
55 length:sizeof(cursorBytes)
57 NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
68 Cocoa_CreateDefaultCursor()
74 nscursor = [NSCursor arrowCursor];
88 Cocoa_CreateCursor(
SDL_Surface * surface,
int hot_x,
int hot_y)
92 NSCursor *nscursor =
NULL;
97 nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
116 NSCursor *nscursor =
NULL;
121 nscursor = [NSCursor arrowCursor];
124 nscursor = [NSCursor IBeamCursor];
127 nscursor = [NSCursor arrowCursor];
130 nscursor = [NSCursor crosshairCursor];
133 nscursor = [NSCursor arrowCursor];
137 nscursor = [NSCursor closedHandCursor];
140 nscursor = [NSCursor resizeLeftRightCursor];
143 nscursor = [NSCursor resizeUpDownCursor];
146 nscursor = [NSCursor closedHandCursor];
149 nscursor = [NSCursor operationNotAllowedCursor];
152 nscursor = [NSCursor pointingHandCursor];
175 NSCursor *nscursor = (NSCursor *)cursor->
driverdata;
187 for (; window !=
NULL; window = window->
next) {
190 [driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
191 withObject:[driverdata->nswindow contentView]
199 SDL_FindWindowAtPoint(
const int x,
const int y)
214 Cocoa_WarpMouseGlobal(
int x,
int y)
220 DLog(
"Postponing warp, window being moved.");
221 [data->listener setPendingMoveX:x Y:y];
225 const CGPoint point = CGPointMake((
float)x, (
float)y);
229 CGWarpMouseCursorPosition(point);
236 CGAssociateMouseAndMouseCursorPosition(YES);
243 SDL_Window *win = SDL_FindWindowAtPoint(x, y);
255 Cocoa_WarpMouse(
SDL_Window * window,
int x,
int y)
257 Cocoa_WarpMouseGlobal(x + window->
x, y + window->
y);
282 result = CGAssociateMouseAndMouseCursorPosition(NO);
284 DLog(
"Turning off.");
285 result = CGAssociateMouseAndMouseCursorPosition(YES);
287 if (result != kCGErrorSuccess) {
288 return SDL_SetError(
"CGAssociateMouseAndMouseCursorPosition() failed");
311 Cocoa_GetGlobalMouseState(
int *x,
int *y)
313 const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
314 const NSPoint cocoaLocation = [NSEvent mouseLocation];
317 for (NSScreen *
screen in [NSScreen screens]) {
318 NSRect
frame = [screen frame];
319 if (NSMouseInRect(cocoaLocation, frame, NO)) {
320 *x = (int) cocoaLocation.x;
321 *y = (
int) ((frame.origin.y + frame.
size.
height) - cocoaLocation.y);
357 const NSPoint
location = [NSEvent mouseLocation];
365 switch ([event
type]) {
367 case NSLeftMouseDragged:
368 case NSRightMouseDragged:
369 case NSOtherMouseDragged:
386 const NSPoint
location = [NSEvent mouseLocation];
387 const CGFloat lastMoveX = driverdata->
lastMoveX;
388 const CGFloat lastMoveY = driverdata->
lastMoveY;
391 DLog(
"Last seen mouse: (%g, %g)", location.x, location.y);
399 if ([event window]) {
400 NSRect windowRect = [[[event window] contentView] frame];
401 if (!NSMouseInRect([event locationInWindow], windowRect, NO)) {
406 float deltaX = [event deltaX];
407 float deltaY = [event deltaY];
410 deltaX += (lastMoveX - driverdata->lastWarpX);
411 deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
413 DLog(
"Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
424 CGFloat x = -[event deltaX];
425 CGFloat y = [event deltaY];
428 if ([event respondsToSelector:
@selector(isDirectionInvertedFromDevice)]) {
429 if ([event isDirectionInvertedFromDevice] == YES) {
458 DLog(
"(%g, %g)", x, y);
void Cocoa_InitMouse(_THIS)
SDL_Mouse * SDL_GetMouse(void)
int(* ShowCursor)(SDL_Cursor *cursor)
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint GLint x
int(* SetRelativeMouseMode)(SDL_bool enabled)
#define SDL_BUTTON_X2MASK
static SDL_Window * window
The structure that defines a point.
A collection of pixels used in software blitting.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Uint32(* GetGlobalMouseState)(int *x, int *y)
SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
Returns true if point resides inside a rectangle.
void SDL_SetMouseFocus(SDL_Window *window)
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
uint32_t Uint32
An unsigned 32-bit integer type.
GLint GLint GLsizei GLsizei height
int(* CaptureMouse)(SDL_Window *window)
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
GLuint GLuint GLsizei GLenum type
void * SDL_calloc(size_t nmemb, size_t size)
void Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
GLint GLint GLint GLint GLint GLint y
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
void Cocoa_QuitMouse(_THIS)
Cocoa_WindowListener * listener
#define SDL_BUTTON_X1MASK
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
NSCursor * invisibleCursor()
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
int(* WarpMouseGlobal)(int x, int y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void(* FreeCursor)(SDL_Cursor *cursor)
#define SDL_assert(condition)
#define SDL_GetMouseFocus
The type used to identify a window.
void(* WarpMouse)(SDL_Window *window, int x, int y)
SDL_VideoDevice * SDL_GetVideoDevice(void)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
SDL_MouseWheelDirection
Scroll direction types for the Scroll event.
void Cocoa_InitMouseEventTap(SDL_MouseData *driverdata)
A rectangle, with the origin at the upper left.