Abstract operations on SDL_surface flags behind accessors

This commit is contained in:
Michael Martin
2019-08-21 21:43:36 -07:00
parent a6d42126f7
commit b6724c9300
3 changed files with 111 additions and 0 deletions
+53
View File
@@ -400,4 +400,57 @@ TFB_SetGamma (float gamma)
} }
} }
int
TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
{
if (!surface || !surface->format || !alpha)
{
return -1;
}
if (surface->flags & SDL_SRCALPHA)
{
*alpha = surface->format->alpha;
}
else
{
*alpha = 255;
}
return 0;
}
int
TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
{
return SDL_SetAlpha (surface, SDL_SRCALPHA, alpha);
}
int
TFB_DisableSurfaceAlphaMod (SDL_Surface *surface)
{
return SDL_SetAlpha (surface, 0, 255);
}
int
TFB_GetColorKey (SDL_Surface *surface, Uint32 *key)
{
if (surface && surface->format && key &&
(surface->flags & SDL_SRCCOLORKEY))
{
*key = surface->format->colorkey;
return 0;
}
return -1;
}
int
TFB_SetColorKey (SDL_Surface *surface, Uint32 key)
{
return SDL_SetColorKey (surface, SDL_SRCCOLORKEY, key);
}
int
TFB_DisableColorKey (SDL_Surface *surface)
{
return SDL_SetColorKey (surface, 0, 0);
}
#endif #endif
+52
View File
@@ -366,4 +366,56 @@ TFB_SetGamma (float gamma)
log_add (log_Warning, "Custom gamma correction is not available in the SDL2 engine."); log_add (log_Warning, "Custom gamma correction is not available in the SDL2 engine.");
} }
int
TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
{
SDL_BlendMode blend_mode;
if (!surface || !alpha)
{
return -1;
}
if (SDL_GetSurfaceBlendMode (surface, &blend_mode) == 0)
{
return SDL_GetSurfaceAlphaMod (surface, alpha);
}
*alpha = 255;
return 0;
}
int
TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
{
int result = SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_BLEND);
if (result == 0)
{
result = SDL_SetSurfaceAlphaMod (surface, alpha);
}
return result;
}
int
TFB_DisableSurfaceAlphaMod (SDL_Surface *surface)
{
SDL_SetSurfaceAlphaMod (surface, 255);
return SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_NONE);
}
int
TFB_GetColorKey (SDL_Surface *surface, Uint32 *key)
{
return SDL_GetColorKey (surface, key);
}
int
TFB_SetColorKey (SDL_Surface *surface, Uint32 key)
{
return SDL_SetColorKey (surface, SDL_TRUE, key);
}
int
TFB_DisableColorKey (SDL_Surface *surface)
{
return SDL_SetColorKey (surface, SDL_FALSE, 0);
}
#endif #endif
+6
View File
@@ -45,5 +45,11 @@ extern SDL_Surface *SDL_Screens[TFB_GFX_NUMSCREENS];
extern SDL_Surface *format_conv_surf; extern SDL_Surface *format_conv_surf;
SDL_Surface* TFB_DisplayFormatAlpha (SDL_Surface *surface); SDL_Surface* TFB_DisplayFormatAlpha (SDL_Surface *surface);
int TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha);
int TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha);
int TFB_DisableSurfaceAlphaMod (SDL_Surface *surface);
int TFB_GetColorKey (SDL_Surface *surface, Uint32 *key);
int TFB_SetColorKey (SDL_Surface *surface, Uint32 key);
int TFB_DisableColorKey (SDL_Surface *surface);
#endif #endif