/** * 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. */ void Surface::resize(int width, int height) { // Set up new surface Uint8 bpp = _surface->format->BitsPerPixel; int pitch = GetPitch(bpp, width); void *alignedBuffer = NewAligned(bpp, width, height); SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(alignedBuffer, width, height, bpp, pitch, 0, 0, 0, 0); if (surface == 0) { throw Exception(SDL_GetError()); } // Copy old contents SDL_SetColorKey(surface, SDL_SRCCOLORKEY, 0); SDL_SetColors(surface, getPalette(), 0, 255); SDL_BlitSurface(_surface, 0, surface, 0); // Delete old surface DeleteAligned(_alignedBuffer); SDL_FreeSurface(_surface); _alignedBuffer = alignedBuffer; _surface = surface; _clear.w = getWidth(); _clear.h = getHeight(); }
/** * Sets up a blank 8bpp surface with the specified size and position, * with pure black as the transparent color. * @note Surfaces don't have to fill the whole size since their * background is transparent, specially subclasses with their own * drawing logic, so it just covers the maximum drawing area. * @param width Width in pixels. * @param height Height in pixels. * @param x X position in pixels. * @param y Y position in pixels. * @param bpp Bits-per-pixel depth. */ Surface::Surface(int width, int height, int x, int y, int bpp) : _x(x), _y(y), _visible(true), _hidden(false), _redraw(false), _originalColors(0), _alignedBuffer(0) { _alignedBuffer = NewAligned(bpp, width, height); _surface = SDL_CreateRGBSurfaceFrom(_alignedBuffer, width, height, bpp, GetPitch(bpp, width), 0, 0, 0, 0); if (_surface == 0) { throw Exception(SDL_GetError()); } SDL_SetColorKey(_surface, SDL_SRCCOLORKEY, 0); _crop.w = 0; _crop.h = 0; _crop.x = 0; _crop.y = 0; _dx = Screen::getDX(); _dy = Screen::getDY(); }
/** * Sets up a blank 8bpp surface with the specified size and position, * with pure black as the transparent color. * @note Surfaces don't have to fill the whole size since their * background is transparent, specially subclasses with their own * drawing logic, so it just covers the maximum drawing area. * @param width Width in pixels. * @param height Height in pixels. * @param x X position in pixels. * @param y Y position in pixels. * @param bpp Bits-per-pixel depth. */ Surface::Surface(int width, int height, int x, int y, int bpp) : _x(x), _y(y), _visible(true), _hidden(false), _redraw(false), _tftdMode(false), _alignedBuffer(0) { _alignedBuffer = NewAligned(bpp, width, height); _surface = SDL_CreateRGBSurfaceFrom(_alignedBuffer, width, height, bpp, GetPitch(bpp, width), 0, 0, 0, 0); if (_surface == 0) { throw Exception(SDL_GetError()); } SDL_SetColorKey(_surface, SDL_SRCCOLORKEY, 0); _crop.w = 0; _crop.h = 0; _crop.x = 0; _crop.y = 0; _clear.x = 0; _clear.y = 0; _clear.w = getWidth(); _clear.h = getHeight(); }
/** * Performs a deep copy of an existing surface. * @param other Surface to copy from. */ Surface::Surface(const Surface& other) { //if is native OpenXcom aligned surface if(other._alignedBuffer) { Uint8 bpp = other._surface->format->BitsPerPixel; int width = other.getWidth(); int height = other.getHeight(); int pitch = GetPitch(bpp, width); _alignedBuffer = NewAligned(bpp, width, height); _surface = SDL_CreateRGBSurfaceFrom(_alignedBuffer, width, height, bpp, pitch, 0, 0, 0, 0); SDL_SetColorKey(_surface, SDL_SRCCOLORKEY, 0); //cant call `SetPalette` because its vitual function and it dont work correctly in constructor //additionally it use original colors, not temporarily ones. SDL_SetColors(_surface, other._originalColors ? other._originalColors : other.getPalette(), 0, 255); memcpy(_alignedBuffer, other._alignedBuffer, height*pitch); } else { _surface = SDL_ConvertSurface(other._surface, other._surface->format, other._surface->flags); _alignedBuffer = 0; } if (_surface == 0) { throw Exception(SDL_GetError()); } _x = other._x; _y = other._y; _crop.w = other._crop.w; _crop.h = other._crop.h; _crop.x = other._crop.x; _crop.y = other._crop.y; _visible = other._visible; _hidden = other._hidden; _redraw = other._redraw; _originalColors = 0; _dx = other._dx; _dy = other._dy; }