Skip to content

Commit

Permalink
tmxrasterizer: Fixed --hide/show-layer to work on group layers
Browse files Browse the repository at this point in the history
When using --hide-layer or --show-layer with the name of a group layer,
it now hides or shows all children of that group layer respectively.

Hiding a layer overrides showing a layer, which means you can hide some
children of a group layer that was explicitly shown.

Fixes #3899
  • Loading branch information
bjorn committed Mar 6, 2024
1 parent f46b444 commit 5b84675
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* GameMaker 2 plugin: Fixed positioning of objects on isometric maps
* tmxrasterizer: Added --hide-object and --show-object arguments (by Lars Luz, #3819)
* tmxrasterizer: Added --frames and --frame-duration arguments to export animated maps as multiple images (#3868)
* tmxrasterizer: Fixed --hide/show-layer to work on group layers (#3899)
* tmxviewer: Added support for viewing JSON maps (#3866)
* AutoMapping: Ignore empty outputs per-rule (#3523)
* Windows: Fixed the support for WebP images (updated to Qt 6.6.1, #3661)
Expand Down
25 changes: 17 additions & 8 deletions src/tmxrasterizer/tmxrasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "tmxrasterizer.h"

#include "grouplayer.h"
#include "imagelayer.h"
#include "map.h"
#include "mapformat.h"
Expand All @@ -44,9 +45,7 @@

using namespace Tiled;

TmxRasterizer::TmxRasterizer()
{
}
TmxRasterizer::TmxRasterizer() = default;

void TmxRasterizer::drawMapLayers(const MapRenderer &renderer,
QPainter &painter,
Expand All @@ -62,9 +61,9 @@ void TmxRasterizer::drawMapLayers(const MapRenderer &renderer,
painter.setOpacity(layer->effectiveOpacity());
painter.translate(offset);

const TileLayer *tileLayer = dynamic_cast<const TileLayer*>(layer);
const ImageLayer *imageLayer = dynamic_cast<const ImageLayer*>(layer);
const ObjectGroup *objectGroup = dynamic_cast<const ObjectGroup*>(layer);
auto *tileLayer = dynamic_cast<const TileLayer*>(layer);
auto *imageLayer = dynamic_cast<const ImageLayer*>(layer);
auto *objectGroup = dynamic_cast<const ObjectGroup*>(layer);

if (tileLayer) {
renderer.drawTileLayer(&painter, tileLayer);
Expand Down Expand Up @@ -98,16 +97,26 @@ void TmxRasterizer::drawMapLayers(const MapRenderer &renderer,
}
}

static bool containsLayerOrParentLayerName(const Layer *layer, const QStringList &layerNames)
{
while (layer) {
if (layerNames.contains(layer->name(), Qt::CaseInsensitive))
return true;
layer = layer->parentLayer();
}
return false;
}

bool TmxRasterizer::shouldDrawLayer(const Layer *layer) const
{
if (!(mLayerTypesToShow & layer->layerType()))
return false;

if (mLayersToHide.contains(layer->name(), Qt::CaseInsensitive))
if (containsLayerOrParentLayerName(layer, mLayersToHide))
return false;

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

Expand Down

0 comments on commit 5b84675

Please sign in to comment.