Skip to content

Commit 53e9587

Browse files
SmallJokerest31
authored andcommittedMay 9, 2016
Add [resize texture modifier Resizes the texture to the given dimensions.
1 parent 95446f4 commit 53e9587

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
 

‎doc/lua_api.txt

+7
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ Example:
279279

280280
[combine:16x32:0,0=default_cobble.png:0,16=default_wood.png
281281

282+
#### `[resize:<w>x<h>`
283+
Resizes the texture to the given dimensions.
284+
285+
Example:
286+
287+
default_sandstone.png^[resize:16x16
288+
282289
#### `[brighten`
283290
Brightens the texture.
284291

‎src/client/tile.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,6 @@ bool TextureSource::generateImagePart(std::string part_of_name,
13521352
u32 r1 = stoi(sf.next(","));
13531353
u32 g1 = stoi(sf.next(","));
13541354
u32 b1 = stoi(sf.next(""));
1355-
std::string filename = sf.next("");
13561355

13571356
core::dimension2d<u32> dim = baseimg->getDimension();
13581357

@@ -1711,6 +1710,31 @@ bool TextureSource::generateImagePart(std::string part_of_name,
17111710
}
17121711
}
17131712
}
1713+
/*
1714+
[resize:WxH
1715+
Resizes the base image to the given dimensions
1716+
*/
1717+
else if (str_starts_with(part_of_name, "[resize"))
1718+
{
1719+
if (baseimg == NULL) {
1720+
errorstream << "generateImagePart(): baseimg == NULL "
1721+
<< "for part_of_name=\""<< part_of_name
1722+
<< "\", cancelling." << std::endl;
1723+
return false;
1724+
}
1725+
1726+
Strfnd sf(part_of_name);
1727+
sf.next(":");
1728+
u32 width = stoi(sf.next("x"));
1729+
u32 height = stoi(sf.next(""));
1730+
core::dimension2d<u32> dim(width, height);
1731+
1732+
video::IImage* image = m_device->getVideoDriver()->
1733+
createImage(video::ECF_A8R8G8B8, dim);
1734+
baseimg->copyToScaling(image);
1735+
baseimg->drop();
1736+
baseimg = image;
1737+
}
17141738
else
17151739
{
17161740
errorstream << "generateImagePart(): Invalid "

0 commit comments

Comments
 (0)
Please sign in to comment.