Changeset 122
- Timestamp:
- 05/07/07 12:59:02 (1 year ago)
- Files:
-
- trunk/lib/xtra/graf/16x16.png (modified) (previous)
- trunk/lib/xtra/graf/32x32.png (modified) (previous)
- trunk/src/main-sdl.c (modified) (45 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main-sdl.c
r114 r122 9 9 * Comments and suggestions are welcome. The UI probably needs some 10 10 * 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 12 14 */ 13 15 … … 107 109 #include "SDL.h" 108 110 #include "SDL_ttf.h" 111 #include "SDL_image.h" 109 112 110 113 /* SDL flags used for the main window surface */ … … 127 130 static cptr ANGBAND_DIR_XTRA_FONT; 128 131 static cptr ANGBAND_DIR_XTRA_GRAF; 132 133 /* XXXXXXXXX */ 134 static cptr ANGBAND_DIR_USER_SDL; 135 129 136 /* Later... 130 137 static cptr ANGBAND_DIR_XTRA_SOUND; … … 176 183 177 184 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 179 188 byte Term_idx; /* Index of term that relates to this */ 180 189 … … 333 342 (k == SDLK_KP7) || (k == SDLK_KP8) || (k == SDLK_KP9) || (k == SDLK_KP_ENTER)) 334 343 344 static int SnapRange = 5; /* Window snap range (pixels) */ 335 345 static int StatusHeight; /* The height in pixels of the status bar */ 336 346 static int SelectedTerm; /* Current selected Term */ … … 346 356 static int MoreOK; /* Accept changes */ 347 357 static int MoreFullscreen; /* Fullscreen toggle button */ 358 static int MoreSnapPlus; /* Increase snap range */ 359 static int MoreSnapMinus; /* Decrease snap range */ 348 360 349 361 static bool Moving; /* Moving a window */ … … 359 371 cptr name; /* Name to show on button */ 360 372 cptr gfxfile; /* The file with tiles */ 361 cptr maskfile; /* The mask file (if any) */362 373 int width; /* Width of a tile */ 363 374 int height; /* Height of a tile */ 364 375 cptr pref; /* Preference file to use */ 376 int x; /* Yuk - Pixel location of colour key */ 377 int y; /* ditto */ 365 378 bool avail; /* Are the appropriate files available? */ 366 379 }; … … 372 385 { 373 386 /* No gfx (GRAPHICS_NONE) */ 374 {"None", NULL, NULL, -1, -1, NULL, TRUE},387 {"None", NULL, -1, -1, NULL, 0, 0, TRUE}, 375 388 /* 8x8 tiles (GRAPHICS_ORIGINAL) */ 376 {"8x8", "8x8. bmp", NULL, 8, 8, "old", TRUE},389 {"8x8", "8x8.png", 8, 8, "old", 0, 0, TRUE}, 377 390 /* 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}, 379 392 /* XXX (GRAPHICS_DAVID_GERVAIS) */ 380 {"32x32", "32x32. bmp", "mask32.bmp", 32, 32, "david", TRUE},393 {"32x32", "32x32.png", 32, 32, "david", 0, 0, TRUE}, 381 394 382 395 /* XXX (GRAPHICS_PSEUDO ???) */ … … 392 405 * The basic angband text colours in an sdl friendly form 393 406 */ 394 static u32b text_colours[ 16];407 static u32b text_colours[MAX_COLORS]; 395 408 396 409 u32b back_colour; /* Background colour */ … … 1044 1057 static void term_windowFree(term_window* win) 1045 1058 { 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 } 1048 1073 1049 1074 sdl_FontFree(&win->font); 1050 1075 } 1051 1076 1077 static errr save_prefs(void); 1052 1078 static void hook_quit(cptr str) 1053 1079 { 1054 1080 int i; 1055 1081 1056 1082 save_prefs(); 1083 1084 string_free(ANGBAND_DIR_USER_SDL); 1085 1057 1086 /* Free the surfaces of the windows */ 1058 1087 for (i = 0; i < ANGBAND_TERM_MAX; i++) … … 1395 1424 { 1396 1425 window->visible = FALSE; 1397 term_nuke(&window->term_data);1398 1426 term_windowFree(window); 1399 1427 angband_term[SelectedTerm] = NULL; … … 1422 1450 1423 1451 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 1424 1460 1425 1461 ResizeWin(window, (w * window->cols) + (2 * window->border), … … 1507 1543 } 1508 1544 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 } 1509 1559 1510 1560 #endif … … 1556 1606 sdl_ButtonCaption(sender, "On"); 1557 1607 } 1608 } 1609 1610 static 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; 1558 1616 } 1559 1617 … … 1613 1671 1614 1672 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); 1615 1681 } 1616 1682 … … 1673 1739 button->activate = FlipTag; 1674 1740 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 1675 1763 MoreOK = sdl_ButtonBankNew(&PopUp.buttons); 1676 1764 button = sdl_ButtonBankGet(&PopUp.buttons, MoreOK); … … 1798 1886 StatusBar.need_update = TRUE; 1799 1887 1800 /* H mmmm...*/1888 /* HACK - Redraw all windows */ 1801 1889 if (character_dungeon) do_cmd_redraw(); 1802 1890 } … … 1846 1934 path_build(buf, sizeof(buf), ANGBAND_DIR_USER , "sdlinit.txt"); 1847 1935 1936 /* XXXXX */ 1937 ANGBAND_DIR_USER_SDL = string_make(buf); 1938 1848 1939 /* Open the file */ 1849 1940 fff = my_fopen(buf, "r"); … … 1929 2020 static errr save_prefs() 1930 2021 { 1931 char buf[1024];1932 2022 FILE *fff; 1933 2023 int i; 1934 2024 1935 /* Build the path */1936 path_build(buf, sizeof(buf), ANGBAND_DIR_USER , "sdlinit.txt");1937 1938 2025 /* Open the file */ 1939 fff = my_fopen( buf, "w");2026 fff = my_fopen(ANGBAND_DIR_USER_SDL, "w"); 1940 2027 1941 2028 /* Check it */ … … 1979 2066 static int Movingx; 1980 2067 static 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 1981 2076 /* 1982 2077 * This function keeps the 'mouse' info up to date, … … 1999 2094 if (Moving) 2000 2095 { 2096 int i; 2097 2001 2098 /* Move the window */ 2002 2099 win->left = (mouse.x - Movingx); … … 2031 2128 } 2032 2129 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 2033 2176 /* Show on the screen */ 2034 2177 sdl_BlitAll(); … … 2056 2199 sdl_BlitAll(); 2057 2200 } 2058 else 2201 else if (!popped) 2059 2202 { 2060 2203 /* Have a look for the corner stuff */ … … 2365 2508 case SDL_QUIT: 2366 2509 { 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) 2369 2512 { 2370 2513 /* Hack -- Forget messages */ … … 2555 2698 } 2556 2699 2700 static 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 2557 2725 static errr Term_curs_sdl(int col, int row) 2558 2726 { … … 2626 2794 return (Term_xtra_sdl_delay(v)); 2627 2795 } 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 } 2628 2807 } 2629 2808 … … 2687 2866 * Do a 'stretched blit' 2688 2867 * 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 * 2690 2869 */ 2691 2870 static void sdl_StretchBlit(SDL_Surface *src, SDL_Rect *srcRect, SDL_Surface *dest, SDL_Rect *destRect) … … 2694 2873 int sx, sy, dx, dy; 2695 2874 Uint8 *ps, *pd; 2696 Uint32 *ps1;2697 2875 2698 2876 for (y = 0; y < destRect->h; y++) … … 2706 2884 /* Find a source pixel */ 2707 2885 ps = (Uint8 *)src->pixels + (sx * src->format->BytesPerPixel) + (sy * src->pitch); 2708 ps1 = (Uint32*) ps; 2709 2886 #if 0 2710 2887 /* 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 2713 2911 /* Actual destination pixel coords */ 2714 2912 dx = x + destRect->x; … … 2722 2920 case 1: 2723 2921 { 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; 2727 2923 break; 2728 2924 } 2729 2925 case 2: 2730 2926 { 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; 2735 2930 break; 2736 2931 } … … 2738 2933 case 4: 2739 2934 { 2740 Uint32 *pd1 = (Uint32*)pd; 2741 *pd1 = (*ps1 & ~(src->format->Amask)); 2935 Uint32 *ps32 = (Uint32*) ps; 2936 Uint32 *pd32 = (Uint32*) pd; 2937 *pd32 = *ps32; 2742 2938 } 2743 2939 } … … 2747 2943 2748 2944 } 2945 2946 /* 2947 * Make the 'pre-stretched' tiles for this window 2948 * Assumes the tiles surface was freed elsewhere 2949 */ 2950 static 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 } 2749 2999 #endif 2750 3000 … … 2765 3015 int i; 2766 3016 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 2767 3024 /* Make the destination rectangle */ 2768 3025 RECT(col * win->tile_wid, row * win->tile_hgt, win->tile_wid, win->tile_hgt, &rc); … … 2776 3033 2777 3034 /* 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; 2780 3037 2781 3038 /* Clear the way */ … … 2789 3046 src.y = (tap[i] & 0x7F) * src.h; 2790 3047 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); 2793 3049 2794 3050 /* If foreground is the same as background, we're done */ … … 2799 3055 src.y = (ap[i] & 0x7F) * src.h; 2800 3056 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); 2803 3058 } 2804 3059 … … 2837 3092 t->xtra_hook = Term_xtra_sdl; 2838 3093 t->curs_hook = Term_curs_sdl; 3094 t->bigcurs_hook = Term_bigcurs_sdl; 2839 3095 t->wipe_hook = Term_wipe_sdl; 2840 3096 t->text_hook = Term_text_sdl; … … 2940 3196 2941 3197 /* 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 2957 3201 */ 2958 3202 static errr load_gfx(void) … … 2960 3204 char buf[1024]; 2961 3205 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; 2963 3211 2964 3212 /* This may be called when GRAPHICS_NONE is set */ … … 2970 3218 /* Find and load the file into a temporary surface */ 2971 3219 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, filename); 2972 temp = SDL_LoadBMP(buf);3220 temp = IMG_Load(buf); 2973 3221 2974 3222 /* Oops */ … … 2976 3224 2977 3225 /* 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 */ 3095 3260 SDL_FreeSurface(temp); 3096 3261 … … 3122 3287 use_bigtile = FALSE; 3123 3288 #else 3124 constGfxInfo *info = &GfxDesc[use_graphics];3289 GfxInfo *info = &GfxDesc[use_graphics]; 3125 3290 int i; 3126 3291 … … 3144 3309 } 3145 3310 } 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 else3155 {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 }3160 3311 } 3161 3312 … … 3190 3341 /* Don't crowd out the status bar... */ 3191 3342 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 3193 3351 /* This will set up the window correctly */ 3194 3352 ResizeWin(win, win->width, win->height); … … 3267 3425 3268 3426 /* Initialize the colours */ 3269 for (i = 0; i < 16; i++)3427 for (i = 0; i < MAX_COLORS; i++) 3270 3428 { 3271 3429 text_colours[i] = SDL_MapRGB(AppWin->format, angband_color_table[i][1],
