Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
22779f35
Commit
22779f35
authored
Feb 22, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
parent
ada38635
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
9 deletions
+112
-9
SDL_mouse.c
src/events/SDL_mouse.c
+4
-6
SDL_mouse_c.h
src/events/SDL_mouse_c.h
+0
-3
SDL_cocoamouse.m
src/video/cocoa/SDL_cocoamouse.m
+97
-0
SDL_cocoawindow.m
src/video/cocoa/SDL_cocoawindow.m
+11
-0
No files found.
src/events/SDL_mouse.c
View file @
22779f35
...
@@ -37,6 +37,10 @@ static SDL_Mouse SDL_mouse;
...
@@ -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)
...
@@ -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
)
{
{
...
...
src/events/SDL_mouse_c.h
View file @
22779f35
...
@@ -72,9 +72,6 @@ extern int SDL_MouseInit(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
);
...
...
src/video/cocoa/SDL_cocoamouse.m
View file @
22779f35
...
@@ -26,9 +26,106 @@
...
@@ -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
...
...
src/video/cocoa/SDL_cocoawindow.m
View file @
22779f35
...
@@ -251,12 +251,19 @@ static __inline__ void ConvertNSRect(NSRect *r)
...
@@ -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)
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment