GRAPHICS: Enhanced setAlpha method
This commit is contained in:
parent
8259a8aa33
commit
b45cadb065
2 changed files with 5 additions and 3 deletions
|
@ -719,14 +719,16 @@ void TransparentSurface::applyColorKey(uint8 rKey, uint8 gKey, uint8 bKey, bool
|
||||||
/**
|
/**
|
||||||
* Sets alpha channel for all pixels to specified value
|
* Sets alpha channel for all pixels to specified value
|
||||||
* @param alpha value of the alpha channel to set
|
* @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);
|
assert(format.bytesPerPixel == 4);
|
||||||
for (int i = 0; i < h; i++) {
|
for (int i = 0; i < h; i++) {
|
||||||
for (int j = 0; j < w; j++) {
|
for (int j = 0; j < w; j++) {
|
||||||
uint32 pix = ((uint32 *)pixels)[i * w + j];
|
uint32 pix = ((uint32 *)pixels)[i * w + j];
|
||||||
uint8 r, g, b, a;
|
uint8 r, g, b, a;
|
||||||
format.colorToARGB(pix, a, r, g, b);
|
format.colorToARGB(pix, a, r, g, b);
|
||||||
|
if (!skipTransparent || a)
|
||||||
a = alpha;
|
a = alpha;
|
||||||
((uint32 *)pixels)[i * w + j] = format.ARGBToColor(a, r, g, b);
|
((uint32 *)pixels)[i * w + j] = format.ARGBToColor(a, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ struct TransparentSurface : public Graphics::Surface {
|
||||||
TSpriteBlendMode blend = BLEND_NORMAL);
|
TSpriteBlendMode blend = BLEND_NORMAL);
|
||||||
|
|
||||||
void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false);
|
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
|
* @brief Scale function; this returns a transformed version of this surface after rotation and
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue