src/SDL12_compat.c
changeset 105 5eca9fdcac0c
parent 104 f3976d9769ab
child 106 8948c4b1ef8d
equal deleted inserted replaced
104:f3976d9769ab 105:5eca9fdcac0c
   727 static Uint32 VideoSurfaceLastPresentTicks = 0;
   727 static Uint32 VideoSurfaceLastPresentTicks = 0;
   728 static SDL_Surface *VideoConvertSurface20 = NULL;
   728 static SDL_Surface *VideoConvertSurface20 = NULL;
   729 static SDL_GLContext *VideoGLContext20 = NULL;
   729 static SDL_GLContext *VideoGLContext20 = NULL;
   730 static char *WindowTitle = NULL;
   730 static char *WindowTitle = NULL;
   731 static char *WindowIconTitle = NULL;
   731 static char *WindowIconTitle = NULL;
   732 static SDL12_Surface *VideoIcon12;
   732 static SDL_Surface *VideoIcon20 = NULL;
   733 static int EnabledUnicode = 0;
   733 static int EnabledUnicode = 0;
   734 static int VideoDisplayIndex = 0;
   734 static int VideoDisplayIndex = 0;
   735 static int CDRomInit = 0;
   735 static int CDRomInit = 0;
   736 static SDL12_EventFilter EventFilter12 = NULL;
   736 static SDL12_EventFilter EventFilter12 = NULL;
   737 static SDL12_Cursor *CurrentCursor12 = NULL;
   737 static SDL12_Cursor *CurrentCursor12 = NULL;
  1200 
  1200 
  1201 static void
  1201 static void
  1202 Quit12Video(void)
  1202 Quit12Video(void)
  1203 {
  1203 {
  1204     int i;
  1204     int i;
       
  1205 
       
  1206     SDL20_FreeSurface(VideoIcon20);
       
  1207     VideoIcon20 = NULL;
  1205 
  1208 
  1206     for (i = 0; i < VideoModesCount; i++) {
  1209     for (i = 0; i < VideoModesCount; i++) {
  1207         SDL20_free(VideoModes[i].modeslist12);
  1210         SDL20_free(VideoModes[i].modeslist12);
  1208         SDL20_free(VideoModes[i].modes12);
  1211         SDL20_free(VideoModes[i].modes12);
  1209     }
  1212     }
  2743 
  2746 
  2744         VideoWindow20 = SDL20_CreateWindow(WindowTitle, x, y, width, height, flags20);
  2747         VideoWindow20 = SDL20_CreateWindow(WindowTitle, x, y, width, height, flags20);
  2745         if (!VideoWindow20) {
  2748         if (!VideoWindow20) {
  2746             return EndVidModeCreate();
  2749             return EndVidModeCreate();
  2747         }
  2750         }
       
  2751         if (VideoIcon20) {
       
  2752             SDL20_SetWindowIcon(VideoWindow20, VideoIcon20);
       
  2753         }
  2748     } else {  /* resize it */
  2754     } else {  /* resize it */
  2749         SDL20_SetWindowSize(VideoWindow20, width, height);
  2755         SDL20_SetWindowSize(VideoWindow20, width, height);
  2750         SDL20_SetWindowFullscreen(VideoWindow20, fullscreen_flags20);
  2756         SDL20_SetWindowFullscreen(VideoWindow20, fullscreen_flags20);
  2751         SDL20_SetWindowBordered(VideoWindow20, (flags12 & SDL12_NOFRAME) ? SDL_FALSE : SDL_TRUE);
  2757         SDL20_SetWindowBordered(VideoWindow20, (flags12 & SDL12_NOFRAME) ? SDL_FALSE : SDL_TRUE);
  2752         SDL20_SetWindowResizable(VideoWindow20, (flags12 & SDL12_RESIZABLE) ? SDL_TRUE : SDL_FALSE);
  2758         SDL20_SetWindowResizable(VideoWindow20, (flags12 & SDL12_RESIZABLE) ? SDL_TRUE : SDL_FALSE);
  3225         *icon = WindowIconTitle;
  3231         *icon = WindowIconTitle;
  3226     }
  3232     }
  3227 }
  3233 }
  3228 
  3234 
  3229 DECLSPEC void SDLCALL
  3235 DECLSPEC void SDLCALL
  3230 SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
  3236 SDL_WM_SetIcon(SDL12_Surface *icon12, Uint8 *mask)
  3231 {
  3237 {
  3232     FIXME("write me");
  3238 SDL20_SetWindowIcon(VideoWindow20, icon12->surface20);
  3233     SDL20_Unsupported();
  3239 return;
       
  3240 
       
  3241     // take the mask and zero out those alpha values.
       
  3242     SDL_BlendMode blendmode = SDL_BLENDMODE_NONE;
       
  3243     if (SDL20_GetSurfaceBlendMode(icon12->surface20, &blendmode) < 0) {
       
  3244         return;  // oh well.
       
  3245     }
       
  3246 
       
  3247     Uint32 rmask, gmask, bmask, amask;
       
  3248     int bpp;
       
  3249     if (!SDL20_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &bpp, &rmask, &gmask, &bmask, &amask)) {
       
  3250         return;  // oh well.
       
  3251     }
       
  3252 
       
  3253     SDL_Surface *icon20 = SDL20_CreateRGBSurface(0, icon12->w, icon12->h, bpp, rmask, gmask, bmask, amask);
       
  3254     if (!icon20) {
       
  3255         return;  // oh well.
       
  3256     }
       
  3257 
       
  3258     SDL20_SetSurfaceBlendMode(icon12->surface20, SDL_BLENDMODE_NONE);
       
  3259     const int rc = SDL20_UpperBlit(icon12->surface20, NULL, icon20, NULL);
       
  3260     SDL20_SetSurfaceBlendMode(icon12->surface20, blendmode);
       
  3261     if (rc == 0) {
       
  3262         SDL_assert(icon20->format->BytesPerPixel == 4);
       
  3263         SDL_assert(icon20->pitch == icon20->w * 4);
       
  3264         const int w = icon12->w;
       
  3265         const int h = icon12->h;
       
  3266         const int mpitch = (w + 7) / 8;
       
  3267         Uint32 *ptr = (Uint32 *) icon20->pixels;
       
  3268         for (int y = 0; y < h; y++) {
       
  3269             for (int x = 0; x < w; x++, ptr++) {
       
  3270                 if (!(mask[y*mpitch + x/8] & (128 >> (x % 8)))) {
       
  3271                     *ptr &= ~amask;
       
  3272                 }
       
  3273             }
       
  3274         }
       
  3275         SDL20_SetWindowIcon(VideoWindow20, icon20);
       
  3276         SDL20_FreeSurface(VideoIcon20);
       
  3277         VideoIcon20 = icon20;
       
  3278     }
  3234 }
  3279 }
  3235 
  3280 
  3236 DECLSPEC int SDLCALL
  3281 DECLSPEC int SDLCALL
  3237 SDL_WM_IconifyWindow(void)
  3282 SDL_WM_IconifyWindow(void)
  3238 {
  3283 {