Mercurial > sdl-ios-xcode
changeset 4527:3ce59cbecaa3
Added support for testing window manager icons
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 14 Jul 2010 21:25:15 -0700 |
parents | c04dd942610d |
children | f06faa886423 |
files | test/common.c test/common.h |
diffstat | 2 files changed, 43 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/test/common.c Wed Jul 14 07:48:35 2010 -0700 +++ b/test/common.c Wed Jul 14 21:25:15 2010 -0700 @@ -6,7 +6,7 @@ #include "common.h" #define VIDEO_USAGE \ -"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display N] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display N] [--fullscreen | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" #define AUDIO_USAGE \ "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" @@ -192,6 +192,14 @@ state->window_title = argv[index]; return 2; } + if (SDL_strcasecmp(argv[index], "--icon") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->window_icon = argv[index]; + return 2; + } if (SDL_strcasecmp(argv[index], "--center") == 0) { state->window_x = SDL_WINDOWPOS_CENTERED; state->window_y = SDL_WINDOWPOS_CENTERED; @@ -611,6 +619,30 @@ } } +static SDL_Surface * +LoadIcon(const char *file) +{ + SDL_Surface *icon; + + /* Load the icon surface */ + icon = SDL_LoadBMP(file); + if (icon == NULL) { + fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); + return (NULL); + } + + if (icon->format->palette == NULL) { + fprintf(stderr, "Icon must have a palette!\n"); + SDL_FreeSurface(icon); + return (NULL); + } + + /* Set the colorkey */ + SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels)); + + return (icon); +} + SDL_bool CommonInit(CommonState * state) { @@ -791,6 +823,15 @@ SDL_GetError()); return SDL_FALSE; } + + if (state->window_icon) { + SDL_Surface *icon = LoadIcon(state->window_icon); + if (icon) { + SDL_SetWindowIcon(state->windows[i], icon); + SDL_FreeSurface(icon); + } + } + SDL_ShowWindow(state->windows[i]); if (!state->skip_renderer