Skip to content

Commit

Permalink
Added Quartz version of SDL_SetIcon() for MacOS X (thanks Bob)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 18, 2002
1 parent d412560 commit 199bfb3
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/video/quartz/SDL_QuartzWM.m
Expand Up @@ -143,8 +143,48 @@ static void QZ_SetCaption (_THIS, const char *title, const char *icon) {
}
}

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<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];
}

static int QZ_IconifyWindow (_THIS) {
Expand Down

0 comments on commit 199bfb3

Please sign in to comment.