From 28438bba27168289be59a26d3ae55e3f3658d8d3 Mon Sep 17 00:00:00 2001 From: BlockMen Date: Fri, 3 Oct 2014 06:11:21 +0200 Subject: Add [colorize modifier --- src/tile.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/tile.cpp') diff --git a/src/tile.cpp b/src/tile.cpp index ebef77fb9..fa2f4c84e 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "gamedef.h" #include "strfnd.h" +#include "util/string.h" // for parseColorString() #ifdef __ANDROID__ #include @@ -1588,10 +1589,46 @@ bool TextureSource::generateImagePart(std::string part_of_name, << filename << "\"."; } } + /* + [colorize:color + Overlays image with given color + color = color as ColorString + */ + else if (part_of_name.substr(0,10) == "[colorize:") { + Strfnd sf(part_of_name); + sf.next(":"); + std::string color_str = sf.next(":"); + + if (baseimg == NULL) { + errorstream << "generateImagePart(): baseimg != NULL " + << "for part_of_name=\"" << part_of_name + << "\", cancelling." << std::endl; + return false; + } + + video::SColor color; + if (!parseColorString(color_str, color, false)) + return false; + + core::dimension2d dim = baseimg->getDimension(); + video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim); + + if (!img) { + errorstream << "generateImagePart(): Could not create image " + << "for part_of_name=\"" << part_of_name + << "\", cancelling." << std::endl; + return false; + } + + img->fill(video::SColor(color)); + // Overlay the colored image + blit_with_alpha_overlay(img, baseimg, v2s32(0,0), v2s32(0,0), dim); + img->drop(); + } else { - errorstream<<"generateImagePart(): Invalid " - " modification: \""<