Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
This commit is contained in:
parent
ada3863500
commit
22779f35b2
4 changed files with 112 additions and 9 deletions
|
@ -37,6 +37,10 @@ static SDL_Mouse SDL_mouse;
|
||||||
int
|
int
|
||||||
SDL_MouseInit(void)
|
SDL_MouseInit(void)
|
||||||
{
|
{
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
|
||||||
|
mouse->cursor_shown = SDL_TRUE;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +50,6 @@ SDL_GetMouse(void)
|
||||||
return &SDL_mouse;
|
return &SDL_mouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SDL_ResetMouse(void)
|
|
||||||
{
|
|
||||||
/* FIXME */
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Window *
|
SDL_Window *
|
||||||
SDL_GetMouseFocus(void)
|
SDL_GetMouseFocus(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,9 +72,6 @@ extern int SDL_MouseInit(void);
|
||||||
/* Get the mouse state structure */
|
/* Get the mouse state structure */
|
||||||
SDL_Mouse *SDL_GetMouse(void);
|
SDL_Mouse *SDL_GetMouse(void);
|
||||||
|
|
||||||
/* Clear the mouse state */
|
|
||||||
extern void SDL_ResetMouse(void);
|
|
||||||
|
|
||||||
/* Set the mouse focus window */
|
/* Set the mouse focus window */
|
||||||
extern void SDL_SetMouseFocus(SDL_Window * window);
|
extern void SDL_SetMouseFocus(SDL_Window * window);
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,106 @@
|
||||||
|
|
||||||
#include "../../events/SDL_mouse_c.h"
|
#include "../../events/SDL_mouse_c.h"
|
||||||
|
|
||||||
|
|
||||||
|
static SDL_Cursor *
|
||||||
|
Cocoa_CreateDefaultCursor()
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
NSCursor *nscursor;
|
||||||
|
SDL_Cursor *cursor = NULL;
|
||||||
|
|
||||||
|
nscursor = [NSCursor arrowCursor];
|
||||||
|
|
||||||
|
if (nscursor) {
|
||||||
|
cursor = SDL_calloc(1, sizeof(*cursor));
|
||||||
|
if (cursor) {
|
||||||
|
cursor->driverdata = nscursor;
|
||||||
|
[nscursor retain];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SDL_Cursor *
|
||||||
|
Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
NSImage *nsimage;
|
||||||
|
NSCursor *nscursor = NULL;
|
||||||
|
SDL_Cursor *cursor = NULL;
|
||||||
|
|
||||||
|
nsimage = Cocoa_CreateImage(surface);
|
||||||
|
if (nsimage) {
|
||||||
|
nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nscursor) {
|
||||||
|
cursor = SDL_calloc(1, sizeof(*cursor));
|
||||||
|
if (cursor) {
|
||||||
|
cursor->driverdata = nscursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Cocoa_FreeCursor(SDL_Cursor * cursor)
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
NSCursor *nscursor = (NSCursor *)cursor->driverdata;
|
||||||
|
|
||||||
|
[nscursor release];
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
Cocoa_ShowCursor(SDL_Cursor * cursor)
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
if (SDL_GetMouseFocus()) {
|
||||||
|
if (cursor) {
|
||||||
|
[NSCursor unhide];
|
||||||
|
} else {
|
||||||
|
[NSCursor hide];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Cocoa_WarpMouse(SDL_Window * window, int x, int y)
|
||||||
|
{
|
||||||
|
CGPoint point;
|
||||||
|
|
||||||
|
point.x = (CGFloat)window->x + x;
|
||||||
|
point.y = (CGFloat)window->y + y;
|
||||||
|
CGWarpMouseCursorPosition(point);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Cocoa_InitMouse(_THIS)
|
Cocoa_InitMouse(_THIS)
|
||||||
{
|
{
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
SDL_Cursor *cursor;
|
||||||
|
|
||||||
|
mouse->CreateCursor = Cocoa_CreateCursor;
|
||||||
|
mouse->ShowCursor = Cocoa_ShowCursor;
|
||||||
|
mouse->WarpMouse = Cocoa_WarpMouse;
|
||||||
|
mouse->FreeCursor = Cocoa_FreeCursor;
|
||||||
|
|
||||||
|
cursor = Cocoa_CreateDefaultCursor();
|
||||||
|
mouse->cursors = mouse->cur_cursor = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -251,12 +251,19 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
||||||
|
|
||||||
- (void)mouseEntered:(NSEvent *)theEvent
|
- (void)mouseEntered:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
|
||||||
SDL_SetMouseFocus(_data->window);
|
SDL_SetMouseFocus(_data->window);
|
||||||
|
|
||||||
|
if (!mouse->cursor_shown) {
|
||||||
|
[NSCursor hide];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseExited:(NSEvent *)theEvent
|
- (void)mouseExited:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
SDL_Window *window = _data->window;
|
SDL_Window *window = _data->window;
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
|
||||||
if (SDL_GetMouseFocus() == window) {
|
if (SDL_GetMouseFocus() == window) {
|
||||||
if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
|
if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
|
||||||
|
@ -276,6 +283,10 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
||||||
SDL_SetMouseFocus(NULL);
|
SDL_SetMouseFocus(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mouse->cursor_shown) {
|
||||||
|
[NSCursor unhide];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseMoved:(NSEvent *)theEvent
|
- (void)mouseMoved:(NSEvent *)theEvent
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue