From f21dae63390aa872062bcfc96fc6817b0fcfe601 Mon Sep 17 00:00:00 2001 From: Thomas--S Date: Sat, 2 Jul 2016 17:58:08 +0200 Subject: Add an [opacity: texture modifier. Makes the base image transparent according to the given ratio. r must be between 0 and 255. 0 means totally transparent. 255 means totally opaque. Useful for texture overlaying. --- src/client/tile.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/client') diff --git a/src/client/tile.cpp b/src/client/tile.cpp index ec8c95f02..3b5d2a3ae 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -1735,6 +1735,36 @@ bool TextureSource::generateImagePart(std::string part_of_name, baseimg->drop(); baseimg = image; } + /* + [opacity:R + Makes the base image transparent according to the given ratio. + R must be between 0 and 255. + 0 means totally transparent. + 255 means totally opaque. + */ + else if (str_starts_with(part_of_name, "[opacity:")) { + if (baseimg == NULL) { + errorstream << "generateImagePart(): baseimg == NULL " + << "for part_of_name=\"" << part_of_name + << "\", cancelling." << std::endl; + return false; + } + + Strfnd sf(part_of_name); + sf.next(":"); + + u32 ratio = mystoi(sf.next(""), 0, 255); + + core::dimension2d dim = baseimg->getDimension(); + + for (u32 y = 0; y < dim.Height; y++) + for (u32 x = 0; x < dim.Width; x++) + { + video::SColor c = baseimg->getPixel(x,y); + c.setAlpha(floor((c.getAlpha() * ratio) / 255 + 0.5)); + baseimg->setPixel(x,y,c); + } + } else { errorstream << "generateImagePart(): Invalid " -- cgit v1.2.3