comparison src/video/quartz/SDL_QuartzWM.m @ 501:74262d2647ca

Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Oct 2002 05:07:57 +0000
parents 19e73568a75c
children 04dcaf3da918
comparison
equal deleted inserted replaced
500:c335456c421d 501:74262d2647ca
85 } 85 }
86 86
87 return 1; 87 return 1;
88 } 88 }
89 89
90 /** 90 /*
91 * Coordinate conversion functions, for convenience 91 Coordinate conversion functions, for convenience
92 * Cocoa sets the origin at the lower left corner of the window/screen 92 Cocoa sets the origin at the lower left corner of the window/screen
93 * SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner 93 SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
94 * The routines were written so they could be called before SetVideoMode() has finished; 94 The routines were written so they could be called before SetVideoMode() has finished;
95 * this might have limited usefulness at the moment, but the extra cost is trivial. 95 this might have limited usefulness at the moment, but the extra cost is trivial.
96 **/ 96 */
97 97
98 /* Convert Cocoa screen coordinate to Cocoa window coordinate */ 98 /* Convert Cocoa screen coordinate to Cocoa window coordinate */
99 static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) { 99 static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
100 100
101 *p = [ qz_window convertScreenToBase:*p ]; 101 *p = [ qz_window convertScreenToBase:*p ];
188 } 188 }
189 189
190 static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) { 190 static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
191 191
192 /* Only allow warping when in foreground */ 192 /* Only allow warping when in foreground */
193 if ( ! inForeground ) 193 if ( ! in_foreground )
194 return; 194 return;
195 195
196 /* Do the actual warp */ 196 /* Do the actual warp */
197 QZ_PrivateWarpCursor (this, x, y); 197 QZ_PrivateWarpCursor (this, x, y);
198 } 198 }
217 } 217 }
218 } 218 }
219 219
220 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) 220 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask)
221 { 221 {
222 NSBitmapImageRep *imgrep; 222 NSBitmapImageRep *imgrep;
223 NSImage *img; 223 NSImage *img;
224 SDL_Surface *mergedSurface; 224 SDL_Surface *mergedSurface;
225 Uint8 *surfPtr; 225 Uint8 *surfPtr;
226 int i,j,masksize; 226 int i,j,masksize;
227 NSAutoreleasePool *pool; 227 NSAutoreleasePool *pool;
228 SDL_Rect rrect; 228 SDL_Rect rrect;
229 NSSize imgSize = {icon->w, icon->h}; 229 NSSize imgSize = {icon->w, icon->h};
230 pool = [ [ NSAutoreleasePool alloc ] init ]; 230
231 SDL_GetClipRect(icon, &rrect); 231 pool = [ [ NSAutoreleasePool alloc ] init ];
232 /* create a big endian RGBA surface */ 232 SDL_GetClipRect(icon, &rrect);
233 mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 233
234 icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0); 234 /* create a big endian RGBA surface */
235 if (mergedSurface==NULL) { 235 mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
236 icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
237 if (mergedSurface==NULL) {
236 NSLog(@"Error creating surface for merge"); 238 NSLog(@"Error creating surface for merge");
237 goto freePool; 239 goto freePool;
238 } 240 }
239 if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) { 241
240 NSLog(@"Error blitting to mergedSurface"); 242 if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
241 goto freePool; 243 NSLog(@"Error blitting to mergedSurface");
242 } 244 goto freePool;
243 if (mask) { 245 }
244 masksize=icon->w*icon->h; 246
245 surfPtr = (Uint8 *)mergedSurface->pixels; 247 if (mask) {
246 #define ALPHASHIFT 3 248 masksize=icon->w*icon->h;
247 for (i=0;i<masksize;i+=8) 249 surfPtr = (Uint8 *)mergedSurface->pixels;
248 for (j=0;j<8;j++) 250 #define ALPHASHIFT 3
249 surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00; 251 for (i=0;i<masksize;i+=8)
250 } 252 for (j=0;j<8;j++)
251 imgrep = [ [ NSBitmapImageRep alloc] 253 surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
252 initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 254 }
253 pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 255
254 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 256 imgrep = [ [ NSBitmapImageRep alloc]
255 bytesPerRow:icon->w<<2 bitsPerPixel:32 ]; 257 initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels
256 img = [ [ NSImage alloc ] initWithSize:imgSize ]; 258 pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4
257 [ img addRepresentation: imgrep ]; 259 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
258 [ NSApp setApplicationIconImage:img ]; 260 bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
259 [ img release ]; 261
260 [ imgrep release ]; 262 img = [ [ NSImage alloc ] initWithSize:imgSize ];
261 SDL_FreeSurface(mergedSurface); 263
264 [ img addRepresentation: imgrep ];
265 [ NSApp setApplicationIconImage:img ];
266
267 [ img release ];
268 [ imgrep release ];
269 SDL_FreeSurface(mergedSurface);
262 freePool: 270 freePool:
263 [pool release]; 271 [pool release];
264 } 272 }
265 273
266 static int QZ_IconifyWindow (_THIS) { 274 static int QZ_IconifyWindow (_THIS) {
267 275
268 /* Bug! minimize erases the framebuffer */
269 if ( ! [ qz_window isMiniaturized ] ) { 276 if ( ! [ qz_window isMiniaturized ] ) {
270 [ qz_window miniaturize:nil ]; 277 [ qz_window miniaturize:nil ];
271 return 1; 278 return 1;
272 } 279 }
273 else { 280 else {
274 SDL_SetError ("qz_window already iconified"); 281 SDL_SetError ("window already iconified");
275 return 0; 282 return 0;
276 } 283 }
277 } 284 }
278 285
279 /* 286 /*
287 switch (grab_mode) { 294 switch (grab_mode) {
288 case SDL_GRAB_QUERY: 295 case SDL_GRAB_QUERY:
289 break; 296 break;
290 case SDL_GRAB_OFF: 297 case SDL_GRAB_OFF:
291 CGAssociateMouseAndMouseCursorPosition (1); 298 CGAssociateMouseAndMouseCursorPosition (1);
292 currentGrabMode = SDL_GRAB_OFF; 299 current_grab_mode = SDL_GRAB_OFF;
293 break; 300 break;
294 case SDL_GRAB_ON: 301 case SDL_GRAB_ON:
295 QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); 302 QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
296 CGAssociateMouseAndMouseCursorPosition (0); 303 CGAssociateMouseAndMouseCursorPosition (0);
297 currentGrabMode = SDL_GRAB_ON; 304 current_grab_mode = SDL_GRAB_ON;
298 break; 305 break;
299 case SDL_GRAB_FULLSCREEN: 306 case SDL_GRAB_FULLSCREEN:
300 break; 307 break;
301 } 308 }
302 309
303 return currentGrabMode; 310 return current_grab_mode;
304 } 311 }
312
313 /* Resize icon, BMP format */
314 static unsigned char QZ_ResizeIcon[] = {
315 0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
316 0x00,0x00,0x0d,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
317 0x00,0x00,0xfb,0x01,0x00,0x00,0x13,0x0b,0x00,0x00,0x13,0x0b,0x00,0x00,0x00,0x00,
318 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
319 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
320 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
321 0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,
322 0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
323 0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xda,0xda,0xda,0x87,
324 0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,
325 0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
326 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0xd5,0xd5,0x87,0x87,0x87,0xe8,0xe8,0xe8,
327 0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,
328 0xda,0xda,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
329 0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,
330 0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
331 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,
332 0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
333 0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
334 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,
335 0xe8,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
336 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
337 0xff,0xff,0xff,0xd9,0xd9,0xd9,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xdc,
338 0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
339 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,
340 0xdb,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
341 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
342 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,0xdb,0x87,0x87,0x87,0xe8,
343 0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
344 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
345 0xff,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
346 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
347 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdc,
348 0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
349 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
350 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
351 };
352
353 static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
354
355 /* Check if we should draw the resize icon */
356 if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
357
358 Rect icon;
359 SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13,
360 SDL_VideoSurface->w, SDL_VideoSurface->h);
361
362 if (RectInRgn (&icon, dirtyRegion)) {
363
364 SDL_Rect icon_rect;
365
366 /* Create the icon image */
367 if (resize_icon == NULL) {
368
369 SDL_RWops *rw;
370 SDL_Surface *tmp;
371
372 rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
373 tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
374
375 resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);
376 SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
377
378 SDL_FreeSurface (tmp);
379 }
380
381 icon_rect.x = SDL_VideoSurface->w - 13;
382 icon_rect.y = SDL_VideoSurface->h - 13;
383 icon_rect.w = 13;
384 icon_rect.h = 13;
385
386 SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
387 }
388 }
389 }