Added support for testing window manager icons
authorSam Lantinga
Wed, 14 Jul 2010 21:25:15 -0700
changeset 45273ce59cbecaa3
parent 4526 c04dd942610d
child 4528 f06faa886423
Added support for testing window manager icons
test/common.c
test/common.h
     1.1 --- a/test/common.c	Wed Jul 14 07:48:35 2010 -0700
     1.2 +++ b/test/common.c	Wed Jul 14 21:25:15 2010 -0700
     1.3 @@ -6,7 +6,7 @@
     1.4  #include "common.h"
     1.5  
     1.6  #define VIDEO_USAGE \
     1.7 -"[--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]"
     1.8 +"[--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]"
     1.9  
    1.10  #define AUDIO_USAGE \
    1.11  "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
    1.12 @@ -192,6 +192,14 @@
    1.13          state->window_title = argv[index];
    1.14          return 2;
    1.15      }
    1.16 +    if (SDL_strcasecmp(argv[index], "--icon") == 0) {
    1.17 +        ++index;
    1.18 +        if (!argv[index]) {
    1.19 +            return -1;
    1.20 +        }
    1.21 +        state->window_icon = argv[index];
    1.22 +        return 2;
    1.23 +    }
    1.24      if (SDL_strcasecmp(argv[index], "--center") == 0) {
    1.25          state->window_x = SDL_WINDOWPOS_CENTERED;
    1.26          state->window_y = SDL_WINDOWPOS_CENTERED;
    1.27 @@ -611,6 +619,30 @@
    1.28      }
    1.29  }
    1.30  
    1.31 +static SDL_Surface *
    1.32 +LoadIcon(const char *file)
    1.33 +{
    1.34 +    SDL_Surface *icon;
    1.35 +
    1.36 +    /* Load the icon surface */
    1.37 +    icon = SDL_LoadBMP(file);
    1.38 +    if (icon == NULL) {
    1.39 +        fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
    1.40 +        return (NULL);
    1.41 +    }
    1.42 +
    1.43 +    if (icon->format->palette == NULL) {
    1.44 +        fprintf(stderr, "Icon must have a palette!\n");
    1.45 +        SDL_FreeSurface(icon);
    1.46 +        return (NULL);
    1.47 +    }
    1.48 +
    1.49 +    /* Set the colorkey */
    1.50 +    SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels));
    1.51 +
    1.52 +    return (icon);
    1.53 +}
    1.54 +
    1.55  SDL_bool
    1.56  CommonInit(CommonState * state)
    1.57  {
    1.58 @@ -791,6 +823,15 @@
    1.59                          SDL_GetError());
    1.60                  return SDL_FALSE;
    1.61              }
    1.62 +
    1.63 +            if (state->window_icon) {
    1.64 +                SDL_Surface *icon = LoadIcon(state->window_icon);
    1.65 +                if (icon) {
    1.66 +                    SDL_SetWindowIcon(state->windows[i], icon);
    1.67 +                    SDL_FreeSurface(icon);
    1.68 +                }
    1.69 +            }
    1.70 +
    1.71              SDL_ShowWindow(state->windows[i]);
    1.72  
    1.73              if (!state->skip_renderer
     2.1 --- a/test/common.h	Wed Jul 14 07:48:35 2010 -0700
     2.2 +++ b/test/common.h	Wed Jul 14 21:25:15 2010 -0700
     2.3 @@ -24,6 +24,7 @@
     2.4      const char *videodriver;
     2.5      int display;
     2.6      const char *window_title;
     2.7 +    const char *window_icon;
     2.8      Uint32 window_flags;
     2.9      int window_x;
    2.10      int window_y;