diff --git a/src/tiled/bucketfilltool.cpp b/src/tiled/bucketfilltool.cpp index ef514e86d4..5512230b73 100644 --- a/src/tiled/bucketfilltool.cpp +++ b/src/tiled/bucketfilltool.cpp @@ -413,6 +413,7 @@ void BucketFillTool::wangFill(TileLayer &tileLayerToFill, return; WangFiller wangFiller(mWangSet, + mapDocument()->map()->infinite(), dynamic_cast(mapDocument()->renderer()), mapDocument()->map()->staggerAxis()); diff --git a/src/tiled/stampbrush.cpp b/src/tiled/stampbrush.cpp index 34e72fc853..0c5fe81dcb 100644 --- a/src/tiled/stampbrush.cpp +++ b/src/tiled/stampbrush.cpp @@ -437,6 +437,7 @@ void StampBrush::drawPreviewLayer(const QVector &list) bounds.width(), bounds.height())); WangFiller wangFiller(mWangSet, + mapDocument()->map()->infinite(), dynamic_cast(mapDocument()->renderer()), mapDocument()->map()->staggerAxis()); diff --git a/src/tiled/wangbrush.cpp b/src/tiled/wangbrush.cpp index 12e4766800..4a9e8cdd98 100644 --- a/src/tiled/wangbrush.cpp +++ b/src/tiled/wangbrush.cpp @@ -365,9 +365,6 @@ void WangBrush::captureHoverColor() QPoint mousePoint = mPaintPoint - tileLayer->position(); - if (!tileLayer->contains(mousePoint)) - return; - const Cell &cell = tileLayer->cellAt(mousePoint); if (WangId wangId = mWangSet->wangIdOfCell(cell)) { @@ -511,7 +508,7 @@ void WangBrush::updateBrush() adjacentPositions[i] = mPaintPoint + aroundTilePoints[i]; } - if (currentLayer->contains(mPaintPoint)) { + if (mapDocument()->map()->infinite() || currentLayer->contains(mPaintPoint)) { WangId centerWangId = mWangSet->wangIdOfCell(currentLayer->cellAt(mPaintPoint)); for (int i = 0; i < 4; ++i) { @@ -544,7 +541,7 @@ void WangBrush::updateBrush() continue; QPoint p = adjacentPositions[i]; - if (!currentLayer->contains(p) || currentLayer->cellAt(p).isEmpty()) + if (currentLayer->cellAt(p).isEmpty()) continue; WangId wangId = mWangSet->wangIdOfCell(currentLayer->cellAt(p)); @@ -622,7 +619,7 @@ void WangBrush::updateBrush() for (int i = 0; i < 4; ++i) { QPoint p = adjacentPoints[i]; - if (!currentLayer->contains(p) || currentLayer->cellAt(p).isEmpty()) + if (currentLayer->cellAt(p).isEmpty()) continue; WangId wangId = mWangSet->wangIdOfCell(currentLayer->cellAt(p)); @@ -681,44 +678,36 @@ void WangBrush::updateBrush() dirPoint = mPaintPoint + aroundTilePoints[mEdgeDir*2]; } - if (currentLayer->contains(mPaintPoint)) { - WangId wangId = mWangSet->wangIdOfCell(currentLayer->cellAt(mPaintPoint)); - - if (wangId && !currentLayer->cellAt(mPaintPoint).isEmpty()) { - wangId.setEdgeColor(mEdgeDir, mCurrentColor); + if (WangId wangId = mWangSet->wangIdOfCell(currentLayer->cellAt(mPaintPoint))) { + wangId.setEdgeColor(mEdgeDir, mCurrentColor); - const Cell &cell = mWangSet->findMatchingWangTile(wangId).makeCell(); - - if (cell.isEmpty()) { - QRegion r = QRect(mPaintPoint, QSize(1, 1)); - r += QRect(dirPoint, QSize(1, 1)); - static_cast(brushItem())->setInvalidTiles(r); - return; - } + const Cell &cell = mWangSet->findMatchingWangTile(wangId).makeCell(); - QPoint p = mPaintPoint - stamp->position(); - stamp->setCell(p.x(), p.y(), cell); + if (cell.isEmpty()) { + QRegion r = QRect(mPaintPoint, QSize(1, 1)); + r += QRect(dirPoint, QSize(1, 1)); + static_cast(brushItem())->setInvalidTiles(r); + return; } - } - if (currentLayer->contains(dirPoint)) { - WangId wangId = mWangSet->wangIdOfCell(currentLayer->cellAt(dirPoint)); - - if (wangId && !currentLayer->cellAt(dirPoint).isEmpty()) { - wangId.setEdgeColor((mEdgeDir + 2) % 4, mCurrentColor); + QPoint p = mPaintPoint - stamp->position(); + stamp->setCell(p.x(), p.y(), cell); + } - const Cell &cell = mWangSet->findMatchingWangTile(wangId).makeCell(); + if (WangId wangId = mWangSet->wangIdOfCell(currentLayer->cellAt(dirPoint))) { + wangId.setEdgeColor((mEdgeDir + 2) % 4, mCurrentColor); - if (cell.isEmpty()) { - QRegion r = QRect(mPaintPoint, QSize(1, 1)); - r += QRect(dirPoint, QSize(1, 1)); - static_cast(brushItem())->setInvalidTiles(r); - return; - } + const Cell &cell = mWangSet->findMatchingWangTile(wangId).makeCell(); - dirPoint -= stamp->position(); - stamp->setCell(dirPoint.x(), dirPoint.y(), cell); + if (cell.isEmpty()) { + QRegion r = QRect(mPaintPoint, QSize(1, 1)); + r += QRect(dirPoint, QSize(1, 1)); + static_cast(brushItem())->setInvalidTiles(r); + return; } + + dirPoint -= stamp->position(); + stamp->setCell(dirPoint.x(), dirPoint.y(), cell); } } } diff --git a/src/tiled/wangfiller.cpp b/src/tiled/wangfiller.cpp index f29eccf873..dde5545931 100644 --- a/src/tiled/wangfiller.cpp +++ b/src/tiled/wangfiller.cpp @@ -40,9 +40,11 @@ static const QPoint aroundTilePoints[] = { }; WangFiller::WangFiller(WangSet *wangSet, + bool isInfinite, StaggeredRenderer *staggeredRenderer, Map::StaggerAxis staggerAxis) : mWangSet(wangSet) + , mIsInfinite(isInfinite) , mStaggeredRenderer(staggeredRenderer) , mStaggerAxis(staggerAxis) { @@ -248,14 +250,10 @@ const Cell &WangFiller::getCell(const TileLayer &back, const QRegion &fillRegion, QPoint point) const { - if (!fillRegion.contains(point) && back.contains(point)) { + if (!fillRegion.contains(point)) return back.cellAt(point); - } else if (front.contains(point.x() - front.x(), point.y() - front.y())) { + else return front.cellAt(point.x() - front.x(), point.y() - front.y()); - } else { - static const Cell cell; - return cell; - } } @@ -285,7 +283,7 @@ WangId WangFiller::wangIdFromSurroundings(const TileLayer &back, getSurroundingPoints(point, mStaggeredRenderer, mStaggerAxis, adjacentPoints); for (int i = 0; i < 8; ++i) { - if (!fillRegion.contains(adjacentPoints[i]) && back.contains(adjacentPoints[i])) + if (!fillRegion.contains(adjacentPoints[i])) surroundingCells[i] = back.cellAt(adjacentPoints[i]); } diff --git a/src/tiled/wangfiller.h b/src/tiled/wangfiller.h index e8c6d9b575..5d17e80b01 100644 --- a/src/tiled/wangfiller.h +++ b/src/tiled/wangfiller.h @@ -42,7 +42,8 @@ namespace Internal { class WangFiller { public: - explicit WangFiller(WangSet *wangSet = nullptr, + explicit WangFiller(WangSet *wangSet, + bool isInfinite, //the map we are filling to is infinite. StaggeredRenderer *staggeredRenderer = nullptr, Map::StaggerAxis staggerAxis = Map::StaggerX); @@ -91,6 +92,7 @@ class WangFiller QPoint point) const; WangSet *mWangSet; + bool mIsInfinite; StaggeredRenderer *mStaggeredRenderer; Map::StaggerAxis mStaggerAxis; }; diff --git a/tests/staggeredrenderer/test_staggeredrenderer.cpp b/tests/staggeredrenderer/test_staggeredrenderer.cpp index ef37ecca2a..3b80653d27 100644 --- a/tests/staggeredrenderer/test_staggeredrenderer.cpp +++ b/tests/staggeredrenderer/test_staggeredrenderer.cpp @@ -102,8 +102,10 @@ void test_StaggeredRenderer::screenToTileCoords() QFETCH(QPointF, tileCoords); StaggeredRenderer renderer(mMap); - QCOMPARE(renderer.screenToTileCoords(screenCoords).toPoint(), QPoint(qFloor(tileCoords.x()), - qFloor(tileCoords.y()))); + + QPointF point = renderer.screenToTileCoords(screenCoords); + + QCOMPARE(QPoint(qFloor(point.x()), qFloor(point.y())), tileCoords.toPoint()); } void test_StaggeredRenderer::tileToScreenCoords_data()