comparison src/video/win32/SDL_win32window.c @ 2970:94b634c56455

Added support for translucent icons on Windows
author Sam Lantinga <slouken@libsdl.org>
date Sat, 03 Jan 2009 01:01:53 +0000
parents efe4d0ce2e97
children a3012c6652ff
comparison
equal deleted inserted replaced
2969:1ee69e7e7cea 2970:94b634c56455
28 #endif 28 #endif
29 29
30 #include "SDL_config.h" 30 #include "SDL_config.h"
31 31
32 #include "../SDL_sysvideo.h" 32 #include "../SDL_sysvideo.h"
33 #include "../SDL_pixels_c.h"
33 #include "../../events/SDL_keyboard_c.h" 34 #include "../../events/SDL_keyboard_c.h"
34 35
35 #include "SDL_win32video.h" 36 #include "SDL_win32video.h"
36 37
37 /* This is included after SDL_win32video.h, which includes windows.h */ 38 /* This is included after SDL_win32video.h, which includes windows.h */
310 SDL_free(title); 311 SDL_free(title);
311 } 312 }
312 } 313 }
313 314
314 void 315 void
316 WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
317 {
318 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
319 HICON hicon = NULL;
320
321 if(icon) {
322 BYTE *icon_bmp;
323 int icon_len;
324 SDL_RWops *dst;
325 SDL_PixelFormat format;
326 SDL_Surface *surface;
327
328 /* Create temporary bitmap buffer */
329 icon_len = 40 + icon->h * icon->w * 4;
330 icon_bmp = SDL_stack_alloc(BYTE, icon_len);
331 dst = SDL_RWFromMem(icon_bmp, icon_len);
332 if (!dst) {
333 SDL_stack_free(icon_bmp);
334 return;
335 }
336
337 /* Write the BITMAPINFO header */
338 SDL_WriteLE32(dst, 40);
339 SDL_WriteLE32(dst, icon->w);
340 SDL_WriteLE32(dst, icon->h*2);
341 SDL_WriteLE16(dst, 1);
342 SDL_WriteLE16(dst, 32);
343 SDL_WriteLE32(dst, BI_RGB);
344 SDL_WriteLE32(dst, icon->h * icon->w * 4);
345 SDL_WriteLE32(dst, 0);
346 SDL_WriteLE32(dst, 0);
347 SDL_WriteLE32(dst, 0);
348 SDL_WriteLE32(dst, 0);
349
350 /* Convert the icon to a 32-bit surface with alpha channel */
351 SDL_InitFormat(&format, 32,
352 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
353 surface = SDL_ConvertSurface(icon, &format, 0);
354 if (surface) {
355 /* Write the pixels upside down into the bitmap buffer */
356 int y = surface->h;
357 while (y--) {
358 Uint8 *src = (Uint8 *)surface->pixels + y * surface->pitch;
359 SDL_RWwrite(dst, src, surface->pitch, 1);
360 }
361 SDL_FreeSurface(surface);
362
363 hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
364 }
365 SDL_RWclose(dst);
366 SDL_stack_free(icon_bmp);
367 }
368
369 /* Set the icon */
370 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hicon);
371 }
372
373 void
315 WIN_SetWindowPosition(_THIS, SDL_Window * window) 374 WIN_SetWindowPosition(_THIS, SDL_Window * window)
316 { 375 {
317 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; 376 HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
318 RECT rect; 377 RECT rect;
319 DWORD style; 378 DWORD style;