comparison src/video/quartz/SDL_QuartzWM.m @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 2780f547f5e7
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include "SDL_QuartzVideo.h" 24 #include "SDL_QuartzVideo.h"
25 25
26 26
27 struct WMcursor { 27 struct WMcursor
28 {
28 NSCursor *nscursor; 29 NSCursor *nscursor;
29 }; 30 };
30 31
31 void QZ_FreeWMCursor (_THIS, WMcursor *cursor) { 32 void
32 33 QZ_FreeWMCursor(_THIS, WMcursor * cursor)
33 if ( cursor != NULL ) { 34 {
34 [ cursor->nscursor release ]; 35
35 free (cursor); 36 if (cursor != NULL) {
36 } 37 [cursor->nscursor release];
37 } 38 free(cursor);
38 39 }
39 WMcursor* QZ_CreateWMCursor (_THIS, Uint8 *data, Uint8 *mask, 40 }
40 int w, int h, int hot_x, int hot_y) { 41
42 WMcursor *
43 QZ_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
44 int w, int h, int hot_x, int hot_y)
45 {
41 WMcursor *cursor; 46 WMcursor *cursor;
42 NSBitmapImageRep *imgrep; 47 NSBitmapImageRep *imgrep;
43 NSImage *img; 48 NSImage *img;
44 unsigned char *planes[5]; 49 unsigned char *planes[5];
45 int i; 50 int i;
46 NSAutoreleasePool *pool; 51 NSAutoreleasePool *pool;
47 52
48 pool = [ [ NSAutoreleasePool alloc ] init ]; 53 pool =[[NSAutoreleasePool alloc] init];
49 54
50 /* Allocate the cursor memory */ 55 /* Allocate the cursor memory */
51 cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor)); 56 cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
52 if (cursor == NULL) goto outOfMemory; 57 if (cursor == NULL)
53 58 goto outOfMemory;
59
54 /* create the image representation and get the pointers to its storage */ 60 /* create the image representation and get the pointers to its storage */
55 imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceBlackColorSpace bytesPerRow: (w+7)/8 bitsPerPixel: 0 ] autorelease ]; 61 imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceBlackColorSpace bytesPerRow: (w + 7) / 8 bitsPerPixel:0] autorelease];
56 if (imgrep == nil) goto outOfMemory; 62 if (imgrep == nil)
57 [ imgrep getBitmapDataPlanes: planes ]; 63 goto outOfMemory;
58 64 [imgrep getBitmapDataPlanes:planes];
65
59 /* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */ 66 /* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */
60 for (i = 0; i < (w+7)/8*h; i++) { 67 for (i = 0; i < (w + 7) / 8 * h; i++) {
61 planes[0][i] = data[i]; 68 planes[0][i] = data[i];
62 planes[1][i] = mask[i] | data[i]; 69 planes[1][i] = mask[i] | data[i];
63 } 70 }
64 71
65 /* create image and cursor */ 72 /* create image and cursor */
66 img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(w, h) ] autorelease ]; 73 img =[[[NSImage alloc] initWithSize:NSMakeSize(w, h)] autorelease];
67 if (img == nil) goto outOfMemory; 74 if (img == nil)
68 [ img addRepresentation: imgrep ]; 75 goto outOfMemory;
69 if (system_version < 0x1030) { /* on 10.2, cursors must be 16*16 */ 76 [img addRepresentation:imgrep];
77 if (system_version < 0x1030) { /* on 10.2, cursors must be 16*16 */
70 if (w > 16 || h > 16) { /* too big: scale it down */ 78 if (w > 16 || h > 16) { /* too big: scale it down */
71 [ img setScalesWhenResized: YES ]; 79 [img setScalesWhenResized:YES];
72 hot_x = hot_x*16/w; 80 hot_x = hot_x * 16 / w;
73 hot_y = hot_y*16/h; 81 hot_y = hot_y * 16 / h;
74 } 82 } else { /* too small (or just right): extend it (from the bottom left corner, so hot_y must be adjusted) */
75 else { /* too small (or just right): extend it (from the bottom left corner, so hot_y must be adjusted) */
76 hot_y += 16 - h; 83 hot_y += 16 - h;
77 } 84 }
78 [ img setSize: NSMakeSize(16, 16) ]; 85 [img setSize:NSMakeSize(16, 16)];
79 } 86 }
80 cursor->nscursor = [ [ NSCursor alloc ] initWithImage: img hotSpot: NSMakePoint(hot_x, hot_y) ]; 87 cursor->nscursor =[[NSCursor alloc] initWithImage: img hotSpot:NSMakePoint(hot_x,
81 if (cursor->nscursor == nil) goto outOfMemory; 88 hot_y)];
82 89 if (cursor->nscursor == nil)
83 [ pool release ]; 90 goto outOfMemory;
84 return(cursor); 91
85 92 [pool release];
86 outOfMemory: 93 return (cursor);
87 [ pool release ]; 94
88 if (cursor != NULL) SDL_free(cursor); 95 outOfMemory:
96 [pool release];
97 if (cursor != NULL)
98 SDL_free(cursor);
89 SDL_OutOfMemory(); 99 SDL_OutOfMemory();
90 return(NULL); 100 return (NULL);
91 } 101 }
92 102
93 void QZ_ShowMouse (_THIS) { 103 void
104 QZ_ShowMouse(_THIS)
105 {
94 if (!cursor_visible) { 106 if (!cursor_visible) {
95 [ NSCursor unhide ]; 107 [NSCursor unhide];
96 cursor_visible = YES; 108 cursor_visible = YES;
97 } 109 }
98 } 110 }
99 111
100 void QZ_HideMouse (_THIS) { 112 void
113 QZ_HideMouse(_THIS)
114 {
101 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) { 115 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) {
102 [ NSCursor hide ]; 116 [NSCursor hide];
103 cursor_visible = NO; 117 cursor_visible = NO;
104 } 118 }
105 } 119 }
106 120
107 BOOL QZ_IsMouseInWindow (_THIS) { 121 BOOL
108 if (qz_window == nil) return YES; /*fullscreen*/ 122 QZ_IsMouseInWindow(_THIS)
123 {
124 if (qz_window == nil)
125 return YES; /*fullscreen */
109 else { 126 else {
110 NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ]; 127 NSPoint p =[qz_window mouseLocationOutsideOfEventStream];
111 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" */ 128 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" */
112 return NSPointInRect(p, [ window_view frame ]); 129 return NSPointInRect(p,[window_view frame]);
113 } 130 }
114 } 131 }
115 132
116 int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 133 int
117 134 QZ_ShowWMCursor(_THIS, WMcursor * cursor)
118 if ( cursor == NULL) { 135 {
119 if ( cursor_should_be_visible ) { 136
120 QZ_HideMouse (this); 137 if (cursor == NULL) {
138 if (cursor_should_be_visible) {
139 QZ_HideMouse(this);
121 cursor_should_be_visible = NO; 140 cursor_should_be_visible = NO;
122 QZ_ChangeGrabState (this, QZ_HIDECURSOR); 141 QZ_ChangeGrabState(this, QZ_HIDECURSOR);
123 } 142 }
124 } 143 } else {
125 else { 144 [cursor->nscursor set];
126 [ cursor->nscursor set ]; 145 if (!cursor_should_be_visible) {
127 if ( ! cursor_should_be_visible ) { 146 QZ_ShowMouse(this);
128 QZ_ShowMouse (this);
129 cursor_should_be_visible = YES; 147 cursor_should_be_visible = YES;
130 QZ_ChangeGrabState (this, QZ_SHOWCURSOR); 148 QZ_ChangeGrabState(this, QZ_SHOWCURSOR);
131 } 149 }
132 } 150 }
133 151
134 return 1; 152 return 1;
135 } 153 }
141 The routines were written so they could be called before SetVideoMode() has finished; 159 The routines were written so they could be called before SetVideoMode() has finished;
142 this might have limited usefulness at the moment, but the extra cost is trivial. 160 this might have limited usefulness at the moment, but the extra cost is trivial.
143 */ 161 */
144 162
145 /* Convert Cocoa screen coordinate to Cocoa window coordinate */ 163 /* Convert Cocoa screen coordinate to Cocoa window coordinate */
146 void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) { 164 void
147 165 QZ_PrivateGlobalToLocal(_THIS, NSPoint * p)
148 *p = [ qz_window convertScreenToBase:*p ]; 166 {
167
168 *p =[qz_window convertScreenToBase:*p];
149 } 169 }
150 170
151 171
152 /* Convert Cocoa window coordinate to Cocoa screen coordinate */ 172 /* Convert Cocoa window coordinate to Cocoa screen coordinate */
153 void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) { 173 void
154 174 QZ_PrivateLocalToGlobal(_THIS, NSPoint * p)
155 *p = [ qz_window convertBaseToScreen:*p ]; 175 {
176
177 *p =[qz_window convertBaseToScreen:*p];
156 } 178 }
157 179
158 /* Convert SDL coordinate to Cocoa coordinate */ 180 /* Convert SDL coordinate to Cocoa coordinate */
159 void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) { 181 void
160 182 QZ_PrivateSDLToCocoa(_THIS, NSPoint * p)
161 if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */ 183 {
162 184
163 p->y = CGDisplayPixelsHigh (display_id) - p->y; 185 if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
164 } 186
165 else { 187 p->y = CGDisplayPixelsHigh(display_id) - p->y;
166 188 } else {
167 *p = [ window_view convertPoint:*p toView: nil ]; 189
168 190 *p =[window_view convertPoint: *p toView:nil];
191
169 /* We need a workaround in OpenGL mode */ 192 /* We need a workaround in OpenGL mode */
170 if ( SDL_VideoSurface->flags & SDL_OPENGL ) { 193 if (SDL_VideoSurface->flags & SDL_OPENGL) {
171 p->y = [window_view frame].size.height - p->y; 194 p->y =[window_view frame].size.height - p->y;
172 } 195 }
173 } 196 }
174 } 197 }
175 198
176 /* Convert Cocoa coordinate to SDL coordinate */ 199 /* Convert Cocoa coordinate to SDL coordinate */
177 void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) { 200 void
178 201 QZ_PrivateCocoaToSDL(_THIS, NSPoint * p)
179 if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */ 202 {
180 203
181 p->y = CGDisplayPixelsHigh (display_id) - p->y; 204 if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
182 } 205
183 else { 206 p->y = CGDisplayPixelsHigh(display_id) - p->y;
184 207 } else {
185 *p = [ window_view convertPoint:*p fromView: nil ]; 208
186 209 *p =[window_view convertPoint: *p fromView:nil];
210
187 /* We need a workaround in OpenGL mode */ 211 /* We need a workaround in OpenGL mode */
188 if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_OPENGL) ) { 212 if (SDL_VideoSurface != NULL
189 p->y = [window_view frame].size.height - p->y; 213 && (SDL_VideoSurface->flags & SDL_OPENGL)) {
214 p->y =[window_view frame].size.height - p->y;
190 } 215 }
191 } 216 }
192 } 217 }
193 218
194 /* Convert SDL coordinate to window server (CoreGraphics) coordinate */ 219 /* Convert SDL coordinate to window server (CoreGraphics) coordinate */
195 CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) { 220 CGPoint
196 221 QZ_PrivateSDLToCG(_THIS, NSPoint * p)
222 {
223
197 CGPoint cgp; 224 CGPoint cgp;
198 225
199 if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */ 226 if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
200 227
201 int height; 228 int height;
202 229
203 QZ_PrivateSDLToCocoa (this, p); 230 QZ_PrivateSDLToCocoa(this, p);
204 QZ_PrivateLocalToGlobal (this, p); 231 QZ_PrivateLocalToGlobal(this, p);
205 232
206 height = CGDisplayPixelsHigh (display_id); 233 height = CGDisplayPixelsHigh(display_id);
207 p->y = height - p->y; 234 p->y = height - p->y;
208 } 235 }
209 236
210 cgp.x = p->x; 237 cgp.x = p->x;
211 cgp.y = p->y; 238 cgp.y = p->y;
212 239
213 return cgp; 240 return cgp;
214 } 241 }
215 242
216 #if 0 /* Dead code */ 243 #if 0 /* Dead code */
217 /* Convert window server (CoreGraphics) coordinate to SDL coordinate */ 244 /* Convert window server (CoreGraphics) coordinate to SDL coordinate */
218 void QZ_PrivateCGToSDL (_THIS, NSPoint *p) { 245 void
219 246 QZ_PrivateCGToSDL(_THIS, NSPoint * p)
220 if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */ 247 {
221 248
249 if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
250
222 int height; 251 int height;
223 252
224 /* Convert CG Global to Cocoa Global */ 253 /* Convert CG Global to Cocoa Global */
225 height = CGDisplayPixelsHigh (display_id); 254 height = CGDisplayPixelsHigh(display_id);
226 p->y = height - p->y; 255 p->y = height - p->y;
227 256
228 QZ_PrivateGlobalToLocal (this, p); 257 QZ_PrivateGlobalToLocal(this, p);
229 QZ_PrivateCocoaToSDL (this, p); 258 QZ_PrivateCocoaToSDL(this, p);
230 } 259 }
231 } 260 }
232 #endif /* Dead code */ 261 #endif /* Dead code */
233 262
234 void QZ_PrivateWarpCursor (_THIS, int x, int y) { 263 void
235 264 QZ_PrivateWarpCursor(_THIS, int x, int y)
265 {
266
236 NSPoint p; 267 NSPoint p;
237 CGPoint cgp; 268 CGPoint cgp;
238 269
239 p = NSMakePoint (x, y); 270 p = NSMakePoint(x, y);
240 cgp = QZ_PrivateSDLToCG (this, &p); 271 cgp = QZ_PrivateSDLToCG(this, &p);
241 272
242 /* this is the magic call that fixes cursor "freezing" after warp */ 273 /* this is the magic call that fixes cursor "freezing" after warp */
243 CGSetLocalEventsSuppressionInterval (0.0); 274 CGSetLocalEventsSuppressionInterval(0.0);
244 CGWarpMouseCursorPosition (cgp); 275 CGWarpMouseCursorPosition(cgp);
245 } 276 }
246 277
247 void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) { 278 void
279 QZ_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
280 {
248 281
249 /* Only allow warping when in foreground */ 282 /* Only allow warping when in foreground */
250 if ( ! [ NSApp isActive ] ) 283 if (![NSApp isActive])
251 return; 284 return;
252 285
253 /* Do the actual warp */ 286 /* Do the actual warp */
254 if (grab_state != QZ_INVISIBLE_GRAB) QZ_PrivateWarpCursor (this, x, y); 287 if (grab_state != QZ_INVISIBLE_GRAB)
288 QZ_PrivateWarpCursor(this, x, y);
255 289
256 /* Generate the mouse moved event */ 290 /* Generate the mouse moved event */
257 SDL_PrivateMouseMotion (0, 0, x, y); 291 SDL_PrivateMouseMotion(0, 0, x, y);
258 } 292 }
259 293
260 void QZ_MoveWMCursor (_THIS, int x, int y) { } 294 void
261 void QZ_CheckMouseMode (_THIS) { } 295 QZ_MoveWMCursor(_THIS, int x, int y)
262 296 {
263 void QZ_SetCaption (_THIS, const char *title, const char *icon) { 297 }
264 298 void
265 if ( qz_window != nil ) { 299 QZ_CheckMouseMode(_THIS)
300 {
301 }
302
303 void
304 QZ_SetCaption(_THIS, const char *title, const char *icon)
305 {
306
307 if (qz_window != nil) {
266 NSString *string; 308 NSString *string;
267 if ( title != NULL ) { 309 if (title != NULL) {
268 string = [ [ NSString alloc ] initWithUTF8String:title ]; 310 string =[[NSString alloc] initWithUTF8String:title];
269 [ qz_window setTitle:string ]; 311 [qz_window setTitle:string];
270 [ string release ]; 312 [string release];
271 } 313 }
272 if ( icon != NULL ) { 314 if (icon != NULL) {
273 string = [ [ NSString alloc ] initWithUTF8String:icon ]; 315 string =[[NSString alloc] initWithUTF8String:icon];
274 [ qz_window setMiniwindowTitle:string ]; 316 [qz_window setMiniwindowTitle:string];
275 [ string release ]; 317 [string release];
276 } 318 }
277 } 319 }
278 } 320 }
279 321
280 void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) 322 void
323 QZ_SetIcon(_THIS, SDL_Surface * icon, Uint8 * mask)
281 { 324 {
282 NSBitmapImageRep *imgrep; 325 NSBitmapImageRep *imgrep;
283 NSImage *img; 326 NSImage *img;
284 SDL_Surface *mergedSurface; 327 SDL_Surface *mergedSurface;
285 NSAutoreleasePool *pool; 328 NSAutoreleasePool *pool;
286 Uint8 *pixels; 329 Uint8 *pixels;
287 SDL_bool iconSrcAlpha; 330 SDL_bool iconSrcAlpha;
288 Uint8 iconAlphaValue; 331 Uint8 iconAlphaValue;
289 int i, j, maskPitch, index; 332 int i, j, maskPitch, index;
290 333
291 pool = [ [ NSAutoreleasePool alloc ] init ]; 334 pool =[[NSAutoreleasePool alloc] init];
292 335
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 ]; 336 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];
294 if (imgrep == nil) goto freePool; 337 if (imgrep == nil)
295 pixels = [ imgrep bitmapData ]; 338 goto freePool;
296 SDL_memset(pixels, 0, 4*icon->w*icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */ 339 pixels =[imgrep bitmapData];
297 340 SDL_memset(pixels, 0, 4 * icon->w * icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
341
298 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 342 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
299 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF 343 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
300 #else 344 #else
301 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 345 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
302 #endif 346 #endif
303 mergedSurface = SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4*icon->w, BYTEORDER_DEPENDENT_RGBA_MASKS); 347 mergedSurface =
304 if (mergedSurface == NULL) goto freePool; 348 SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4 * icon->w,
305 349 BYTEORDER_DEPENDENT_RGBA_MASKS);
350 if (mergedSurface == NULL)
351 goto freePool;
352
306 /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */ 353 /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
307 iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0); 354 iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
308 iconAlphaValue = icon->format->alpha; 355 iconAlphaValue = icon->format->alpha;
309 SDL_SetAlpha(icon, 0, 255); 356 SDL_SetAlpha(icon, 0, 255);
310 SDL_BlitSurface(icon, NULL, mergedSurface, NULL); 357 SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
311 if (iconSrcAlpha) SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue); 358 if (iconSrcAlpha)
312 359 SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
360
313 SDL_FreeSurface(mergedSurface); 361 SDL_FreeSurface(mergedSurface);
314 362
315 /* apply mask, source alpha, and premultiply color values by alpha */ 363 /* apply mask, source alpha, and premultiply color values by alpha */
316 maskPitch = (icon->w+7)/8; 364 maskPitch = (icon->w + 7) / 8;
317 for (i = 0; i < icon->h; i++) { 365 for (i = 0; i < icon->h; i++) {
318 for (j = 0; j < icon->w; j++) { 366 for (j = 0; j < icon->w; j++) {
319 index = i*4*icon->w + j*4; 367 index = i * 4 * icon->w + j * 4;
320 if (!(mask[i*maskPitch + j/8] & (128 >> j%8))) { 368 if (!(mask[i * maskPitch + j / 8] & (128 >> j % 8))) {
321 pixels[index + 3] = 0; 369 pixels[index + 3] = 0;
322 } 370 } else {
323 else {
324 if (iconSrcAlpha) { 371 if (iconSrcAlpha) {
325 if (icon->format->Amask == 0) pixels[index + 3] = icon->format->alpha; 372 if (icon->format->Amask == 0)
326 } 373 pixels[index + 3] = icon->format->alpha;
327 else { 374 } else {
328 pixels[index + 3] = 255; 375 pixels[index + 3] = 255;
329 } 376 }
330 } 377 }
331 if (pixels[index + 3] < 255) { 378 if (pixels[index + 3] < 255) {
332 pixels[index + 0] = (Uint16)pixels[index + 0]*pixels[index + 3]/255; 379 pixels[index + 0] =
333 pixels[index + 1] = (Uint16)pixels[index + 1]*pixels[index + 3]/255; 380 (Uint16) pixels[index + 0] * pixels[index + 3] / 255;
334 pixels[index + 2] = (Uint16)pixels[index + 2]*pixels[index + 3]/255; 381 pixels[index + 1] =
382 (Uint16) pixels[index + 1] * pixels[index + 3] / 255;
383 pixels[index + 2] =
384 (Uint16) pixels[index + 2] * pixels[index + 3] / 255;
335 } 385 }
336 } 386 }
337 } 387 }
338 388
339 img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(icon->w, icon->h) ] autorelease ]; 389 img =[[[NSImage alloc] initWithSize:NSMakeSize(icon->w,
340 if (img == nil) goto freePool; 390 icon->h)] autorelease];
341 [ img addRepresentation: imgrep ]; 391 if (img == nil)
342 [ NSApp setApplicationIconImage:img ]; 392 goto freePool;
343 393 [img addRepresentation:imgrep];
344 freePool: 394 [NSApp setApplicationIconImage:img];
345 [ pool release ]; 395
346 } 396 freePool:
347 397 [pool release];
348 int QZ_IconifyWindow (_THIS) { 398 }
349 399
350 if ( ! [ qz_window isMiniaturized ] ) { 400 int
351 [ qz_window miniaturize:nil ]; 401 QZ_IconifyWindow(_THIS)
402 {
403
404 if (![qz_window isMiniaturized]) {
405 [qz_window miniaturize:nil];
352 return 1; 406 return 1;
353 } 407 } else {
354 else { 408 SDL_SetError("window already iconified");
355 SDL_SetError ("window already iconified");
356 return 0; 409 return 0;
357 } 410 }
358 } 411 }
359 412
360 /* 413 /*
361 int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) { 414 int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) {
362 info->nsWindowPtr = qz_window; 415 info->nsWindowPtr = qz_window;
363 return 0; 416 return 0;
364 }*/ 417 }*/
365 418
366 void QZ_ChangeGrabState (_THIS, int action) { 419 void
420 QZ_ChangeGrabState(_THIS, int action)
421 {
367 422
368 /* 423 /*
369 Figure out what the next state should be based on the action. 424 Figure out what the next state should be based on the action.
370 Ignore actions that can't change the current state. 425 Ignore actions that can't change the current state.
371 */ 426 */
372 if ( grab_state == QZ_UNGRABBED ) { 427 if (grab_state == QZ_UNGRABBED) {
373 if ( action == QZ_ENABLE_GRAB ) { 428 if (action == QZ_ENABLE_GRAB) {
374 if ( cursor_should_be_visible ) 429 if (cursor_should_be_visible)
375 grab_state = QZ_VISIBLE_GRAB; 430 grab_state = QZ_VISIBLE_GRAB;
376 else 431 else
377 grab_state = QZ_INVISIBLE_GRAB; 432 grab_state = QZ_INVISIBLE_GRAB;
378 } 433 }
379 } 434 } else if (grab_state == QZ_VISIBLE_GRAB) {
380 else if ( grab_state == QZ_VISIBLE_GRAB ) { 435 if (action == QZ_DISABLE_GRAB)
381 if ( action == QZ_DISABLE_GRAB )
382 grab_state = QZ_UNGRABBED; 436 grab_state = QZ_UNGRABBED;
383 else if ( action == QZ_HIDECURSOR ) 437 else if (action == QZ_HIDECURSOR)
384 grab_state = QZ_INVISIBLE_GRAB; 438 grab_state = QZ_INVISIBLE_GRAB;
385 } 439 } else {
386 else { 440 assert(grab_state == QZ_INVISIBLE_GRAB);
387 assert( grab_state == QZ_INVISIBLE_GRAB ); 441
388 442 if (action == QZ_DISABLE_GRAB)
389 if ( action == QZ_DISABLE_GRAB )
390 grab_state = QZ_UNGRABBED; 443 grab_state = QZ_UNGRABBED;
391 else if ( action == QZ_SHOWCURSOR ) 444 else if (action == QZ_SHOWCURSOR)
392 grab_state = QZ_VISIBLE_GRAB; 445 grab_state = QZ_VISIBLE_GRAB;
393 } 446 }
394 447
395 /* now apply the new state */ 448 /* now apply the new state */
396 if (grab_state == QZ_UNGRABBED) { 449 if (grab_state == QZ_UNGRABBED) {
397 450
398 CGAssociateMouseAndMouseCursorPosition (1); 451 CGAssociateMouseAndMouseCursorPosition(1);
399 } 452 } else if (grab_state == QZ_VISIBLE_GRAB) {
400 else if (grab_state == QZ_VISIBLE_GRAB) { 453
401 454 CGAssociateMouseAndMouseCursorPosition(1);
402 CGAssociateMouseAndMouseCursorPosition (1); 455 } else {
403 } 456 assert(grab_state == QZ_INVISIBLE_GRAB);
404 else { 457
405 assert( grab_state == QZ_INVISIBLE_GRAB ); 458 QZ_PrivateWarpCursor(this, SDL_VideoSurface->w / 2,
406 459 SDL_VideoSurface->h / 2);
407 QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); 460 CGAssociateMouseAndMouseCursorPosition(0);
408 CGAssociateMouseAndMouseCursorPosition (0); 461 }
409 } 462 }
410 } 463
411 464 SDL_GrabMode
412 SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) { 465 QZ_GrabInput(_THIS, SDL_GrabMode grab_mode)
466 {
413 467
414 int doGrab = grab_mode & SDL_GRAB_ON; 468 int doGrab = grab_mode & SDL_GRAB_ON;
415 /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN;*/ 469 /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN; */
416 470
417 if ( this->screen == NULL ) { 471 if (this->screen == NULL) {
418 SDL_SetError ("QZ_GrabInput: screen is NULL"); 472 SDL_SetError("QZ_GrabInput: screen is NULL");
419 return SDL_GRAB_OFF; 473 return SDL_GRAB_OFF;
420 } 474 }
421 475
422 if ( ! video_set ) { 476 if (!video_set) {
423 /*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */ 477 /*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */
424 current_grab_mode = grab_mode; 478 current_grab_mode = grab_mode;
425 return grab_mode; /* Will be set later on mode switch */ 479 return grab_mode; /* Will be set later on mode switch */
426 } 480 }
427 481
428 if ( grab_mode != SDL_GRAB_QUERY ) { 482 if (grab_mode != SDL_GRAB_QUERY) {
429 if ( doGrab ) 483 if (doGrab)
430 QZ_ChangeGrabState (this, QZ_ENABLE_GRAB); 484 QZ_ChangeGrabState(this, QZ_ENABLE_GRAB);
431 else 485 else
432 QZ_ChangeGrabState (this, QZ_DISABLE_GRAB); 486 QZ_ChangeGrabState(this, QZ_DISABLE_GRAB);
433 487
434 current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF; 488 current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF;
435 } 489 }
436 490
437 return current_grab_mode; 491 return current_grab_mode;
438 } 492 }