Skip to content

Commit

Permalink
Fixed drawing lines with stamps having differently sized variations
Browse files Browse the repository at this point in the history
This is also a small optimization since it avoids calling
MapDocument::unifyTilesets when the stamp stays the same (which is
usually the case, since drawing with multiple variations is rare).

See issue #3533
  • Loading branch information
bjorn committed Mar 1, 2023
1 parent 85a6531 commit 087c645
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Fixed slight drift when zooming the map view in/out
* Fixed remaining lag after switching off hardware acceleration (#3584)
* Fixed point object hover highlight position (#3571)
* Fixed drawing lines with stamps having differently sized variations (#3533)
* Fixed compile against Qt 6.4
* snap: Added Wayland platform plugin and additional image format plugins
* AppImage: Updated to Sentry 0.5.4
Expand Down
21 changes: 15 additions & 6 deletions src/tiled/stampbrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,21 +478,23 @@ void StampBrush::drawPreviewLayer(const QVector<QPoint> &points)
QHash<const Map *, QRegion> regionCache;
QHash<const Map *, Map *> shiftedCopies;
const auto randomVariations = mStamp.randomVariations();
const Map::StaggerAxis mapStaggerAxis = mapDocument()->map()->staggerAxis();
const Map::StaggerIndex mapStaggerIndex = mapDocument()->map()->staggerIndex();

mMissingTilesets.clear();

for (const QPoint &p : points) {
Map *map = randomVariations.pick();
mapDocument()->unifyTilesets(*map, mMissingTilesets);
// Pick a random variation for the first position
Map *variation = randomVariations.pick();
mapDocument()->unifyTilesets(*variation, mMissingTilesets);

Map::StaggerAxis mapStaggerAxis = mapDocument()->map()->staggerAxis();
for (const QPoint &p : points) {
Map *map = variation;

// if staggered map, makes sure stamp stays the same
if (mapDocument()->map()->isStaggered()
&& ((mapStaggerAxis == Map::StaggerY) ? map->height() > 1 : map->width() > 1)) {

Map::StaggerIndex mapStaggerIndex = mapDocument()->map()->staggerIndex();
Map::StaggerIndex stampStaggerIndex = map->staggerIndex();
const Map::StaggerIndex stampStaggerIndex = map->staggerIndex();

if (mapStaggerAxis == Map::StaggerY) {
bool topIsOdd = (p.y() - map->height() / 2) & 1;
Expand Down Expand Up @@ -545,6 +547,13 @@ void StampBrush::drawPreviewLayer(const QVector<QPoint> &points)

PaintOperation op = { centered, map };
operations.append(op);

// Pick a potentially new random variation for the next position
Map *newVariation = randomVariations.pick();
if (variation != newVariation) {
variation = newVariation;
mapDocument()->unifyTilesets(*variation, mMissingTilesets);
}
}
}

Expand Down

0 comments on commit 087c645

Please sign in to comment.