src/SDL12_compat.c
changeset 105 5eca9fdcac0c
parent 104 f3976d9769ab
child 106 8948c4b1ef8d
     1.1 --- a/src/SDL12_compat.c	Wed Mar 06 16:51:58 2019 -0500
     1.2 +++ b/src/SDL12_compat.c	Wed Mar 06 16:53:01 2019 -0500
     1.3 @@ -729,7 +729,7 @@
     1.4  static SDL_GLContext *VideoGLContext20 = NULL;
     1.5  static char *WindowTitle = NULL;
     1.6  static char *WindowIconTitle = NULL;
     1.7 -static SDL12_Surface *VideoIcon12;
     1.8 +static SDL_Surface *VideoIcon20 = NULL;
     1.9  static int EnabledUnicode = 0;
    1.10  static int VideoDisplayIndex = 0;
    1.11  static int CDRomInit = 0;
    1.12 @@ -1203,6 +1203,9 @@
    1.13  {
    1.14      int i;
    1.15  
    1.16 +    SDL20_FreeSurface(VideoIcon20);
    1.17 +    VideoIcon20 = NULL;
    1.18 +
    1.19      for (i = 0; i < VideoModesCount; i++) {
    1.20          SDL20_free(VideoModes[i].modeslist12);
    1.21          SDL20_free(VideoModes[i].modes12);
    1.22 @@ -2745,6 +2748,9 @@
    1.23          if (!VideoWindow20) {
    1.24              return EndVidModeCreate();
    1.25          }
    1.26 +        if (VideoIcon20) {
    1.27 +            SDL20_SetWindowIcon(VideoWindow20, VideoIcon20);
    1.28 +        }
    1.29      } else {  /* resize it */
    1.30          SDL20_SetWindowSize(VideoWindow20, width, height);
    1.31          SDL20_SetWindowFullscreen(VideoWindow20, fullscreen_flags20);
    1.32 @@ -3227,10 +3233,49 @@
    1.33  }
    1.34  
    1.35  DECLSPEC void SDLCALL
    1.36 -SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
    1.37 +SDL_WM_SetIcon(SDL12_Surface *icon12, Uint8 *mask)
    1.38  {
    1.39 -    FIXME("write me");
    1.40 -    SDL20_Unsupported();
    1.41 +SDL20_SetWindowIcon(VideoWindow20, icon12->surface20);
    1.42 +return;
    1.43 +
    1.44 +    // take the mask and zero out those alpha values.
    1.45 +    SDL_BlendMode blendmode = SDL_BLENDMODE_NONE;
    1.46 +    if (SDL20_GetSurfaceBlendMode(icon12->surface20, &blendmode) < 0) {
    1.47 +        return;  // oh well.
    1.48 +    }
    1.49 +
    1.50 +    Uint32 rmask, gmask, bmask, amask;
    1.51 +    int bpp;
    1.52 +    if (!SDL20_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &bpp, &rmask, &gmask, &bmask, &amask)) {
    1.53 +        return;  // oh well.
    1.54 +    }
    1.55 +
    1.56 +    SDL_Surface *icon20 = SDL20_CreateRGBSurface(0, icon12->w, icon12->h, bpp, rmask, gmask, bmask, amask);
    1.57 +    if (!icon20) {
    1.58 +        return;  // oh well.
    1.59 +    }
    1.60 +
    1.61 +    SDL20_SetSurfaceBlendMode(icon12->surface20, SDL_BLENDMODE_NONE);
    1.62 +    const int rc = SDL20_UpperBlit(icon12->surface20, NULL, icon20, NULL);
    1.63 +    SDL20_SetSurfaceBlendMode(icon12->surface20, blendmode);
    1.64 +    if (rc == 0) {
    1.65 +        SDL_assert(icon20->format->BytesPerPixel == 4);
    1.66 +        SDL_assert(icon20->pitch == icon20->w * 4);
    1.67 +        const int w = icon12->w;
    1.68 +        const int h = icon12->h;
    1.69 +        const int mpitch = (w + 7) / 8;
    1.70 +        Uint32 *ptr = (Uint32 *) icon20->pixels;
    1.71 +        for (int y = 0; y < h; y++) {
    1.72 +            for (int x = 0; x < w; x++, ptr++) {
    1.73 +                if (!(mask[y*mpitch + x/8] & (128 >> (x % 8)))) {
    1.74 +                    *ptr &= ~amask;
    1.75 +                }
    1.76 +            }
    1.77 +        }
    1.78 +        SDL20_SetWindowIcon(VideoWindow20, icon20);
    1.79 +        SDL20_FreeSurface(VideoIcon20);
    1.80 +        VideoIcon20 = icon20;
    1.81 +    }
    1.82  }
    1.83  
    1.84  DECLSPEC int SDLCALL