Mercurial > sdl-ios-xcode
comparison src/video/quartz/SDL_QuartzWM.m @ 269:4125b9859c71
Added Quartz version of SDL_SetIcon() for MacOS X (thanks Bob)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 18 Jan 2002 19:41:59 +0000 |
parents | e8157fcb3114 |
children | d1447a846d80 |
comparison
equal
deleted
inserted
replaced
268:217b02923e79 | 269:4125b9859c71 |
---|---|
141 [ string release ]; | 141 [ string release ]; |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) { | 146 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) |
147 /* Convert icon/mask to NSImage, assign with NSWindow's setMiniwindowImage method */ | 147 { |
148 NSBitmapImageRep *imgrep; | |
149 NSImage *img; | |
150 SDL_Surface *mergedSurface; | |
151 Uint8 *surfPtr; | |
152 int i,j,masksize; | |
153 NSAutoreleasePool *pool; | |
154 SDL_Rect rrect; | |
155 NSSize imgSize = {icon->w, icon->h}; | |
156 pool = [ [ NSAutoreleasePool alloc ] init ]; | |
157 SDL_GetClipRect(icon, &rrect); | |
158 /* create a big endian RGBA surface */ | |
159 mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, | |
160 icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0); | |
161 if (mergedSurface==NULL) { NSLog(@"Error creating surface for | |
162 merge"); goto freePool; } | |
163 if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) { | |
164 NSLog(@"Error blitting to mergedSurface"); | |
165 goto freePool; | |
166 } | |
167 if (mask) { | |
168 masksize=icon->w*icon->h; | |
169 surfPtr = (Uint8 *)mergedSurface->pixels; | |
170 #define ALPHASHIFT 3 | |
171 for (i=0;i<masksize;i+=8) | |
172 for (j=0;j<8;j++) | |
173 surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00; | |
174 } | |
175 imgrep = [[NSBitmapImageRep alloc] | |
176 initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels | |
177 pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 | |
178 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace | |
179 bytesPerRow:icon->w<<2 bitsPerPixel:32]; | |
180 img = [[NSImage alloc] initWithSize:imgSize]; | |
181 [img addRepresentation: imgrep]; | |
182 [NSApp setApplicationIconImage:img]; | |
183 [img release]; | |
184 [imgrep release]; | |
185 SDL_FreeSurface(mergedSurface); | |
186 freePool: | |
187 [pool release]; | |
148 } | 188 } |
149 | 189 |
150 static int QZ_IconifyWindow (_THIS) { | 190 static int QZ_IconifyWindow (_THIS) { |
151 | 191 |
152 /* Bug! minimize erases the framebuffer */ | 192 /* Bug! minimize erases the framebuffer */ |