Abstract operations on SDL_surface flags behind accessors
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user