# HG changeset patch # User Sam Lantinga # Date 1011382919 0 # Node ID 4125b9859c7193e73c4c4617f568aadf9b91eddc # Parent 217b02923e79fa638633113f17981c89b4a5a767 Added Quartz version of SDL_SetIcon() for MacOS X (thanks Bob) diff -r 217b02923e79 -r 4125b9859c71 src/video/quartz/SDL_QuartzWM.m --- a/src/video/quartz/SDL_QuartzWM.m Fri Jan 18 18:34:51 2002 +0000 +++ b/src/video/quartz/SDL_QuartzWM.m Fri Jan 18 19:41:59 2002 +0000 @@ -143,8 +143,48 @@ } } -static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) { -/* Convert icon/mask to NSImage, assign with NSWindow's setMiniwindowImage method */ +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) { 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>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]; } static int QZ_IconifyWindow (_THIS) {