diff 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
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzWM.m	Sat Oct 05 04:56:32 2002 +0000
+++ b/src/video/quartz/SDL_QuartzWM.m	Sat Oct 05 05:07:57 2002 +0000
@@ -87,13 +87,13 @@
     return 1;
 }
 
-/**
- * Coordinate conversion functions, for convenience
- * Cocoa sets the origin at the lower left corner of the window/screen
- * SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
- * The routines were written so they could be called before SetVideoMode() has finished;
- * this might have limited usefulness at the moment, but the extra cost is trivial.
- **/
+/*
+    Coordinate conversion functions, for convenience
+    Cocoa sets the origin at the lower left corner of the window/screen
+    SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
+    The routines were written so they could be called before SetVideoMode() has finished;
+    this might have limited usefulness at the moment, but the extra cost is trivial.
+*/
 
 /* Convert Cocoa screen coordinate to Cocoa window coordinate */
 static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
@@ -190,7 +190,7 @@
 static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
 
     /* Only allow warping when in foreground */
-    if ( ! inForeground )
+    if ( ! in_foreground )
         return;
             
     /* Do the actual warp */
@@ -219,59 +219,66 @@
 
 static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
 {
-     NSBitmapImageRep *imgrep;
-     NSImage *img;
-     SDL_Surface *mergedSurface;
-     Uint8 *surfPtr;
-     int i,j,masksize;
-     NSAutoreleasePool *pool;
-     SDL_Rect rrect;
-     NSSize imgSize = {icon->w, icon->h};
-     pool = [ [ NSAutoreleasePool alloc ] init ];
-     SDL_GetClipRect(icon, &rrect);
-     /* create a big endian RGBA surface */
-     mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
-                        icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
-     if (mergedSurface==NULL) {
+    NSBitmapImageRep *imgrep;
+    NSImage *img;
+    SDL_Surface *mergedSurface;
+    Uint8 *surfPtr;
+    int i,j,masksize;
+    NSAutoreleasePool *pool;
+    SDL_Rect rrect;
+    NSSize imgSize = {icon->w, icon->h};
+    
+    pool = [ [ NSAutoreleasePool alloc ] init ];
+    SDL_GetClipRect(icon, &rrect);
+    
+    /* create a big endian RGBA surface */
+    mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
+                    icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
+    if (mergedSurface==NULL) {
         NSLog(@"Error creating surface for merge");
         goto freePool;
     }
-     if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
-         NSLog(@"Error blitting to mergedSurface");
-         goto freePool;
-     }
-     if (mask) {
-     masksize=icon->w*icon->h;
-     surfPtr = (Uint8 *)mergedSurface->pixels;
-     #define ALPHASHIFT 3
-     for (i=0;i<masksize;i+=8)
-         for (j=0;j<8;j++) 
-             surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
-     }
-     imgrep = [ [ NSBitmapImageRep alloc] 
-                     initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
-                         pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
-                         hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
-                         bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
-     img = [ [ NSImage alloc ] initWithSize:imgSize ];
-     [ img addRepresentation: imgrep ];
-     [ NSApp setApplicationIconImage:img ];
-     [ img release ];
-     [ imgrep release ];
-     SDL_FreeSurface(mergedSurface);
+    
+    if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
+        NSLog(@"Error blitting to mergedSurface");
+        goto freePool;
+    }
+    
+    if (mask) {
+        masksize=icon->w*icon->h;
+        surfPtr = (Uint8 *)mergedSurface->pixels;
+        #define ALPHASHIFT 3
+        for (i=0;i<masksize;i+=8)
+            for (j=0;j<8;j++) 
+                surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
+    }
+    
+    imgrep = [ [ NSBitmapImageRep alloc] 
+                    initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
+                        pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
+                        hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
+                        bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
+    
+    img = [ [ NSImage alloc ] initWithSize:imgSize ];
+    
+    [ img addRepresentation: imgrep ];
+    [ NSApp setApplicationIconImage:img ];
+    
+    [ img release ];
+    [ imgrep release ];
+    SDL_FreeSurface(mergedSurface);
 freePool:
-     [pool release];
+    [pool release];
 }
 
 static int  QZ_IconifyWindow (_THIS) { 
 
-    /* Bug! minimize erases the framebuffer */
     if ( ! [ qz_window isMiniaturized ] ) {
         [ qz_window miniaturize:nil ];
         return 1;
     }
     else {
-        SDL_SetError ("qz_window already iconified");
+        SDL_SetError ("window already iconified");
         return 0;
     }
 }
@@ -289,16 +296,94 @@
             break;
     case SDL_GRAB_OFF:
             CGAssociateMouseAndMouseCursorPosition (1);
-            currentGrabMode = SDL_GRAB_OFF;
+            current_grab_mode = SDL_GRAB_OFF;
             break;
     case SDL_GRAB_ON:
             QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
             CGAssociateMouseAndMouseCursorPosition (0);
-            currentGrabMode = SDL_GRAB_ON;
+            current_grab_mode = SDL_GRAB_ON;
             break;
     case SDL_GRAB_FULLSCREEN:        
             break;
     }
         
-    return currentGrabMode;
+    return current_grab_mode;
 }
+
+/* Resize icon, BMP format */
+static unsigned char QZ_ResizeIcon[] = {
+    0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
+    0x00,0x00,0x0d,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
+    0x00,0x00,0xfb,0x01,0x00,0x00,0x13,0x0b,0x00,0x00,0x13,0x0b,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
+    0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,
+    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
+    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xda,0xda,0xda,0x87,
+    0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,
+    0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0xd5,0xd5,0x87,0x87,0x87,0xe8,0xe8,0xe8,
+    0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,
+    0xda,0xda,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,
+    0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,
+    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
+    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,
+    0xe8,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xd9,0xd9,0xd9,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xdc,
+    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,
+    0xdb,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,0xdb,0x87,0x87,0x87,0xe8,
+    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdc,
+    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
+};
+
+static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
+
+    /* Check if we should draw the resize icon */
+    if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
+    
+        Rect	icon;
+        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
+                    SDL_VideoSurface->w, SDL_VideoSurface->h);
+                    
+        if (RectInRgn (&icon, dirtyRegion)) {
+        
+            SDL_Rect icon_rect;
+            
+            /* Create the icon image */
+            if (resize_icon == NULL) {
+            
+                SDL_RWops *rw;
+                SDL_Surface *tmp;
+                
+                rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
+                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
+                                                                
+                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);								
+                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
+                
+                SDL_FreeSurface (tmp);
+            }
+            
+            icon_rect.x = SDL_VideoSurface->w - 13;
+            icon_rect.y = SDL_VideoSurface->h - 13;
+            icon_rect.w = 13;
+            icon_rect.h = 13;
+            
+            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
+        }
+    }
+}
\ No newline at end of file