From b45cadb0654ce47dea0d24046110820b9ce8ae99 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 1 Jan 2019 23:06:35 +0100 Subject: GRAPHICS: Enhanced setAlpha method --- graphics/transparent_surface.cpp | 6 ++++-- graphics/transparent_surface.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'graphics') diff --git a/graphics/transparent_surface.cpp b/graphics/transparent_surface.cpp index a24f7198aa..eb8d3fe5ce 100644 --- a/graphics/transparent_surface.cpp +++ b/graphics/transparent_surface.cpp @@ -719,15 +719,17 @@ void TransparentSurface::applyColorKey(uint8 rKey, uint8 gKey, uint8 bKey, bool /** * Sets alpha channel for all pixels to specified value * @param alpha value of the alpha channel to set + * @param skipTransparent if set to true, then do not touch pixels with alpha=0 */ -void TransparentSurface::setAlpha(uint8 alpha) { +void TransparentSurface::setAlpha(uint8 alpha, bool skipTransparent) { assert(format.bytesPerPixel == 4); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { uint32 pix = ((uint32 *)pixels)[i * w + j]; uint8 r, g, b, a; format.colorToARGB(pix, a, r, g, b); - a = alpha; + if (!skipTransparent || a) + a = alpha; ((uint32 *)pixels)[i * w + j] = format.ARGBToColor(a, r, g, b); } } diff --git a/graphics/transparent_surface.h b/graphics/transparent_surface.h index 0738c90f90..8f4493679b 100644 --- a/graphics/transparent_surface.h +++ b/graphics/transparent_surface.h @@ -137,7 +137,7 @@ struct TransparentSurface : public Graphics::Surface { TSpriteBlendMode blend = BLEND_NORMAL); void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false); - void setAlpha(uint8 alpha); + void setAlpha(uint8 alpha, bool skipTransparent = false); /** * @brief Scale function; this returns a transformed version of this surface after rotation and -- cgit v1.2.3