diff options
author | Luke Puchner-Hardman <x.lukk3.x@gmail.com> | 2014-09-23 14:39:34 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2017-01-02 15:28:06 +0100 |
commit | 7057c196c442ff3484b53f48d940f4c9e0ffe23a (patch) | |
tree | ea6e57d1755253577e3eda6fe22280314d22fb87 /src/client | |
parent | 523f0e8c5bce0cb58215dc1f9d027cf32394e3c3 (diff) | |
download | minetest-7057c196c442ff3484b53f48d940f4c9e0ffe23a.tar.gz minetest-7057c196c442ff3484b53f48d940f4c9e0ffe23a.tar.bz2 minetest-7057c196c442ff3484b53f48d940f4c9e0ffe23a.zip |
Added "[sheet" to the texture special commands.
"[sheet:WxH:X,Y" assumes the base image is a tilesheet with W*H tiles
on it and crops to the tile at position X,Y. Basically it works
like "[verticalframe" but in 2D.
For testing, I combined the four default_chest images into one.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/tile.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 7f7535df6..4d2166342 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -1827,6 +1827,49 @@ bool TextureSource::generateImagePart(std::string part_of_name, baseimg->setPixel(x, y, c); } } + /* + [sheet:WxH:X,Y + Retrieves a tile at position X,Y (in tiles) + from the base image it assumes to be a + tilesheet with dimensions W,H (in tiles). + */ + else if (part_of_name.substr(0,7) == "[sheet:") { + 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 w0 = stoi(sf.next("x")); + u32 h0 = stoi(sf.next(":")); + u32 x0 = stoi(sf.next(",")); + u32 y0 = stoi(sf.next(":")); + + core::dimension2d<u32> img_dim = baseimg->getDimension(); + core::dimension2d<u32> tile_dim(v2u32(img_dim) / v2u32(w0, h0)); + + video::IImage *img = driver->createImage( + video::ECF_A8R8G8B8, tile_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(0,0,0,0)); + v2u32 vdim(tile_dim); + core::rect<s32> rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); + baseimg->copyToWithAlpha(img, v2s32(0), rect, + video::SColor(255,255,255,255), NULL); + + // Replace baseimg + baseimg->drop(); + baseimg = img; + } else { errorstream << "generateImagePart(): Invalid " |