Skip to content

Commit

Permalink
tmxrasterizer: Added --show-layer option (mapeditor#2858)
Browse files Browse the repository at this point in the history
  • Loading branch information
varnholt authored Jul 14, 2020
1 parent c992a7f commit a41b332
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/tmxrasterizer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ int main(int argc, char *argv[])
{ "hide-layer",
QCoreApplication::translate("main", "Specifies a layer to omit from the output image. Can be repeated to hide multiple layers."),
QCoreApplication::translate("main", "name") },
{ "show-layer",
QCoreApplication::translate("main", "If used only specified layers are shown. Can be repeated to show multiple specified layers only."),
QCoreApplication::translate("main", "name") },
});
parser.addPositionalArgument("map|world", QCoreApplication::translate("main", "Map or world file to render."));
parser.addPositionalArgument("image", QCoreApplication::translate("main", "Image file to output."));
Expand All @@ -94,6 +97,7 @@ int main(int argc, char *argv[])
w.setSmoothImages(!parser.isSet(QLatin1String("no-smoothing")));
w.setIgnoreVisibility(parser.isSet(QLatin1String("ignore-visibility")));
w.setLayersToHide(parser.values(QLatin1String("hide-layer")));
w.setLayersToShow(parser.values(QLatin1String("show-layer")));

if (parser.isSet(QLatin1String("size"))) {
bool ok;
Expand Down
7 changes: 6 additions & 1 deletion src/tmxrasterizer/tmxrasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ bool TmxRasterizer::shouldDrawLayer(const Layer *layer) const
if (mLayersToHide.contains(layer->name(), Qt::CaseInsensitive))
return false;

if (!mLayersToShow.empty()) {
if (!mLayersToShow.contains(layer->name(), Qt::CaseInsensitive))
return false;
}

if (mIgnoreVisibility)
return true;

Expand Down Expand Up @@ -230,7 +235,7 @@ int TmxRasterizer::renderWorld(const QString &worldFileName,
qUtf8Printable(errorString));
return 1;
}

auto const maps = world->allMaps();
if (maps.isEmpty()) {
qWarning("Error: The world file to rasterize contains no maps : \"%s\"",
Expand Down
2 changes: 2 additions & 0 deletions src/tmxrasterizer/tmxrasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TmxRasterizer
void setIgnoreVisibility(bool IgnoreVisibility) { mIgnoreVisibility = IgnoreVisibility; }

void setLayersToHide(QStringList layersToHide) { mLayersToHide = layersToHide; }
void setLayersToShow(QStringList layersToShow) { mLayersToShow = layersToShow; }

int render(const QString &fileName, const QString &imageFileName);

Expand All @@ -72,6 +73,7 @@ class TmxRasterizer
bool mSmoothImages;
bool mIgnoreVisibility;
QStringList mLayersToHide;
QStringList mLayersToShow;

void drawMapLayers(MapRenderer &renderer, QPainter &painter, Map &map, QPoint mapOffset = QPoint(0, 0)) const;
int renderMap(const QString &mapFileName, const QString &imageFileName);
Expand Down

0 comments on commit a41b332

Please sign in to comment.