diff --git a/sc2/src/libs/graphics/sdl/sdl1_common.c b/sc2/src/libs/graphics/sdl/sdl1_common.c index 96eb5fcbc..68be53419 100644 --- a/sc2/src/libs/graphics/sdl/sdl1_common.c +++ b/sc2/src/libs/graphics/sdl/sdl1_common.c @@ -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 diff --git a/sc2/src/libs/graphics/sdl/sdl2_common.c b/sc2/src/libs/graphics/sdl/sdl2_common.c index 3e73c10b5..d34d01568 100644 --- a/sc2/src/libs/graphics/sdl/sdl2_common.c +++ b/sc2/src/libs/graphics/sdl/sdl2_common.c @@ -366,4 +366,56 @@ TFB_SetGamma (float gamma) 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 diff --git a/sc2/src/libs/graphics/sdl/sdl_common.h b/sc2/src/libs/graphics/sdl/sdl_common.h index 2e1a60c8a..fc9d4968b 100644 --- a/sc2/src/libs/graphics/sdl/sdl_common.h +++ b/sc2/src/libs/graphics/sdl/sdl_common.h @@ -45,5 +45,11 @@ extern SDL_Surface *SDL_Screens[TFB_GFX_NUMSCREENS]; extern SDL_Surface *format_conv_surf; 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