Added Quartz version of SDL_SetIcon() for MacOS X (thanks Bob)
authorSam Lantinga <slouken@libsdl.org>
Fri, 18 Jan 2002 19:41:59 +0000
changeset 2694125b9859c71
parent 268 217b02923e79
child 270 37fa1484f71b
Added Quartz version of SDL_SetIcon() for MacOS X (thanks Bob)
src/video/quartz/SDL_QuartzWM.m
     1.1 --- a/src/video/quartz/SDL_QuartzWM.m	Fri Jan 18 18:34:51 2002 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Fri Jan 18 19:41:59 2002 +0000
     1.3 @@ -143,8 +143,48 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask) {
     1.8 -/* Convert icon/mask to NSImage, assign with NSWindow's setMiniwindowImage method */
     1.9 +static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
    1.10 +{
    1.11 +     NSBitmapImageRep *imgrep;
    1.12 +     NSImage *img;
    1.13 +     SDL_Surface *mergedSurface;
    1.14 +     Uint8 *surfPtr;
    1.15 +     int i,j,masksize;
    1.16 +     NSAutoreleasePool *pool;
    1.17 +     SDL_Rect rrect;
    1.18 +     NSSize imgSize = {icon->w, icon->h};
    1.19 +     pool = [ [ NSAutoreleasePool alloc ] init ];
    1.20 +     SDL_GetClipRect(icon, &rrect);
    1.21 +     /* create a big endian RGBA surface */
    1.22 +     mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
    1.23 +icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
    1.24 +     if (mergedSurface==NULL) { NSLog(@"Error creating surface for 
    1.25 +merge"); goto freePool; }
    1.26 +     if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
    1.27 +         NSLog(@"Error blitting to mergedSurface");
    1.28 +         goto freePool;
    1.29 +     }
    1.30 +     if (mask) {
    1.31 +     masksize=icon->w*icon->h;
    1.32 +     surfPtr = (Uint8 *)mergedSurface->pixels;
    1.33 +     #define ALPHASHIFT 3
    1.34 +     for (i=0;i<masksize;i+=8)
    1.35 +         for (j=0;j<8;j++) 
    1.36 +surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
    1.37 +     }
    1.38 +     imgrep = [[NSBitmapImageRep alloc] 
    1.39 +initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
    1.40 +pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
    1.41 +hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
    1.42 +bytesPerRow:icon->w<<2 bitsPerPixel:32];
    1.43 +     img = [[NSImage alloc] initWithSize:imgSize];
    1.44 +     [img addRepresentation: imgrep];
    1.45 +     [NSApp setApplicationIconImage:img];
    1.46 +     [img release];
    1.47 +     [imgrep release];
    1.48 +     SDL_FreeSurface(mergedSurface);
    1.49 +freePool:
    1.50 +     [pool release];
    1.51  }
    1.52  
    1.53  static int  QZ_IconifyWindow (_THIS) {