slouken@47
|
1 |
/*
|
slouken@47
|
2 |
SDL - Simple DirectMedia Layer
|
slouken@6137
|
3 |
Copyright (C) 1997-2012 Sam Lantinga
|
slouken@47
|
4 |
|
slouken@47
|
5 |
This library is free software; you can redistribute it and/or
|
slouken@47
|
6 |
modify it under the terms of the GNU Library General Public
|
slouken@47
|
7 |
License as published by the Free Software Foundation; either
|
slouken@47
|
8 |
version 2 of the License, or (at your option) any later version.
|
slouken@47
|
9 |
|
slouken@47
|
10 |
This library is distributed in the hope that it will be useful,
|
slouken@47
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
slouken@47
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
slouken@47
|
13 |
Library General Public License for more details.
|
slouken@47
|
14 |
|
slouken@47
|
15 |
You should have received a copy of the GNU Library General Public
|
slouken@47
|
16 |
License along with this library; if not, write to the Free
|
slouken@47
|
17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
slouken@47
|
18 |
|
slouken@47
|
19 |
Sam Lantinga
|
slouken@252
|
20 |
slouken@libsdl.org
|
slouken@47
|
21 |
*/
|
slouken@1403
|
22 |
#include "SDL_config.h"
|
slouken@47
|
23 |
|
slouken@761
|
24 |
#include "SDL_QuartzVideo.h"
|
slouken@4070
|
25 |
#include "SDL_QuartzWM.h"
|
icculus@563
|
26 |
|
slouken@47
|
27 |
|
slouken@761
|
28 |
void QZ_FreeWMCursor (_THIS, WMcursor *cursor) {
|
slouken@47
|
29 |
|
slouken@1883
|
30 |
if ( cursor != NULL ) {
|
slouken@1883
|
31 |
[ cursor->nscursor release ];
|
slouken@47
|
32 |
free (cursor);
|
slouken@1883
|
33 |
}
|
slouken@47
|
34 |
}
|
slouken@47
|
35 |
|
slouken@761
|
36 |
WMcursor* QZ_CreateWMCursor (_THIS, Uint8 *data, Uint8 *mask,
|
slouken@390
|
37 |
int w, int h, int hot_x, int hot_y) {
|
slouken@390
|
38 |
WMcursor *cursor;
|
slouken@1883
|
39 |
NSBitmapImageRep *imgrep;
|
slouken@1883
|
40 |
NSImage *img;
|
slouken@1883
|
41 |
unsigned char *planes[5];
|
slouken@1883
|
42 |
int i;
|
slouken@1883
|
43 |
NSAutoreleasePool *pool;
|
slouken@1883
|
44 |
|
slouken@1883
|
45 |
pool = [ [ NSAutoreleasePool alloc ] init ];
|
slouken@1883
|
46 |
|
slouken@390
|
47 |
/* Allocate the cursor memory */
|
slouken@1756
|
48 |
cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
|
slouken@1883
|
49 |
if (cursor == NULL) goto outOfMemory;
|
icculus@5628
|
50 |
|
slouken@1883
|
51 |
/* create the image representation and get the pointers to its storage */
|
icculus@5628
|
52 |
imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceWhiteColorSpace bytesPerRow: (w+7)/8 bitsPerPixel: 0 ] autorelease ];
|
slouken@1883
|
53 |
if (imgrep == nil) goto outOfMemory;
|
slouken@1883
|
54 |
[ imgrep getBitmapDataPlanes: planes ];
|
slouken@168
|
55 |
|
slouken@1883
|
56 |
/* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */
|
slouken@1883
|
57 |
for (i = 0; i < (w+7)/8*h; i++) {
|
icculus@5628
|
58 |
planes[0][i] = data[i] ^ 0xFF;
|
slouken@1883
|
59 |
planes[1][i] = mask[i] | data[i];
|
slouken@1883
|
60 |
}
|
icculus@5628
|
61 |
|
slouken@1883
|
62 |
/* create image and cursor */
|
slouken@1883
|
63 |
img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(w, h) ] autorelease ];
|
slouken@1883
|
64 |
if (img == nil) goto outOfMemory;
|
slouken@1883
|
65 |
[ img addRepresentation: imgrep ];
|
slouken@1883
|
66 |
if (system_version < 0x1030) { /* on 10.2, cursors must be 16*16 */
|
slouken@1883
|
67 |
if (w > 16 || h > 16) { /* too big: scale it down */
|
slouken@1883
|
68 |
[ img setScalesWhenResized: YES ];
|
slouken@1883
|
69 |
hot_x = hot_x*16/w;
|
slouken@1883
|
70 |
hot_y = hot_y*16/h;
|
slouken@1883
|
71 |
}
|
slouken@1883
|
72 |
else { /* too small (or just right): extend it (from the bottom left corner, so hot_y must be adjusted) */
|
slouken@1883
|
73 |
hot_y += 16 - h;
|
slouken@1883
|
74 |
}
|
slouken@1883
|
75 |
[ img setSize: NSMakeSize(16, 16) ];
|
slouken@390
|
76 |
}
|
slouken@1883
|
77 |
cursor->nscursor = [ [ NSCursor alloc ] initWithImage: img hotSpot: NSMakePoint(hot_x, hot_y) ];
|
slouken@1883
|
78 |
if (cursor->nscursor == nil) goto outOfMemory;
|
slouken@390
|
79 |
|
slouken@1883
|
80 |
[ pool release ];
|
slouken@168
|
81 |
return(cursor);
|
slouken@1883
|
82 |
|
slouken@1883
|
83 |
outOfMemory:
|
slouken@1883
|
84 |
[ pool release ];
|
slouken@1883
|
85 |
if (cursor != NULL) SDL_free(cursor);
|
slouken@1883
|
86 |
SDL_OutOfMemory();
|
slouken@1883
|
87 |
return(NULL);
|
slouken@47
|
88 |
}
|
slouken@47
|
89 |
|
slouken@4070
|
90 |
void QZ_UpdateCursor (_THIS) {
|
slouken@4070
|
91 |
BOOL state;
|
slouken@4070
|
92 |
|
slouken@4070
|
93 |
if (cursor_should_be_visible || !(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
|
slouken@4070
|
94 |
state = YES;
|
slouken@4070
|
95 |
} else {
|
slouken@4070
|
96 |
state = NO;
|
slouken@761
|
97 |
}
|
slouken@4070
|
98 |
if (state != cursor_visible) {
|
slouken@4070
|
99 |
if (state) {
|
slouken@4070
|
100 |
[ NSCursor unhide ];
|
slouken@4070
|
101 |
} else {
|
slouken@4070
|
102 |
[ NSCursor hide ];
|
slouken@4070
|
103 |
}
|
slouken@4070
|
104 |
cursor_visible = state;
|
slouken@761
|
105 |
}
|
slouken@761
|
106 |
}
|
slouken@761
|
107 |
|
slouken@779
|
108 |
BOOL QZ_IsMouseInWindow (_THIS) {
|
slouken@4065
|
109 |
if (qz_window == nil || (mode_flags & SDL_FULLSCREEN)) return YES; /*fullscreen*/
|
icculus@1192
|
110 |
else {
|
icculus@1192
|
111 |
NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ];
|
icculus@1192
|
112 |
p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */
|
icculus@1192
|
113 |
return NSPointInRect(p, [ window_view frame ]);
|
icculus@1192
|
114 |
}
|
slouken@779
|
115 |
}
|
slouken@779
|
116 |
|
slouken@761
|
117 |
int QZ_ShowWMCursor (_THIS, WMcursor *cursor) {
|
slouken@47
|
118 |
|
slouken@47
|
119 |
if ( cursor == NULL) {
|
slouken@761
|
120 |
if ( cursor_should_be_visible ) {
|
slouken@761
|
121 |
cursor_should_be_visible = NO;
|
icculus@563
|
122 |
QZ_ChangeGrabState (this, QZ_HIDECURSOR);
|
slouken@47
|
123 |
}
|
slouken@4070
|
124 |
QZ_UpdateCursor(this);
|
slouken@47
|
125 |
}
|
slouken@47
|
126 |
else {
|
icculus@6121
|
127 |
if ( qz_window != nil && !(mode_flags & SDL_FULLSCREEN) ) {
|
slouken@4070
|
128 |
[ qz_window invalidateCursorRectsForView: [ qz_window contentView ] ];
|
slouken@4070
|
129 |
}
|
slouken@761
|
130 |
if ( ! cursor_should_be_visible ) {
|
slouken@761
|
131 |
cursor_should_be_visible = YES;
|
icculus@563
|
132 |
QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
|
slouken@47
|
133 |
}
|
icculus@6121
|
134 |
[ cursor->nscursor performSelectorOnMainThread:@selector(set) withObject:nil waitUntilDone:NO ];
|
slouken@4070
|
135 |
QZ_UpdateCursor(this);
|
slouken@47
|
136 |
}
|
slouken@47
|
137 |
|
slouken@47
|
138 |
return 1;
|
slouken@47
|
139 |
}
|
slouken@47
|
140 |
|
slouken@501
|
141 |
/*
|
slouken@501
|
142 |
Coordinate conversion functions, for convenience
|
slouken@501
|
143 |
Cocoa sets the origin at the lower left corner of the window/screen
|
slouken@501
|
144 |
SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
|
slouken@501
|
145 |
The routines were written so they could be called before SetVideoMode() has finished;
|
slouken@501
|
146 |
this might have limited usefulness at the moment, but the extra cost is trivial.
|
slouken@501
|
147 |
*/
|
slouken@272
|
148 |
|
slouken@272
|
149 |
/* Convert Cocoa screen coordinate to Cocoa window coordinate */
|
slouken@761
|
150 |
void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
|
slouken@47
|
151 |
|
slouken@4392
|
152 |
if ( ! CGDisplayIsCaptured (display_id) )
|
slouken@4392
|
153 |
*p = [ qz_window convertScreenToBase:*p ];
|
slouken@272
|
154 |
}
|
slouken@272
|
155 |
|
slouken@272
|
156 |
|
slouken@272
|
157 |
/* Convert Cocoa window coordinate to Cocoa screen coordinate */
|
slouken@761
|
158 |
void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
|
slouken@272
|
159 |
|
slouken@4392
|
160 |
if ( ! CGDisplayIsCaptured (display_id) )
|
slouken@4392
|
161 |
*p = [ qz_window convertBaseToScreen:*p ];
|
slouken@272
|
162 |
}
|
slouken@272
|
163 |
|
slouken@272
|
164 |
/* Convert SDL coordinate to Cocoa coordinate */
|
slouken@761
|
165 |
void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
|
slouken@272
|
166 |
|
slouken@272
|
167 |
if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
|
slouken@272
|
168 |
|
icculus@876
|
169 |
p->y = CGDisplayPixelsHigh (display_id) - p->y;
|
slouken@272
|
170 |
}
|
slouken@272
|
171 |
else {
|
slouken@934
|
172 |
|
slouken@934
|
173 |
*p = [ window_view convertPoint:*p toView: nil ];
|
icculus@4204
|
174 |
p->y = [window_view frame].size.height - p->y;
|
slouken@272
|
175 |
}
|
slouken@272
|
176 |
}
|
slouken@272
|
177 |
|
slouken@272
|
178 |
/* Convert Cocoa coordinate to SDL coordinate */
|
slouken@761
|
179 |
void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
|
slouken@272
|
180 |
|
slouken@683
|
181 |
if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
|
slouken@683
|
182 |
|
icculus@876
|
183 |
p->y = CGDisplayPixelsHigh (display_id) - p->y;
|
slouken@683
|
184 |
}
|
slouken@683
|
185 |
else {
|
slouken@934
|
186 |
|
slouken@934
|
187 |
*p = [ window_view convertPoint:*p fromView: nil ];
|
icculus@4204
|
188 |
p->y = [window_view frame].size.height - p->y;
|
slouken@683
|
189 |
}
|
slouken@272
|
190 |
}
|
slouken@272
|
191 |
|
slouken@272
|
192 |
/* Convert SDL coordinate to window server (CoreGraphics) coordinate */
|
slouken@761
|
193 |
CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
|
slouken@272
|
194 |
|
slouken@272
|
195 |
CGPoint cgp;
|
slouken@272
|
196 |
|
slouken@272
|
197 |
if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
|
slouken@272
|
198 |
|
slouken@272
|
199 |
int height;
|
slouken@272
|
200 |
|
slouken@272
|
201 |
QZ_PrivateSDLToCocoa (this, p);
|
slouken@272
|
202 |
QZ_PrivateLocalToGlobal (this, p);
|
slouken@272
|
203 |
|
slouken@272
|
204 |
height = CGDisplayPixelsHigh (display_id);
|
slouken@272
|
205 |
p->y = height - p->y;
|
slouken@272
|
206 |
}
|
slouken@272
|
207 |
|
slouken@272
|
208 |
cgp.x = p->x;
|
slouken@272
|
209 |
cgp.y = p->y;
|
slouken@272
|
210 |
|
slouken@272
|
211 |
return cgp;
|
slouken@272
|
212 |
}
|
slouken@272
|
213 |
|
slouken@683
|
214 |
#if 0 /* Dead code */
|
slouken@272
|
215 |
/* Convert window server (CoreGraphics) coordinate to SDL coordinate */
|
slouken@761
|
216 |
void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
|
slouken@272
|
217 |
|
slouken@272
|
218 |
if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
|
slouken@272
|
219 |
|
slouken@272
|
220 |
int height;
|
slouken@272
|
221 |
|
slouken@272
|
222 |
/* Convert CG Global to Cocoa Global */
|
slouken@272
|
223 |
height = CGDisplayPixelsHigh (display_id);
|
slouken@272
|
224 |
p->y = height - p->y;
|
slouken@272
|
225 |
|
slouken@272
|
226 |
QZ_PrivateGlobalToLocal (this, p);
|
slouken@272
|
227 |
QZ_PrivateCocoaToSDL (this, p);
|
slouken@47
|
228 |
}
|
slouken@47
|
229 |
}
|
slouken@683
|
230 |
#endif /* Dead code */
|
slouken@47
|
231 |
|
slouken@761
|
232 |
void QZ_PrivateWarpCursor (_THIS, int x, int y) {
|
icculus@5628
|
233 |
CGEventSourceRef evsrc = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
|
slouken@272
|
234 |
NSPoint p;
|
slouken@272
|
235 |
CGPoint cgp;
|
slouken@47
|
236 |
|
slouken@272
|
237 |
p = NSMakePoint (x, y);
|
icculus@563
|
238 |
cgp = QZ_PrivateSDLToCG (this, &p);
|
icculus@563
|
239 |
|
icculus@563
|
240 |
/* this is the magic call that fixes cursor "freezing" after warp */
|
icculus@5628
|
241 |
CGEventSourceSetLocalEventsSuppressionInterval(evsrc, 0.0);
|
icculus@563
|
242 |
CGWarpMouseCursorPosition (cgp);
|
icculus@5628
|
243 |
CFRelease(evsrc);
|
icculus@6087
|
244 |
SDL_PrivateAppActive (QZ_IsMouseInWindow (this), SDL_APPMOUSEFOCUS);
|
slouken@272
|
245 |
}
|
slouken@272
|
246 |
|
slouken@761
|
247 |
void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
|
slouken@272
|
248 |
|
slouken@47
|
249 |
/* Only allow warping when in foreground */
|
slouken@761
|
250 |
if ( ! [ NSApp isActive ] )
|
slouken@47
|
251 |
return;
|
slouken@47
|
252 |
|
slouken@47
|
253 |
/* Do the actual warp */
|
icculus@1207
|
254 |
if (grab_state != QZ_INVISIBLE_GRAB) QZ_PrivateWarpCursor (this, x, y);
|
icculus@563
|
255 |
|
icculus@563
|
256 |
/* Generate the mouse moved event */
|
icculus@563
|
257 |
SDL_PrivateMouseMotion (0, 0, x, y);
|
slouken@47
|
258 |
}
|
slouken@47
|
259 |
|
slouken@761
|
260 |
void QZ_MoveWMCursor (_THIS, int x, int y) { }
|
slouken@761
|
261 |
void QZ_CheckMouseMode (_THIS) { }
|
slouken@47
|
262 |
|
slouken@761
|
263 |
void QZ_SetCaption (_THIS, const char *title, const char *icon) {
|
slouken@47
|
264 |
|
slouken@158
|
265 |
if ( qz_window != nil ) {
|
slouken@58
|
266 |
NSString *string;
|
slouken@58
|
267 |
if ( title != NULL ) {
|
slouken@951
|
268 |
string = [ [ NSString alloc ] initWithUTF8String:title ];
|
slouken@158
|
269 |
[ qz_window setTitle:string ];
|
slouken@58
|
270 |
[ string release ];
|
slouken@58
|
271 |
}
|
slouken@58
|
272 |
if ( icon != NULL ) {
|
slouken@951
|
273 |
string = [ [ NSString alloc ] initWithUTF8String:icon ];
|
slouken@158
|
274 |
[ qz_window setMiniwindowTitle:string ];
|
slouken@58
|
275 |
[ string release ];
|
slouken@58
|
276 |
}
|
slouken@58
|
277 |
}
|
slouken@47
|
278 |
}
|
slouken@47
|
279 |
|
slouken@761
|
280 |
void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask)
|
slouken@269
|
281 |
{
|
slouken@501
|
282 |
NSBitmapImageRep *imgrep;
|
slouken@501
|
283 |
NSImage *img;
|
slouken@501
|
284 |
SDL_Surface *mergedSurface;
|
slouken@501
|
285 |
NSAutoreleasePool *pool;
|
slouken@1812
|
286 |
Uint8 *pixels;
|
slouken@1812
|
287 |
SDL_bool iconSrcAlpha;
|
slouken@1812
|
288 |
Uint8 iconAlphaValue;
|
slouken@1812
|
289 |
int i, j, maskPitch, index;
|
slouken@501
|
290 |
|
slouken@501
|
291 |
pool = [ [ NSAutoreleasePool alloc ] init ];
|
slouken@1812
|
292 |
|
slouken@1812
|
293 |
imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4*icon->w bitsPerPixel: 32 ] autorelease ];
|
slouken@1812
|
294 |
if (imgrep == nil) goto freePool;
|
slouken@1812
|
295 |
pixels = [ imgrep bitmapData ];
|
slouken@1812
|
296 |
SDL_memset(pixels, 0, 4*icon->w*icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
|
slouken@501
|
297 |
|
slouken@1812
|
298 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
slouken@1812
|
299 |
#define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
|
slouken@1812
|
300 |
#else
|
slouken@1812
|
301 |
#define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
|
slouken@1812
|
302 |
#endif
|
slouken@1812
|
303 |
mergedSurface = SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4*icon->w, BYTEORDER_DEPENDENT_RGBA_MASKS);
|
slouken@1812
|
304 |
if (mergedSurface == NULL) goto freePool;
|
slouken@501
|
305 |
|
slouken@1812
|
306 |
/* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
|
slouken@1812
|
307 |
iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
|
slouken@1812
|
308 |
iconAlphaValue = icon->format->alpha;
|
slouken@1812
|
309 |
SDL_SetAlpha(icon, 0, 255);
|
slouken@1812
|
310 |
SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
|
slouken@1812
|
311 |
if (iconSrcAlpha) SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
|
slouken@592
|
312 |
|
slouken@1812
|
313 |
SDL_FreeSurface(mergedSurface);
|
slouken@501
|
314 |
|
slouken@1812
|
315 |
/* apply mask, source alpha, and premultiply color values by alpha */
|
slouken@1812
|
316 |
maskPitch = (icon->w+7)/8;
|
slouken@1812
|
317 |
for (i = 0; i < icon->h; i++) {
|
slouken@1812
|
318 |
for (j = 0; j < icon->w; j++) {
|
slouken@1812
|
319 |
index = i*4*icon->w + j*4;
|
slouken@1812
|
320 |
if (!(mask[i*maskPitch + j/8] & (128 >> j%8))) {
|
slouken@1812
|
321 |
pixels[index + 3] = 0;
|
slouken@1812
|
322 |
}
|
slouken@1812
|
323 |
else {
|
slouken@1812
|
324 |
if (iconSrcAlpha) {
|
slouken@1812
|
325 |
if (icon->format->Amask == 0) pixels[index + 3] = icon->format->alpha;
|
slouken@1812
|
326 |
}
|
slouken@1812
|
327 |
else {
|
slouken@1812
|
328 |
pixels[index + 3] = 255;
|
slouken@1812
|
329 |
}
|
slouken@1812
|
330 |
}
|
slouken@1812
|
331 |
if (pixels[index + 3] < 255) {
|
slouken@1812
|
332 |
pixels[index + 0] = (Uint16)pixels[index + 0]*pixels[index + 3]/255;
|
slouken@1812
|
333 |
pixels[index + 1] = (Uint16)pixels[index + 1]*pixels[index + 3]/255;
|
slouken@1812
|
334 |
pixels[index + 2] = (Uint16)pixels[index + 2]*pixels[index + 3]/255;
|
slouken@592
|
335 |
}
|
slouken@592
|
336 |
}
|
slouken@501
|
337 |
}
|
slouken@501
|
338 |
|
slouken@1812
|
339 |
img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(icon->w, icon->h) ] autorelease ];
|
slouken@1812
|
340 |
if (img == nil) goto freePool;
|
slouken@501
|
341 |
[ img addRepresentation: imgrep ];
|
slouken@501
|
342 |
[ NSApp setApplicationIconImage:img ];
|
slouken@501
|
343 |
|
slouken@269
|
344 |
freePool:
|
slouken@1812
|
345 |
[ pool release ];
|
slouken@47
|
346 |
}
|
slouken@47
|
347 |
|
slouken@761
|
348 |
int QZ_IconifyWindow (_THIS) {
|
slouken@47
|
349 |
|
slouken@158
|
350 |
if ( ! [ qz_window isMiniaturized ] ) {
|
slouken@158
|
351 |
[ qz_window miniaturize:nil ];
|
slouken@4122
|
352 |
if ( ! [ qz_window isMiniaturized ] ) {
|
slouken@4122
|
353 |
SDL_SetError ("window iconification failed");
|
slouken@4122
|
354 |
return 0;
|
slouken@4122
|
355 |
}
|
slouken@47
|
356 |
return 1;
|
slouken@47
|
357 |
}
|
slouken@47
|
358 |
else {
|
slouken@501
|
359 |
SDL_SetError ("window already iconified");
|
slouken@47
|
360 |
return 0;
|
slouken@47
|
361 |
}
|
slouken@47
|
362 |
}
|
slouken@47
|
363 |
|
slouken@47
|
364 |
/*
|
slouken@761
|
365 |
int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) {
|
slouken@158
|
366 |
info->nsWindowPtr = qz_window;
|
slouken@47
|
367 |
return 0;
|
slouken@47
|
368 |
}*/
|
slouken@47
|
369 |
|
slouken@761
|
370 |
void QZ_ChangeGrabState (_THIS, int action) {
|
icculus@563
|
371 |
|
icculus@563
|
372 |
/*
|
icculus@563
|
373 |
Figure out what the next state should be based on the action.
|
icculus@563
|
374 |
Ignore actions that can't change the current state.
|
icculus@563
|
375 |
*/
|
icculus@563
|
376 |
if ( grab_state == QZ_UNGRABBED ) {
|
icculus@563
|
377 |
if ( action == QZ_ENABLE_GRAB ) {
|
slouken@761
|
378 |
if ( cursor_should_be_visible )
|
icculus@563
|
379 |
grab_state = QZ_VISIBLE_GRAB;
|
icculus@563
|
380 |
else
|
icculus@563
|
381 |
grab_state = QZ_INVISIBLE_GRAB;
|
icculus@563
|
382 |
}
|
icculus@563
|
383 |
}
|
icculus@563
|
384 |
else if ( grab_state == QZ_VISIBLE_GRAB ) {
|
icculus@563
|
385 |
if ( action == QZ_DISABLE_GRAB )
|
icculus@563
|
386 |
grab_state = QZ_UNGRABBED;
|
icculus@563
|
387 |
else if ( action == QZ_HIDECURSOR )
|
icculus@563
|
388 |
grab_state = QZ_INVISIBLE_GRAB;
|
icculus@563
|
389 |
}
|
icculus@563
|
390 |
else {
|
icculus@563
|
391 |
assert( grab_state == QZ_INVISIBLE_GRAB );
|
icculus@563
|
392 |
|
icculus@563
|
393 |
if ( action == QZ_DISABLE_GRAB )
|
icculus@563
|
394 |
grab_state = QZ_UNGRABBED;
|
icculus@563
|
395 |
else if ( action == QZ_SHOWCURSOR )
|
icculus@563
|
396 |
grab_state = QZ_VISIBLE_GRAB;
|
icculus@563
|
397 |
}
|
icculus@563
|
398 |
|
icculus@563
|
399 |
/* now apply the new state */
|
icculus@563
|
400 |
if (grab_state == QZ_UNGRABBED) {
|
icculus@563
|
401 |
|
icculus@563
|
402 |
CGAssociateMouseAndMouseCursorPosition (1);
|
icculus@563
|
403 |
}
|
icculus@563
|
404 |
else if (grab_state == QZ_VISIBLE_GRAB) {
|
icculus@563
|
405 |
|
icculus@563
|
406 |
CGAssociateMouseAndMouseCursorPosition (1);
|
icculus@563
|
407 |
}
|
icculus@563
|
408 |
else {
|
icculus@563
|
409 |
assert( grab_state == QZ_INVISIBLE_GRAB );
|
icculus@563
|
410 |
|
icculus@563
|
411 |
QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
|
icculus@563
|
412 |
CGAssociateMouseAndMouseCursorPosition (0);
|
icculus@563
|
413 |
}
|
icculus@563
|
414 |
}
|
icculus@563
|
415 |
|
slouken@761
|
416 |
SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
|
slouken@47
|
417 |
|
icculus@563
|
418 |
int doGrab = grab_mode & SDL_GRAB_ON;
|
icculus@563
|
419 |
/*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN;*/
|
icculus@563
|
420 |
|
icculus@563
|
421 |
if ( this->screen == NULL ) {
|
icculus@563
|
422 |
SDL_SetError ("QZ_GrabInput: screen is NULL");
|
icculus@563
|
423 |
return SDL_GRAB_OFF;
|
slouken@47
|
424 |
}
|
slouken@47
|
425 |
|
icculus@563
|
426 |
if ( ! video_set ) {
|
icculus@563
|
427 |
/*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */
|
icculus@563
|
428 |
current_grab_mode = grab_mode;
|
icculus@563
|
429 |
return grab_mode; /* Will be set later on mode switch */
|
icculus@563
|
430 |
}
|
icculus@563
|
431 |
|
icculus@563
|
432 |
if ( grab_mode != SDL_GRAB_QUERY ) {
|
icculus@563
|
433 |
if ( doGrab )
|
icculus@563
|
434 |
QZ_ChangeGrabState (this, QZ_ENABLE_GRAB);
|
icculus@563
|
435 |
else
|
icculus@563
|
436 |
QZ_ChangeGrabState (this, QZ_DISABLE_GRAB);
|
icculus@563
|
437 |
|
icculus@563
|
438 |
current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF;
|
icculus@6150
|
439 |
QZ_UpdateCursor(this);
|
icculus@563
|
440 |
}
|
icculus@563
|
441 |
|
slouken@501
|
442 |
return current_grab_mode;
|
slouken@47
|
443 |
}
|