mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-14 06:30:27 +01:00
Allow rendering (or omitting) scales at every image edge
This commit is contained in:
parent
89ed5494cc
commit
77fdcd15fb
|
@ -86,3 +86,6 @@ zoom:
|
|||
|
||||
colors:
|
||||
Forcefully set path to colors.txt file (it's autodetected otherwise), e.g. ``--colors ../minetest/mycolors.txt``
|
||||
|
||||
scales:
|
||||
Draw scales on specified image edges (letters *t b l r* meaning top, bottom, left and right), e.g. ``--scales tbr``
|
||||
|
|
|
@ -109,7 +109,8 @@ TileGenerator::TileGenerator():
|
|||
m_drawAlpha(false),
|
||||
m_shading(true),
|
||||
m_backend(""),
|
||||
m_border(0),
|
||||
m_xBorder(0),
|
||||
m_yBorder(0),
|
||||
m_db(NULL),
|
||||
m_image(NULL),
|
||||
m_xMin(INT_MAX),
|
||||
|
@ -122,7 +123,8 @@ TileGenerator::TileGenerator():
|
|||
m_geomY(-2048),
|
||||
m_geomX2(2048),
|
||||
m_geomY2(2048),
|
||||
m_zoom(1)
|
||||
m_zoom(1),
|
||||
m_scales(SCALE_LEFT | SCALE_TOP)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -159,6 +161,11 @@ void TileGenerator::setZoom(int zoom)
|
|||
m_zoom = zoom;
|
||||
}
|
||||
|
||||
void TileGenerator::setScales(uint flags)
|
||||
{
|
||||
m_scales = flags;
|
||||
}
|
||||
|
||||
Color TileGenerator::parseColor(const std::string &color)
|
||||
{
|
||||
Color parsed;
|
||||
|
@ -190,9 +197,6 @@ void TileGenerator::setDrawPlayers(bool drawPlayers)
|
|||
void TileGenerator::setDrawScale(bool drawScale)
|
||||
{
|
||||
m_drawScale = drawScale;
|
||||
if (m_drawScale) {
|
||||
m_border = 40;
|
||||
}
|
||||
}
|
||||
|
||||
void TileGenerator::setDrawAlpha(bool drawAlpha)
|
||||
|
@ -359,9 +363,16 @@ void TileGenerator::createImage()
|
|||
{
|
||||
m_mapWidth = (m_xMax - m_xMin + 1) * 16;
|
||||
m_mapHeight = (m_zMax - m_zMin + 1) * 16;
|
||||
if(m_drawScale) {
|
||||
m_xBorder = (m_scales & SCALE_LEFT) ? 40 : 0;
|
||||
m_yBorder = (m_scales & SCALE_TOP) ? 40 : 0;
|
||||
}
|
||||
|
||||
int image_width, image_height;
|
||||
image_width = (m_mapWidth * m_zoom) + m_border;
|
||||
image_height = (m_mapHeight * m_zoom) + m_border;
|
||||
image_width = (m_mapWidth * m_zoom) + m_xBorder;
|
||||
image_width += m_drawScale && (m_scales & SCALE_RIGHT) ? 40 : 0;
|
||||
image_height = (m_mapHeight * m_zoom) + m_yBorder;
|
||||
image_height += m_drawScale && (m_scales & SCALE_BOTTOM) ? 40 : 0;
|
||||
if(image_width > 4096 || image_height > 4096)
|
||||
std::cerr << "Warning: The width or height of the image to be created exceeds 4096 pixels!"
|
||||
<< " (Dimensions: " << image_width << "x" << image_height << ")"
|
||||
|
@ -633,36 +644,66 @@ inline void TileGenerator::renderShading(int zPos)
|
|||
void TileGenerator::renderScale()
|
||||
{
|
||||
int color = color2int(m_scaleColor);
|
||||
gdImageString(m_image, gdFontGetMediumBold(), 24, 0, reinterpret_cast<unsigned char *>(const_cast<char *>("X")), color);
|
||||
gdImageString(m_image, gdFontGetMediumBold(), 2, 24, reinterpret_cast<unsigned char *>(const_cast<char *>("Z")), color);
|
||||
|
||||
string scaleText;
|
||||
|
||||
for (int i = (m_xMin / 4) * 4; i <= m_xMax; i += 4) {
|
||||
stringstream buf;
|
||||
buf << i * 16;
|
||||
scaleText = buf.str();
|
||||
if (m_scales & SCALE_TOP) {
|
||||
gdImageString(m_image, gdFontGetMediumBold(), 24, 0, reinterpret_cast<unsigned char *>(const_cast<char *>("X")), color);
|
||||
for (int i = (m_xMin / 4) * 4; i <= m_xMax; i += 4) {
|
||||
stringstream buf;
|
||||
buf << i * 16;
|
||||
scaleText = buf.str();
|
||||
|
||||
int xPos = (m_xMin * -16 + i * 16)*m_zoom + m_border;
|
||||
gdImageString(m_image, gdFontGetMediumBold(), xPos + 2, 0, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
||||
gdImageLine(m_image, xPos, 0, xPos, m_border - 1, color);
|
||||
int xPos = (m_xMin * -16 + i * 16)*m_zoom + m_xBorder;
|
||||
gdImageString(m_image, gdFontGetMediumBold(), xPos + 2, 0, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
||||
gdImageLine(m_image, xPos, 0, xPos, m_yBorder - 1, color);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = (m_zMax / 4) * 4; i >= m_zMin; i -= 4) {
|
||||
stringstream buf;
|
||||
buf << i * 16;
|
||||
scaleText = buf.str();
|
||||
if (m_scales & SCALE_LEFT) {
|
||||
gdImageString(m_image, gdFontGetMediumBold(), 2, 24, reinterpret_cast<unsigned char *>(const_cast<char *>("Z")), color);
|
||||
for (int i = (m_zMax / 4) * 4; i >= m_zMin; i -= 4) {
|
||||
stringstream buf;
|
||||
buf << i * 16;
|
||||
scaleText = buf.str();
|
||||
|
||||
int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16))*m_zoom + m_border;
|
||||
gdImageString(m_image, gdFontGetMediumBold(), 2, yPos, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
||||
gdImageLine(m_image, 0, yPos, m_border - 1, yPos, color);
|
||||
int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16))*m_zoom + m_yBorder;
|
||||
gdImageString(m_image, gdFontGetMediumBold(), 2, yPos, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
||||
gdImageLine(m_image, 0, yPos, m_xBorder - 1, yPos, color);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_scales & SCALE_BOTTOM) {
|
||||
for (int i = (m_xMin / 4) * 4; i <= m_xMax; i += 4) {
|
||||
stringstream buf;
|
||||
buf << i * 16;
|
||||
scaleText = buf.str();
|
||||
|
||||
int xPos = (m_xMin * -16 + i * 16)*m_zoom + m_xBorder;
|
||||
int yPos = m_yBorder + m_mapHeight;
|
||||
gdImageString(m_image, gdFontGetMediumBold(), xPos + 2, yPos, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
||||
gdImageLine(m_image, xPos, yPos, xPos, yPos + 39, color);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_scales & SCALE_RIGHT) {
|
||||
for (int i = (m_zMax / 4) * 4; i >= m_zMin; i -= 4) {
|
||||
stringstream buf;
|
||||
buf << i * 16;
|
||||
scaleText = buf.str();
|
||||
|
||||
int xPos = m_xBorder + m_mapWidth;
|
||||
int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16))*m_zoom + m_yBorder;
|
||||
gdImageString(m_image, gdFontGetMediumBold(), xPos + 2, yPos, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
||||
gdImageLine(m_image, xPos, yPos, xPos + 39, yPos, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TileGenerator::renderOrigin()
|
||||
{
|
||||
int imageX = (-m_xMin * 16)*m_zoom + m_border;
|
||||
int imageY = (m_mapHeight - m_zMin * -16)*m_zoom + m_border;
|
||||
int imageX = (-m_xMin * 16)*m_zoom + m_xBorder;
|
||||
int imageY = (m_mapHeight - m_zMin * -16)*m_zoom + m_yBorder;
|
||||
gdImageArc(m_image, imageX, imageY, 12, 12, 0, 360, color2int(m_originColor));
|
||||
}
|
||||
|
||||
|
@ -672,8 +713,8 @@ void TileGenerator::renderPlayers(const std::string &inputPath)
|
|||
|
||||
PlayerAttributes players(inputPath);
|
||||
for (PlayerAttributes::Players::iterator player = players.begin(); player != players.end(); ++player) {
|
||||
int imageX = (player->x / 10 - m_xMin * 16)*m_zoom + m_border;
|
||||
int imageY = (m_mapHeight - (player->z / 10 - m_zMin * 16))*m_zoom + m_border;
|
||||
int imageX = (player->x / 10 - m_xMin * 16)*m_zoom + m_xBorder;
|
||||
int imageY = (m_mapHeight - (player->z / 10 - m_zMin * 16))*m_zoom + m_yBorder;
|
||||
|
||||
gdImageArc(m_image, imageX, imageY, 5, 5, 0, 360, color);
|
||||
gdImageString(m_image, gdFontGetMediumBold(), imageX + 2, imageY + 2, reinterpret_cast<unsigned char *>(const_cast<char *>(player->name.c_str())), color);
|
||||
|
@ -718,19 +759,19 @@ void TileGenerator::printUnknown()
|
|||
|
||||
inline int TileGenerator::getImageX(int val) const
|
||||
{
|
||||
return (m_zoom*val) + m_border;
|
||||
return (m_zoom*val) + m_xBorder;
|
||||
}
|
||||
|
||||
inline int TileGenerator::getImageY(int val) const
|
||||
{
|
||||
return (m_zoom*val) + m_border;
|
||||
return (m_zoom*val) + m_yBorder;
|
||||
}
|
||||
|
||||
inline void TileGenerator::setZoomed(gdImagePtr image, int y, int x, int color) {
|
||||
int xx,yy;
|
||||
for (xx = 0; xx < m_zoom; xx++) {
|
||||
for (yy = 0; yy < m_zoom; yy++) {
|
||||
image->tpixels[m_border + (y*m_zoom) + xx][m_border + (x*m_zoom) + yy] = color;
|
||||
image->tpixels[m_yBorder + (y*m_zoom) + xx][m_xBorder + (x*m_zoom) + yy] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,13 @@
|
|||
#include "db.h"
|
||||
#include "types.h"
|
||||
|
||||
enum {
|
||||
SCALE_TOP = (1 << 0),
|
||||
SCALE_BOTTOM = (1 << 1),
|
||||
SCALE_LEFT = (1 << 2),
|
||||
SCALE_RIGHT = (1 << 3),
|
||||
};
|
||||
|
||||
struct Color {
|
||||
Color(): r(0xFF), g(0xFF), b(0xFF), a(0) {};
|
||||
Color(uint8_t r, uint8_t g, uint8_t b): r(r), g(g), b(b), a(0) {};
|
||||
|
@ -72,6 +79,7 @@ public:
|
|||
void setBackend(std::string backend);
|
||||
void generate(const std::string &input, const std::string &output);
|
||||
void setZoom(int zoom);
|
||||
void setScales(uint flags);
|
||||
|
||||
private:
|
||||
void parseColorsStream(std::istream &in);
|
||||
|
@ -104,7 +112,7 @@ private:
|
|||
bool m_drawAlpha;
|
||||
bool m_shading;
|
||||
std::string m_backend;
|
||||
int m_border;
|
||||
int m_xBorder, m_yBorder;
|
||||
|
||||
DB *m_db;
|
||||
gdImagePtr m_image;
|
||||
|
@ -133,6 +141,7 @@ private:
|
|||
int m_blockAirId;
|
||||
int m_blockIgnoreId;
|
||||
int m_zoom;
|
||||
uint m_scales;
|
||||
}; // class TileGenerator
|
||||
|
||||
#endif // TILEGENERATOR_HEADER
|
||||
|
|
16
mapper.cpp
16
mapper.cpp
|
@ -1,4 +1,5 @@
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <getopt.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
@ -29,6 +30,7 @@ void usage()
|
|||
" --geometry x:y+w+h\n"
|
||||
" --zoom <zoomlevel>\n"
|
||||
" --colors <colors.txt>\n"
|
||||
" --scales [t][b][l][r]\n"
|
||||
"Color format: '#000000'\n";
|
||||
std::cout << usage_text;
|
||||
}
|
||||
|
@ -82,6 +84,7 @@ int main(int argc, char *argv[])
|
|||
{"max-y", required_argument, 0, 'c'},
|
||||
{"zoom", required_argument, 0, 'z'},
|
||||
{"colors", required_argument, 0, 'C'},
|
||||
{"scales", required_argument, 0, 'f'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -171,6 +174,19 @@ int main(int argc, char *argv[])
|
|||
generator.setGeometry(x, y, w, h);
|
||||
}
|
||||
break;
|
||||
case 'f': {
|
||||
uint flags = 0;
|
||||
if(strchr(optarg, 't') != NULL)
|
||||
flags |= SCALE_TOP;
|
||||
if(strchr(optarg, 'b') != NULL)
|
||||
flags |= SCALE_BOTTOM;
|
||||
if(strchr(optarg, 'l') != NULL)
|
||||
flags |= SCALE_LEFT;
|
||||
if(strchr(optarg, 'r') != NULL)
|
||||
flags |= SCALE_RIGHT;
|
||||
generator.setScales(flags);
|
||||
}
|
||||
break;
|
||||
case 'z': {
|
||||
std::istringstream iss;
|
||||
iss.str(optarg);
|
||||
|
|
Loading…
Reference in New Issue
Block a user