Changeset 122

Show
Ignore:
Timestamp:
05/07/07 12:59:02 (1 year ago)
Author:
takkaria
Message:

Update to the latest SDL code, with snap-to-edge behaviour, and requiring SDL_Image. (Iain McFall?)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main-sdl.c

    r114 r122  
    99 * Comments and suggestions are welcome. The UI probably needs some 
    1010 * adjustment, and I need comments from you. 
    11  * 
     11 *perhaps also something like "Angband 3.0.8 by Andrew Sidwell and others; 
     12 SDL port by Iain McFall an others, please see the accompanying documentation 
     13 for credits" or something 
    1214 */ 
    1315 
     
    107109#include "SDL.h" 
    108110#include "SDL_ttf.h" 
     111#include "SDL_image.h" 
    109112 
    110113/* SDL flags used for the main window surface */ 
     
    127130static cptr ANGBAND_DIR_XTRA_FONT; 
    128131static cptr ANGBAND_DIR_XTRA_GRAF; 
     132 
     133/* XXXXXXXXX */ 
     134static cptr ANGBAND_DIR_USER_SDL; 
     135 
    129136/* Later... 
    130137static cptr ANGBAND_DIR_XTRA_SOUND; 
     
    176183         
    177184        SDL_Surface *surface;   /* The surface for this window */ 
    178          
     185#ifdef USE_GRAPHICS 
     186        SDL_Surface *tiles;             /* The appropriately sized tiles for this window */ 
     187#endif   
    179188        byte Term_idx;                  /* Index of term that relates to this */ 
    180189         
     
    333342 (k == SDLK_KP7) || (k == SDLK_KP8) || (k == SDLK_KP9) || (k == SDLK_KP_ENTER)) 
    334343 
     344static int SnapRange = 5;       /* Window snap range (pixels) */ 
    335345static int StatusHeight;        /* The height in pixels of the status bar */ 
    336346static int SelectedTerm;        /* Current selected Term */ 
     
    346356static int MoreOK;                      /* Accept changes */ 
    347357static int MoreFullscreen;      /* Fullscreen toggle button */ 
     358static int MoreSnapPlus;        /* Increase snap range */ 
     359static int MoreSnapMinus;       /* Decrease snap range */ 
    348360 
    349361static bool Moving;                             /* Moving a window */ 
     
    359371        cptr name;                              /* Name to show on button */ 
    360372        cptr gfxfile;                   /* The file with tiles */ 
    361         cptr maskfile;                  /* The mask file (if any) */ 
    362373        int width;                              /* Width of a tile */ 
    363374        int height;                             /* Height of a tile */ 
    364375        cptr pref;                              /* Preference file to use */ 
     376        int x;                                  /* Yuk - Pixel location of colour key */ 
     377        int y;                                  /* ditto */ 
    365378        bool avail;                             /* Are the appropriate files available? */ 
    366379}; 
     
    372385{ 
    373386        /* No gfx (GRAPHICS_NONE) */ 
    374         {"None", NULL, NULL, -1, -1, NULL, TRUE}, 
     387        {"None", NULL, -1, -1, NULL, 0, 0, TRUE}, 
    375388        /* 8x8 tiles (GRAPHICS_ORIGINAL) */ 
    376         {"8x8", "8x8.bmp", NULL, 8, 8, "old", TRUE}, 
     389        {"8x8", "8x8.png", 8, 8, "old", 0, 0, TRUE}, 
    377390        /* 16x16 tiles (GRAPHICS_ADAM_BOLT) */ 
    378         {"16x16", "16x16.bmp", "mask.bmp", 16, 16, "new", TRUE}, 
     391        {"16x16", "16x16.png", 16, 16, "new", 0, 65, TRUE}, 
    379392        /* XXX (GRAPHICS_DAVID_GERVAIS) */ 
    380         {"32x32", "32x32.bmp", "mask32.bmp", 32, 32, "david", TRUE}, 
     393        {"32x32", "32x32.png", 32, 32, "david", 0, 0, TRUE}, 
    381394         
    382395        /* XXX (GRAPHICS_PSEUDO ???) */ 
     
    392405 * The basic angband text colours in an sdl friendly form 
    393406 */ 
    394 static u32b text_colours[16]; 
     407static u32b text_colours[MAX_COLORS]; 
    395408 
    396409u32b back_colour;               /* Background colour */ 
     
    10441057static void term_windowFree(term_window* win) 
    10451058{ 
    1046         if (win->surface) SDL_FreeSurface(win->surface); 
    1047         win->surface = NULL; 
     1059        if (win->surface) 
     1060        { 
     1061                SDL_FreeSurface(win->surface); 
     1062                win->surface = NULL; 
     1063#ifdef USE_GRAPHICS 
     1064                /* Invalidate the gfx surface */ 
     1065                if (win->tiles) 
     1066                { 
     1067                        SDL_FreeSurface(win->tiles); 
     1068                        win->tiles = NULL; 
     1069                } 
     1070#endif 
     1071                term_nuke(&win->term_data); 
     1072        } 
    10481073         
    10491074        sdl_FontFree(&win->font); 
    10501075} 
    10511076 
     1077static errr save_prefs(void); 
    10521078static void hook_quit(cptr str) 
    10531079{ 
    10541080        int i; 
    10551081         
    1056                  
     1082        save_prefs(); 
     1083         
     1084        string_free(ANGBAND_DIR_USER_SDL); 
     1085         
    10571086        /* Free the surfaces of the windows */ 
    10581087        for (i = 0; i < ANGBAND_TERM_MAX; i++) 
     
    13951424        { 
    13961425                window->visible = FALSE; 
    1397                 term_nuke(&window->term_data); 
    13981426                term_windowFree(window); 
    13991427                angband_term[SelectedTerm] = NULL; 
     
    14221450         
    14231451        sdl_CheckFont(window->req_font, &w, &h); 
     1452#ifdef USE_GRAPHICS      
     1453        /* Invalidate the gfx surface */ 
     1454        if (window->tiles) 
     1455        { 
     1456                SDL_FreeSurface(window->tiles); 
     1457                window->tiles = NULL; 
     1458        } 
     1459#endif 
    14241460         
    14251461        ResizeWin(window, (w * window->cols) + (2 * window->border), 
     
    15071543        } 
    15081544         
     1545        /* Invalidate all the gfx surfaces */ 
     1546        if (do_update) 
     1547        { 
     1548                int i; 
     1549                for (i = 0; i < ANGBAND_TERM_MAX; i++) 
     1550                { 
     1551                        term_window *win = &windows[i]; 
     1552                        if (win->tiles) 
     1553                        { 
     1554                                SDL_FreeSurface(win->tiles); 
     1555                                win->tiles = NULL; 
     1556                        } 
     1557                } 
     1558        }        
    15091559         
    15101560#endif 
     
    15561606                sdl_ButtonCaption(sender, "On"); 
    15571607        } 
     1608} 
     1609 
     1610static void SnapChange(sdl_Button *sender) 
     1611{ 
     1612        SnapRange += sender->tag; 
     1613        if (SnapRange < 0) SnapRange = 0; 
     1614        if (SnapRange > 20) SnapRange = 20; 
     1615        PopUp.need_update = TRUE; 
    15581616} 
    15591617 
     
    16131671         
    16141672        sdl_ButtonMove(button, 200, y); 
     1673        y+= 20; 
     1674         
     1675        sdl_WindowText(win, colour, 20, y, format("Snap range is %d.", SnapRange)); 
     1676        button = sdl_ButtonBankGet(&win->buttons, MoreSnapMinus); 
     1677        sdl_ButtonMove(button, 200, y); 
     1678         
     1679        button = sdl_ButtonBankGet(&win->buttons, MoreSnapPlus); 
     1680        sdl_ButtonMove(button, 230, y); 
    16151681} 
    16161682 
     
    16731739        button->activate = FlipTag; 
    16741740         
     1741        MoreSnapPlus = sdl_ButtonBankNew(&PopUp.buttons); 
     1742        button = sdl_ButtonBankGet(&PopUp.buttons, MoreSnapPlus); 
     1743         
     1744        button->unsel_colour = ucolour; 
     1745        button->sel_colour = scolour; 
     1746        sdl_ButtonSize(button, 20, PopUp.font.height + 2); 
     1747        sdl_ButtonCaption(button, "+"); 
     1748        button->tag = 1; 
     1749        sdl_ButtonVisible(button, TRUE); 
     1750        button->activate = SnapChange; 
     1751         
     1752        MoreSnapMinus = sdl_ButtonBankNew(&PopUp.buttons); 
     1753        button = sdl_ButtonBankGet(&PopUp.buttons, MoreSnapMinus); 
     1754         
     1755        button->unsel_colour = ucolour; 
     1756        button->sel_colour = scolour; 
     1757        sdl_ButtonSize(button, 20, PopUp.font.height + 2); 
     1758        sdl_ButtonCaption(button, "-"); 
     1759        button->tag = -1; 
     1760        sdl_ButtonVisible(button, TRUE); 
     1761        button->activate = SnapChange; 
     1762         
    16751763        MoreOK = sdl_ButtonBankNew(&PopUp.buttons); 
    16761764        button = sdl_ButtonBankGet(&PopUp.buttons, MoreOK); 
     
    17981886        StatusBar.need_update = TRUE; 
    17991887         
    1800         /* Hmmmm... */ 
     1888        /* HACK - Redraw all windows */ 
    18011889        if (character_dungeon) do_cmd_redraw(); 
    18021890} 
     
    18461934        path_build(buf, sizeof(buf), ANGBAND_DIR_USER , "sdlinit.txt"); 
    18471935         
     1936        /* XXXXX */ 
     1937        ANGBAND_DIR_USER_SDL = string_make(buf); 
     1938         
    18481939        /* Open the file */ 
    18491940        fff = my_fopen(buf, "r"); 
     
    19292020static errr save_prefs() 
    19302021{ 
    1931         char buf[1024]; 
    19322022        FILE *fff; 
    19332023        int i; 
    19342024         
    1935         /* Build the path */ 
    1936         path_build(buf, sizeof(buf), ANGBAND_DIR_USER , "sdlinit.txt"); 
    1937          
    19382025        /* Open the file */ 
    1939         fff = my_fopen(buf, "w"); 
     2026        fff = my_fopen(ANGBAND_DIR_USER_SDL, "w"); 
    19402027         
    19412028        /* Check it */ 
     
    19792066static int Movingx; 
    19802067static int Movingy; 
     2068 
     2069/* 
     2070 * Is What within Range units of Origin 
     2071 */ 
     2072 
     2073#define closeto(Origin, What, Range) \ 
     2074        ((ABS((Origin) - (What))) < (Range)) 
     2075 
    19812076/* 
    19822077 * This function keeps the 'mouse' info up to date, 
     
    19992094                        if (Moving) 
    20002095                        { 
     2096                                int i; 
     2097                                 
    20012098                                /* Move the window */ 
    20022099                                win->left = (mouse.x - Movingx); 
     
    20312128                                } 
    20322129                                 
     2130                                for (i = 0; i < ANGBAND_TERM_MAX; i++) 
     2131                                { 
     2132                                        term_window *snapper = &windows[i]; 
     2133                                         
     2134                                        /* Can't snap to self... */ 
     2135                                        if (i == SelectedTerm) continue; 
     2136                                         
     2137                                        /* Can't snap to the invisible */ 
     2138                                        if (!snapper->visible) continue; 
     2139                                         
     2140                                        /* Check the windows are across from each other */ 
     2141                                        if ((snapper->top < win->top + win->height) && (win->top < snapper->top + snapper->height)) 
     2142                                        { 
     2143                                                /* Lets try to the left... */ 
     2144                                                if (closeto(win->left, snapper->left + snapper->width, SnapRange)) 
     2145                                                { 
     2146                                                        win->left = snapper->left + snapper->width; 
     2147                                                        Movingx = mouse.x - win->left; 
     2148                                                } 
     2149                                                /* Maybe to the right */ 
     2150                                                if (closeto(win->left + win->width, snapper->left, SnapRange)) 
     2151                                                { 
     2152                                                        win->left = snapper->left - win->width; 
     2153                                                        Movingx = mouse.x - win->left; 
     2154                                                } 
     2155                                        } 
     2156                                         
     2157                                        /* Check the windows are above/below each other */ 
     2158                                        if ((snapper->left < win->left + win->width) && (win->left < snapper->left + snapper->width)) 
     2159                                        { 
     2160                                                /* Lets try to the top... */ 
     2161                                                if (closeto(win->top, snapper->top + snapper->height, SnapRange)) 
     2162                                                { 
     2163                                                        win->top = snapper->top + snapper->height; 
     2164                                                        Movingy = mouse.y - win->top; 
     2165                                                } 
     2166                                                /* Maybe to the bottom */ 
     2167                                                if (closeto(win->top + win->height, snapper->top, SnapRange)) 
     2168                                                { 
     2169                                                        win->top = snapper->top - win->height; 
     2170                                                        Movingy = mouse.y - win->top; 
     2171                                                } 
     2172                                        } 
     2173                                         
     2174                                } 
     2175                                 
    20332176                                /* Show on the screen */ 
    20342177                                sdl_BlitAll(); 
     
    20562199                                sdl_BlitAll(); 
    20572200                        } 
    2058                         else 
     2201                        else if (!popped) 
    20592202                        { 
    20602203                                /* Have a look for the corner stuff */ 
     
    23652508                case SDL_QUIT: 
    23662509                { 
    2367                         /* We are playing a game with an active character, and are not using the infinite lives cheat */ 
    2368                         if ((character_generated) && (inkey_flag)
     2510                        /* We are playing a game with an active character */ 
     2511                        if (character_generated && inkey_flag
    23692512                        { 
    23702513                                /* Hack -- Forget messages */ 
     
    25552698} 
    25562699 
     2700static errr Term_bigcurs_sdl(int col, int row) 
     2701{ 
     2702        term_window *win = (term_window*)(Term->data); 
     2703         
     2704        Uint32 colour = text_colours[TERM_YELLOW]; 
     2705         
     2706        SDL_Rect rc; 
     2707         
     2708        /* Make a rectangle */ 
     2709        RECT(col * win->tile_wid, row * win->tile_hgt, win->tile_wid * 2, win->tile_hgt, &rc); 
     2710         
     2711        /* Translate it */ 
     2712        rc.x += win->border; 
     2713        rc.y += win->title_height; 
     2714         
     2715        /* Draw it */ 
     2716        sdl_DrawBox(win->surface, &rc, colour, 1); 
     2717         
     2718        /* Update area */ 
     2719        set_update_rect(win, &rc); 
     2720         
     2721        /* Success */ 
     2722        return (0); 
     2723} 
     2724 
    25572725static errr Term_curs_sdl(int col, int row) 
    25582726{ 
     
    26262794                        return (Term_xtra_sdl_delay(v)); 
    26272795                } 
     2796                case TERM_XTRA_REACT: 
     2797                { 
     2798                        int i; 
     2799                        /* Re-initialize the colours */ 
     2800                        for (i = 0; i < MAX_COLORS; i++) 
     2801                        { 
     2802                                text_colours[i] = SDL_MapRGB(AppWin->format, angband_color_table[i][1], 
     2803                                                                                         angband_color_table[i][2], 
     2804                                                                                         angband_color_table[i][3]); 
     2805                        } 
     2806                } 
    26282807        } 
    26292808         
     
    26872866 * Do a 'stretched blit' 
    26882867 * SDL has no support for stretching... What a bastard! 
    2689  * XXX - The 'source' surface has alpha properties, so we assume it's 32-bit! 
     2868 *  
    26902869 */ 
    26912870static void sdl_StretchBlit(SDL_Surface *src, SDL_Rect *srcRect, SDL_Surface *dest, SDL_Rect *destRect) 
     
    26942873        int sx, sy, dx, dy; 
    26952874        Uint8 *ps, *pd; 
    2696         Uint32 *ps1; 
    26972875         
    26982876        for (y = 0; y < destRect->h; y++) 
     
    27062884                        /* Find a source pixel */ 
    27072885                        ps = (Uint8 *)src->pixels + (sx * src->format->BytesPerPixel) + (sy * src->pitch); 
    2708                         ps1 = (Uint32*) ps; 
    2709                          
     2886#if 0 
    27102887                        /* Do we need to draw it? */ 
    2711                         if (!(*ps1 & src->format->Amask)) continue; 
    2712                          
     2888                        switch (src->format->BytesPerPixel) 
     2889                        { 
     2890                                case 1: 
     2891                                { 
     2892                                        if (*ps == src->format->colorkey) continue; 
     2893                                        break; 
     2894                                } 
     2895                                case 2: 
     2896                                { 
     2897                                        Uint16 *ps16 = (Uint16*) ps; 
     2898                                        if (*ps16 == src->format->colorkey) continue; 
     2899                                        break; 
     2900                                } 
     2901                                case 3: 
     2902                                case 4: 
     2903                                { 
     2904                                        Uint32 *ps32 = (Uint32*) ps; 
     2905                                        if (*ps32 == src->format->colorkey) continue; 
     2906                                        break; 
     2907                                } 
     2908                        } 
     2909#endif 
     2910                                         
    27132911                        /* Actual destination pixel coords */ 
    27142912                        dx = x + destRect->x; 
     
    27222920                                case 1: 
    27232921                                { 
    2724                                         Uint8 r, g, b; 
    2725                                         SDL_GetRGB(*ps1, src->format, &r, &g, &b); 
    2726                                         *pd = SDL_MapRGB(dest->format, r, g, b); 
     2922                                        *pd = *ps; 
    27272923                                        break; 
    27282924                                } 
    27292925                                case 2: 
    27302926                                { 
    2731                                         Uint8 r, g, b; 
    2732                                         Uint16 *pd1 = (Uint16*)pd; 
    2733                                         SDL_GetRGB(*ps1, src->format, &r, &g, &b); 
    2734                                         *pd1 = SDL_MapRGB(dest->format, r, g, b); 
     2927                                        Uint16 *ps16 = (Uint16*) ps; 
     2928                                        Uint16 *pd16 = (Uint16*) pd; 
     2929                                        *pd16 = *ps16; 
    27352930                                        break; 
    27362931                                } 
     
    27382933                                case 4: 
    27392934                                { 
    2740                                         Uint32 *pd1 = (Uint32*)pd; 
    2741                                         *pd1 = (*ps1 & ~(src->format->Amask)); 
     2935                                        Uint32 *ps32 = (Uint32*) ps; 
     2936                                        Uint32 *pd32 = (Uint32*) pd; 
     2937                                        *pd32 = *ps32; 
    27422938                                } 
    27432939                        } 
     
    27472943         
    27482944} 
     2945 
     2946/* 
     2947 * Make the 'pre-stretched' tiles for this window 
     2948 * Assumes the tiles surface was freed elsewhere 
     2949 */ 
     2950static errr sdl_BuildTileset(term_window *win) 
     2951{ 
     2952        int x, y; 
     2953        int ta, td; 
     2954        int xx, yy; 
     2955        GfxInfo *info = &GfxDesc[use_graphics]; 
     2956         
     2957        /* Calculate the number of tiles across & down*/ 
     2958        ta = GfxSurface->w / info->width; 
     2959        td = GfxSurface->h / info->height; 
     2960         
     2961        /* Calculate the size of the new surface */ 
     2962        x = ta * win->tile_wid; 
     2963        if (use_bigtile) x *= 2; 
     2964        y = td * win->tile_hgt; 
     2965         
     2966        /* Make it */ 
     2967        win->tiles = SDL_CreateRGBSurface(SDL_SWSURFACE, x, y, 
     2968                                                                          GfxSurface->format->BitsPerPixel, 
     2969                                                                          GfxSurface->format->Rmask, GfxSurface->format->Gmask, 
     2970                                                                          GfxSurface->format->Bmask, GfxSurface->format->Amask); 
     2971         
     2972        /* Bugger */ 
     2973        if (!win->tiles) return (1); 
     2974         
     2975        /* For every tile... */ 
     2976        for (xx = 0; xx < ta; xx++) 
     2977        { 
     2978                for (yy = 0; yy < td; yy++) 
     2979                { 
     2980                        SDL_Rect src, dest; 
     2981                        int dwid = (use_bigtile ? win->tile_wid * 2 : win->tile_wid); 
     2982                         
     2983                        /* Source rectangle (on GfxSurface) */ 
     2984                        RECT(xx * info->width, yy * info->height, info->width, info->height, &src); 
     2985                         
     2986                        /* Destination rectangle (win->tiles) */ 
     2987                        RECT(xx * dwid, yy * win->tile_hgt, dwid, win->tile_hgt, &dest); 
     2988                         
     2989                        /* Do the stretch thing */ 
     2990                        sdl_StretchBlit(GfxSurface, &src, win->tiles, &dest); 
     2991                } 
     2992        } 
     2993         
     2994        /* Copy across the colour key */ 
     2995        SDL_SetColorKey(win->tiles, SDL_SRCCOLORKEY, GfxSurface->format->colorkey); 
     2996                                         
     2997        return (0); 
     2998} 
    27492999#endif 
    27503000 
     
    27653015        int i; 
    27663016         
     3017        /* First time a pict is requested we load the tileset in */ 
     3018        if (!win->tiles) 
     3019        { 
     3020                sdl_BuildTileset(win); 
     3021                if (!win->tiles) return (1); 
     3022        } 
     3023         
    27673024        /* Make the destination rectangle */ 
    27683025        RECT(col * win->tile_wid, row * win->tile_hgt, win->tile_wid, win->tile_hgt, &rc); 
     
    27763033         
    27773034        /* Get the dimensions of the graphic surface */ 
    2778         src.w = GfxDesc[use_graphics].width
    2779         src.h = GfxDesc[use_graphics].height
     3035        src.w = rc.w
     3036        src.h = rc.h
    27803037         
    27813038        /* Clear the way */ 
     
    27893046                src.y = (tap[i] & 0x7F) * src.h; 
    27903047                 
    2791                 sdl_StretchBlit(GfxSurface, &src, win->surface, &rc); 
    2792                 //SDL_BlitSurface(GfxSurface, &src, win->surface, &rc); 
     3048                SDL_BlitSurface(win->tiles, &src, win->surface, &rc); 
    27933049                 
    27943050                /* If foreground is the same as background, we're done */ 
     
    27993055                src.y = (ap[i] & 0x7F) * src.h; 
    28003056                 
    2801                 sdl_StretchBlit(GfxSurface, &src, win->surface, &rc); 
    2802                 //SDL_BlitSurface(GfxSurface, &src, win->surface, &rc); 
     3057                SDL_BlitSurface(win->tiles, &src, win->surface, &rc); 
    28033058        } 
    28043059         
     
    28373092        t->xtra_hook = Term_xtra_sdl; 
    28383093        t->curs_hook = Term_curs_sdl; 
     3094        t->bigcurs_hook = Term_bigcurs_sdl; 
    28393095        t->wipe_hook = Term_wipe_sdl; 
    28403096        t->text_hook = Term_text_sdl; 
     
    29403196 
    29413197/* 
    2942  * Hmmm.. This function is somewhat scrappy, but it gets the job done 
    2943  * 
    2944  * Things to note: 
    2945  *  If no maskfile is defined it will default to using the pixel at (0,0) 
    2946  *   as a colour key for blits. This seems to work fine with the 8x8.bmp 
    2947  *   default file. 
    2948  * 
    2949  *  The surface eventually generated by this function uses the built-in 
    2950  *   alpha channel support that SDL provides. 
    2951  *   XXX - This may result in an efficiency loss at screen bit-depths of 
    2952  *         less than 32 bits, since the adding of an alpha channel to a surface 
    2953  *         seems to immediately bump up the bits-per-pixel to 32... 
    2954  * 
    2955  * This function just does things in a simple step-by-step fashion, and seems 
    2956  *  to use far too many intermediatory surfaces. Oh well.. 
     3198 * The new streamlined graphics loader. 
     3199 * Only uses colour keys. 
     3200 * Much more tolerant of different bit-planes 
    29573201 */ 
    29583202static errr load_gfx(void) 
     
    29603204        char buf[1024]; 
    29613205        cptr filename = GfxDesc[use_graphics].gfxfile; 
    2962         SDL_Surface *temp, *temp2; 
     3206        SDL_Surface *temp; 
     3207        Uint8 r, g, b; 
     3208        Uint32 key; 
     3209        Uint32 Pixel; 
     3210        int x = GfxDesc[use_graphics].x, y = GfxDesc[use_graphics].y; 
    29633211         
    29643212        /* This may be called when GRAPHICS_NONE is set */ 
     
    29703218        /* Find and load the file into a temporary surface */ 
    29713219        path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, filename); 
    2972         temp = SDL_LoadBMP(buf); 
     3220        temp = IMG_Load(buf); 
    29733221         
    29743222        /* Oops */ 
     
    29763224         
    29773225        /* Change the surface type to the current video surface format */ 
    2978         temp2 = SDL_DisplayFormat(temp); 
    2979          
    2980         /* There is no maskfile - Use a colour key */ 
    2981         if (!GfxDesc[use_graphics].maskfile) 
    2982         { 
    2983                 Uint8 r, g, b; 
    2984                 Uint32 key; 
    2985                 Uint32 Pixel; 
    2986                  
    2987                 /* Get a pixel value depending on bit-depth */ 
    2988                 switch (temp2->format->BytesPerPixel) 
    2989                 { 
    2990                         case 1: 
    2991                         { 
    2992                                 Uint8 *p = (Uint8*)temp2->pixels; 
    2993                                 Pixel = *p; 
    2994                         } 
    2995                         case 2: 
    2996                         { 
    2997                                 Uint16 *p = (Uint16*)temp2->pixels; 
    2998                                 Pixel = *p; 
    2999                         } 
    3000                         case 3: 
    3001                         case 4: 
    3002                         { 
    3003                                 Uint32 *p = (Uint32*)temp2->pixels; 
    3004                                 Pixel = *p; 
    3005                         } 
    3006                 } 
    3007                  
    3008                 /* Get the colour values */ 
    3009                 SDL_GetRGB(Pixel, temp2->format, &r, &g, &b); 
    3010                  
    3011                 /* Create a key */ 
    3012                 key = SDL_MapRGB(temp2->format, r, g, b); 
    3013                  
    3014                 /* Set the colour key */ 
    3015                 SDL_SetColorKey(temp2, SDL_SRCCOLORKEY, key); 
    3016                  
    3017                 /* SDL will now create an alpha-enabled surface with the appropriate 
    3018                         alpha values for each pixel */ 
    3019                 GfxSurface = SDL_DisplayFormatAlpha(temp2); 
    3020         } 
    3021         else 
    3022         { 
    3023                 SDL_Surface *mask, *cmask; 
    3024                 int i; 
    3025                 int size; 
    3026                  
    3027                 /* Load the mask */ 
    3028                 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, GfxDesc[use_graphics].maskfile); 
    3029                 mask = SDL_LoadBMP(buf); 
    3030                  
    3031                 /* Convert to current display format */ 
    3032                 cmask = SDL_DisplayFormat(mask); 
    3033                  
    3034                 /* Create an alpha enabled surface */ 
    3035                 GfxSurface = SDL_DisplayFormatAlpha(temp2); 
    3036                  
    3037                 /* How many pixels? */ 
    3038                 size = cmask->w * cmask->h; 
    3039                  
    3040                 /* Check _every pixel */ 
    3041                 for (i = 0; i < size; i++) 
    3042                 { 
    3043                         /* Get the pixel (mask) */ 
    3044                         Uint8 *mp = (Uint8*)cmask->pixels + i * cmask->format->BytesPerPixel; 
    3045                          
    3046                         /* Get the pixel (graphic) */ 
    3047                         Uint8 *tp = (Uint8*)GfxSurface->pixels + i * GfxSurface->format->BytesPerPixel;  
    3048                          
    3049                         /* XXX - Surfaces with alpha properties seem to all be 32-bit */ 
    3050                         switch (GfxSurface->format->BytesPerPixel) 
    3051                         { 
    3052                                 case 1: 
    3053                                 { 
    3054                                         break; 
    3055                                 } 
    3056                                 case 2: 
    3057                                 { 
    3058                                          
    3059                                         break; 
    3060                                 } 
    3061                                 case 3: 
    3062                                 { 
    3063                                         break; 
    3064                                 } 
    3065                                 case 4: 
    3066                                 { 
    3067                                         Uint32 *mp1 = (Uint32*)mp; 
    3068                                         Uint32 *tp1 = (Uint32*)tp; 
    3069                                          
    3070                                         /* Is this mask pixel black? */ 
    3071                                         if (!*mp1) 
    3072                                         { 
    3073                                                 /* Set the alpha value to maximum */ 
    3074                                                 *tp1 |= GfxSurface->format->Amask; 
    3075                                         } 
    3076                                         else 
    3077                                         { 
    3078                                                 /* Set the alpha value to zero */ 
    3079                                                 *tp1 &= ~(GfxSurface->format->Amask); 
    3080                                         } 
    3081                                         break; 
    3082                                 } 
    3083                                                  
    3084                         } 
    3085                 } 
    3086                  
    3087                 /* Lose the mask surfaces */ 
    3088                 SDL_FreeSurface(mask); 
    3089                 SDL_FreeSurface(cmask); 
    3090         } 
    3091                  
    3092          
    3093         /* Lose the temporary surfaces */ 
    3094         SDL_FreeSurface(temp2); 
     3226        GfxSurface = SDL_DisplayFormat(temp); 
     3227         
     3228        /* Use a colour key */ 
     3229        /* Get a pixel value depending on bit-depth */ 
     3230        switch (GfxSurface->format->BytesPerPixel) 
     3231        { 
     3232                case 1: 
     3233                { 
     3234                        Uint8 *p = (Uint8*)GfxSurface->pixels + x + (y * GfxSurface->pitch); 
     3235                        Pixel = *p; 
     3236                } 
     3237                case 2: 
     3238                { 
     3239                        Uint16 *p = (Uint16*)GfxSurface->pixels + (x * 2) + (y * GfxSurface->pitch); 
     3240                        Pixel = *p; 
     3241                } 
     3242                case 3: 
     3243                case 4: 
     3244                { 
     3245                        Uint32 *p = (Uint32*)GfxSurface->pixels + (x * GfxSurface->format->BytesPerPixel) + (y * GfxSurface->pitch); 
     3246                        Pixel = *p; 
     3247                } 
     3248        } 
     3249         
     3250        /* Get the colour values */ 
     3251        SDL_GetRGB(Pixel, GfxSurface->format, &r, &g, &b); 
     3252         
     3253        /* Create a key */ 
     3254        key = SDL_MapRGB(GfxSurface->format, r, g, b); 
     3255         
     3256        /* Set the colour key */ 
     3257        SDL_SetColorKey(GfxSurface, SDL_SRCCOLORKEY, key); 
     3258         
     3259        /* Lose the temporary surface */ 
    30953260        SDL_FreeSurface(temp); 
    30963261         
     
    31223287        use_bigtile = FALSE; 
    31233288#else 
    3124         const GfxInfo *info = &GfxDesc[use_graphics]; 
     3289        GfxInfo *info = &GfxDesc[use_graphics]; 
    31253290        int i; 
    31263291         
     
    31443309                        } 
    31453310                } 
    3146                  
    3147                 /* Check the mask file */ 
    3148                 if (GfxDesc[i].maskfile) 
    3149                 { 
    3150                         path_build(path, sizeof(path), ANGBAND_DIR_XTRA_GRAF, GfxDesc[i].maskfile); 
    3151                         fd = fd_open(path, O_WRONLY); 
    3152                          
    3153                         if (fd >= 0) fd_close(fd); 
    3154                         else 
    3155                         { 
    3156                                 plog_fmt("Can't find file %s - graphics mode '%s' will be disabled.", path, GfxDesc[i].name); 
    3157                                 GfxDesc[i].avail = FALSE; 
    3158                         } 
    3159                 } 
    31603311        } 
    31613312         
     
    31903341                        /* Don't crowd out the status bar... */ 
    31913342                        if (win->top < StatusHeight) win->top = StatusHeight; 
    3192                          
     3343#ifdef USE_GRAPHICS                      
     3344                        /* Invalidate the gfx surface */ 
     3345                        if (win->tiles) 
     3346                        { 
     3347                                SDL_FreeSurface(win->tiles); 
     3348                                win->tiles = NULL; 
     3349                        } 
     3350#endif 
    31933351                        /* This will set up the window correctly */ 
    31943352                        ResizeWin(win, win->width, win->height); 
     
    32673425         
    32683426        /* Initialize the colours */ 
    3269         for (i = 0; i < 16; i++) 
     3427        for (i = 0; i < MAX_COLORS; i++) 
    32703428        { 
    32713429                text_colours[i] = SDL_MapRGB(AppWin->format, angband_color_table[i][1],