1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 06:28:30 +02:00

Merge pull request #647 from InfoTeddy/general-bug-fixes-4

Copy blend mode to recreated surfaces, fixing room name background during menu animation in Flip Mode
This commit is contained in:
Terry Cavanagh 2021-03-06 16:56:28 +10:30 committed by GitHub
commit 1163a8cca4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,55 @@ void setRect( SDL_Rect& _r, int x, int y, int w, int h )
_r.h = h;
}
static SDL_Surface* RecreateSurfaceWithDimensions(
SDL_Surface* surface,
const int width,
const int height
) {
SDL_Surface* retval;
SDL_BlendMode blend_mode;
if (surface == NULL)
{
return NULL;
}
retval = SDL_CreateRGBSurface(
surface->flags,
width,
height,
surface->format->BitsPerPixel,
surface->format->Rmask,
surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask
);
if (retval == NULL)
{
return NULL;
}
SDL_GetSurfaceBlendMode(surface, &blend_mode);
SDL_SetSurfaceBlendMode(retval, blend_mode);
return retval;
}
static SDL_Surface* RecreateSurface(SDL_Surface* surface)
{
if (surface == NULL)
{
return NULL;
}
return RecreateSurfaceWithDimensions(
surface,
surface->w,
surface->h
);
}
SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height )
{
// Create an SDL_Rect with the area of the _surface
@ -21,15 +70,10 @@ SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, i
area.h = height;
//Convert to the correct display format after nabbing the new _surface or we will slow things down.
SDL_Surface* preSurface = SDL_CreateRGBSurface(
SDL_SWSURFACE,
SDL_Surface* preSurface = RecreateSurfaceWithDimensions(
metaSurface,
width,
height,
metaSurface->format->BitsPerPixel,
metaSurface->format->Rmask,
metaSurface->format->Gmask,
metaSurface->format->Bmask,
metaSurface->format->Amask
height
);
// Lastly, apply the area from the meta _surface onto the whole of the sub _surface.
@ -103,8 +147,7 @@ SDL_Surface * ScaleSurface( SDL_Surface *_surface, int Width, int Height, SDL_Su
SDL_Surface *_ret;
if(Dest == NULL)
{
_ret = SDL_CreateRGBSurface(_surface->flags, Width, Height, _surface->format->BitsPerPixel,
_surface->format->Rmask, _surface->format->Gmask, _surface->format->Bmask, _surface->format->Amask);
_ret = RecreateSurfaceWithDimensions(_surface, Width, Height);
if(_ret == NULL)
{
return NULL;
@ -132,8 +175,7 @@ SDL_Surface * ScaleSurface( SDL_Surface *_surface, int Width, int Height, SDL_Su
SDL_Surface * FlipSurfaceVerticle(SDL_Surface* _src)
{
SDL_Surface * ret = SDL_CreateRGBSurface(_src->flags, _src->w, _src->h, _src->format->BitsPerPixel,
_src->format->Rmask, _src->format->Gmask, _src->format->Bmask, _src->format->Amask);
SDL_Surface * ret = RecreateSurface(_src);
if(ret == NULL)
{
return NULL;
@ -168,16 +210,7 @@ void BlitSurfaceColoured(
const SDL_PixelFormat& fmt = *(_src->format);
SDL_Surface* tempsurface = SDL_CreateRGBSurface(
SDL_SWSURFACE,
_src->w,
_src->h,
fmt.BitsPerPixel,
fmt.Rmask,
fmt.Gmask,
fmt.Bmask,
fmt.Amask
);
SDL_Surface* tempsurface = RecreateSurface(_src);
for(int x = 0; x < tempsurface->w; x++)
{
@ -209,16 +242,7 @@ void BlitSurfaceTinted(
const SDL_PixelFormat& fmt = *(_src->format);
SDL_Surface* tempsurface = SDL_CreateRGBSurface(
SDL_SWSURFACE,
_src->w,
_src->h,
fmt.BitsPerPixel,
fmt.Rmask,
fmt.Gmask,
fmt.Bmask,
fmt.Amask
);
SDL_Surface* tempsurface = RecreateSurface(_src);
for (int x = 0; x < tempsurface->w; x++) {
for (int y = 0; y < tempsurface->h; y++) {
@ -295,8 +319,7 @@ void UpdateFilter(void)
SDL_Surface* ApplyFilter( SDL_Surface* _src )
{
SDL_Surface* _ret = SDL_CreateRGBSurface(_src->flags, _src->w, _src->h, _src->format->BitsPerPixel,
_src->format->Rmask, _src->format->Gmask, _src->format->Bmask, _src->format->Amask);
SDL_Surface* _ret = RecreateSurface(_src);
int redOffset = rand() % 4;