* Recreates the surface with a new size. * Old contents will not be altered, and may be * cropped to fit the new size. * @param width Width in pixels. * @param height Height in pixels. */
| 858 | * @param height Height in pixels. |
| 859 | */ |
| 860 | void Surface::resize(int width, int height) |
| 861 | { |
| 862 | // Set up new surface |
| 863 | Uint8 bpp = _surface->format->BitsPerPixel; |
| 864 | int pitch = GetPitch(bpp, width); |
| 865 | void *alignedBuffer = NewAligned(bpp, width, height); |
| 866 | SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(alignedBuffer, width, height, bpp, pitch, 0, 0, 0, 0); |
| 867 | |
| 868 | if (surface == 0) |
| 869 | { |
| 870 | throw Exception(SDL_GetError()); |
| 871 | } |
| 872 | |
| 873 | // Copy old contents |
| 874 | SDL_SetColorKey(surface, SDL_SRCCOLORKEY, 0); |
| 875 | SDL_SetColors(surface, getPalette(), 0, 255); |
| 876 | SDL_BlitSurface(_surface, 0, surface, 0); |
| 877 | |
| 878 | // Delete old surface |
| 879 | DeleteAligned(_alignedBuffer); |
| 880 | SDL_FreeSurface(_surface); |
| 881 | _alignedBuffer = alignedBuffer; |
| 882 | _surface = surface; |
| 883 | |
| 884 | _clear.w = getWidth(); |
| 885 | _clear.h = getHeight(); |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Changes the width of the surface. |
nothing calls this directly
no test coverage detected