author | Sam Lantinga <slouken@libsdl.org> |
Wed, 23 Feb 2011 15:06:14 -0800 | |
changeset 5391 | 06b239f48b91 |
parent 5387 | 03c79d46bf5c |
child 5405 | 64fa8526e1ce |
permissions | -rw-r--r-- |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
/* |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 |
SDL - Simple DirectMedia Layer |
5262 | 3 |
Copyright (C) 1997-2011 Sam Lantinga |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
|
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 |
This library is free software; you can redistribute it and/or |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
modify it under the terms of the GNU Lesser General Public |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
License as published by the Free Software Foundation; either |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
version 2.1 of the License, or (at your option) any later version. |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
|
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 |
This library is distributed in the hope that it will be useful, |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 |
Lesser General Public License for more details. |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
|
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 |
You should have received a copy of the GNU Lesser General Public |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 |
License along with this library; if not, write to the Free Software |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
|
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 |
Sam Lantinga |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
slouken@libsdl.org |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
*/ |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
#include "SDL_config.h" |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
|
3517
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
24 |
#include "SDL_events.h" |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
#include "SDL_cocoavideo.h" |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
|
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
#include "../../events/SDL_mouse_c.h" |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
|
5376
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
29 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
30 |
static SDL_Cursor * |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
31 |
Cocoa_CreateDefaultCursor() |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
32 |
{ |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
33 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
34 |
NSCursor *nscursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
35 |
SDL_Cursor *cursor = NULL; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
36 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
37 |
nscursor = [NSCursor arrowCursor]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
38 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
39 |
if (nscursor) { |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
40 |
cursor = SDL_calloc(1, sizeof(*cursor)); |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
41 |
if (cursor) { |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
42 |
cursor->driverdata = nscursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
43 |
[nscursor retain]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
44 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
45 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
46 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
47 |
[pool release]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
48 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
49 |
return cursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
50 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
51 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
52 |
static SDL_Cursor * |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
53 |
Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
54 |
{ |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
55 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
56 |
NSImage *nsimage; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
57 |
NSCursor *nscursor = NULL; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
58 |
SDL_Cursor *cursor = NULL; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
59 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
60 |
nsimage = Cocoa_CreateImage(surface); |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
61 |
if (nsimage) { |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
62 |
nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
63 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
64 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
65 |
if (nscursor) { |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
66 |
cursor = SDL_calloc(1, sizeof(*cursor)); |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
67 |
if (cursor) { |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
68 |
cursor->driverdata = nscursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
69 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
70 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
71 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
72 |
[pool release]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
73 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
74 |
return cursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
75 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
76 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
77 |
static void |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
78 |
Cocoa_FreeCursor(SDL_Cursor * cursor) |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
79 |
{ |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
80 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
81 |
NSCursor *nscursor = (NSCursor *)cursor->driverdata; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
82 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
83 |
[nscursor release]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
84 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
85 |
[pool release]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
86 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
87 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
88 |
static int |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
89 |
Cocoa_ShowCursor(SDL_Cursor * cursor) |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
90 |
{ |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
91 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
92 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
93 |
if (SDL_GetMouseFocus()) { |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
94 |
if (cursor) { |
5387
03c79d46bf5c
Actually set the cursor! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5376
diff
changeset
|
95 |
NSCursor *nscursor = (NSCursor *)cursor->driverdata; |
03c79d46bf5c
Actually set the cursor! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5376
diff
changeset
|
96 |
|
03c79d46bf5c
Actually set the cursor! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5376
diff
changeset
|
97 |
[nscursor set]; |
5376
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
98 |
[NSCursor unhide]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
99 |
} else { |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
100 |
[NSCursor hide]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
101 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
102 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
103 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
104 |
[pool release]; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
105 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
106 |
return 0; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
107 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
108 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
109 |
static void |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
110 |
Cocoa_WarpMouse(SDL_Window * window, int x, int y) |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
111 |
{ |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
112 |
CGPoint point; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
113 |
|
5391
06b239f48b91
Fixed compile error on some versions of Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
5387
diff
changeset
|
114 |
point.x = (float)window->x + x; |
06b239f48b91
Fixed compile error on some versions of Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents:
5387
diff
changeset
|
115 |
point.y = (float)window->y + y; |
5376
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
116 |
CGWarpMouseCursorPosition(point); |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
117 |
} |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
118 |
|
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
void |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
Cocoa_InitMouse(_THIS) |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
{ |
5376
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
122 |
SDL_Mouse *mouse = SDL_GetMouse(); |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
123 |
SDL_Cursor *cursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
124 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
125 |
mouse->CreateCursor = Cocoa_CreateCursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
126 |
mouse->ShowCursor = Cocoa_ShowCursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
127 |
mouse->WarpMouse = Cocoa_WarpMouse; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
128 |
mouse->FreeCursor = Cocoa_FreeCursor; |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
129 |
|
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
130 |
cursor = Cocoa_CreateDefaultCursor(); |
183ec2d4485c
Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
5371
diff
changeset
|
131 |
mouse->cursors = mouse->cur_cursor = cursor; |
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
} |
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 |
|
3517
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
134 |
static int |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
135 |
ConvertMouseButtonToSDL(int button) |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
136 |
{ |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
137 |
switch (button) |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
138 |
{ |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
139 |
case 0: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
140 |
return(SDL_BUTTON_LEFT); /* 1 */ |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
141 |
case 1: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
142 |
return(SDL_BUTTON_RIGHT); /* 3 */ |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
143 |
case 2: |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
144 |
return(SDL_BUTTON_MIDDLE); /* 2 */ |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
145 |
} |
5060
2170edcdfbd0
Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents:
5058
diff
changeset
|
146 |
return button+1; |
3517
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
147 |
} |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
148 |
|
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
149 |
void |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
150 |
Cocoa_HandleMouseEvent(_THIS, NSEvent *event) |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
151 |
{ |
5371
fc3d3d580777
Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
152 |
/* We're correctly using views even in fullscreen mode now */ |
3517
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
153 |
} |
e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
154 |
|
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 |
void |
5057
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
156 |
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
157 |
{ |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
158 |
float x = [event deltaX]; |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
159 |
float y = [event deltaY]; |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
160 |
|
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
161 |
if (x > 0) { |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
162 |
x += 0.9f; |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
163 |
} else if (x < 0) { |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
164 |
x -= 0.9f; |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
165 |
} |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
166 |
if (y > 0) { |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
167 |
y += 0.9f; |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
168 |
} else if (y < 0) { |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
169 |
y -= 0.9f; |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
170 |
} |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
171 |
SDL_SendMouseWheel(window, (int)x, (int)y); |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
172 |
} |
bdff53ed6c8b
Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents:
4498
diff
changeset
|
173 |
|
5058
03db7d4b02b4
Moved function for consistency
Sam Lantinga <slouken@libsdl.org>
parents:
5057
diff
changeset
|
174 |
void |
03db7d4b02b4
Moved function for consistency
Sam Lantinga <slouken@libsdl.org>
parents:
5057
diff
changeset
|
175 |
Cocoa_QuitMouse(_THIS) |
03db7d4b02b4
Moved function for consistency
Sam Lantinga <slouken@libsdl.org>
parents:
5057
diff
changeset
|
176 |
{ |
03db7d4b02b4
Moved function for consistency
Sam Lantinga <slouken@libsdl.org>
parents:
5057
diff
changeset
|
177 |
} |
03db7d4b02b4
Moved function for consistency
Sam Lantinga <slouken@libsdl.org>
parents:
5057
diff
changeset
|
178 |
|
1931
103c6fec2a60
The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 |
/* vi: set ts=4 sw=4 expandtab: */ |