From 6eb62971f881736882877024b99a7c8b40ba39be Mon Sep 17 00:00:00 2001 From: myst6re Date: Tue, 16 Jan 2024 22:53:15 +0100 Subject: [PATCH] Trying to display correctly shifted backgrounds --- src/core/field/BackgroundTiles.cpp | 10 ++++++++-- src/widgets/BackgroundEditor.cpp | 12 +++++++----- src/widgets/BackgroundEditor.h | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/field/BackgroundTiles.cpp b/src/core/field/BackgroundTiles.cpp index c9f93d2e..42496992 100644 --- a/src/core/field/BackgroundTiles.cpp +++ b/src/core/field/BackgroundTiles.cpp @@ -453,12 +453,18 @@ QPoint BackgroundTiles::dstShift(quint8 tileSize) const } if (!shiftXComputed && tile.dstX != 0) { - shiftX = std::abs(tile.dstX) % tile.size; + shiftX = tile.dstX < 0 ? tile.size - (-tile.dstX % tile.size) : tile.dstX % tile.size; + if (shiftX == tile.size) { + shiftX = 0; + } shiftXComputed = true; } if (!shiftYComputed && tile.dstY != 0) { - shiftY = std::abs(tile.dstY) % tile.size; + shiftY = tile.dstY < 0 ? tile.size - (-tile.dstY % tile.size) : tile.dstY % tile.size; + if (shiftY == tile.size) { + shiftY = 0; + } shiftYComputed = true; } diff --git a/src/widgets/BackgroundEditor.cpp b/src/widgets/BackgroundEditor.cpp index 8410ca8b..0ded4e82 100644 --- a/src/widgets/BackgroundEditor.cpp +++ b/src/widgets/BackgroundEditor.cpp @@ -389,14 +389,14 @@ void BackgroundEditor::updateImageLabel(int layer, int section, ParamState param updateSelectedTiles(_backgroundLayerWidget->selectedCells()); } -QPoint BackgroundEditor::backgroundPositionFromTile(const QPoint &tile, quint8 cellSize) +QPoint BackgroundEditor::backgroundPositionFromTile(const QPoint &tile, const QPoint &shift) { - return tile + QPoint(MAX_TILE_DST, MAX_TILE_DST) - QPoint(tile.x() % cellSize, tile.y() % cellSize); + return tile + QPoint(MAX_TILE_DST, MAX_TILE_DST) - shift; } QPoint BackgroundEditor::tilePositionFromCell(const QPoint &cell, quint8 cellSize, const QPoint &shift) { - return cell * cellSize - QPoint(MAX_TILE_DST, MAX_TILE_DST) - shift; + return cell * cellSize - QPoint(MAX_TILE_DST, MAX_TILE_DST) + shift; } void BackgroundEditor::refreshImage(int layer, int section, ParamState paramState, const QList &effectTileIds) @@ -432,7 +432,7 @@ void BackgroundEditor::refreshImage(int layer, int section, ParamState paramStat QPoint shift = layerTiles.dstShift(tileSize); qDebug() << "BackgroundEditor::refreshImage" << "area" << area << shift; - + _shiftX->setMaximum(tileSize - 1); _shiftY->setMaximum(tileSize - 1); _shiftX->setValue(shift.x()); @@ -484,7 +484,9 @@ void BackgroundEditor::refreshImage(int layer, int section, ParamState paramStat QSize gridSize((MAX_TILE_DST - shift.x()) * 2, (MAX_TILE_DST - shift.y()) * 2); _backgroundLayerWidget->setGridSize(gridSize / tileSize); - _backgroundLayerWidget->setPixmap(backgroundPositionFromTile(layerTiles.minTopLeft(), tileSize), pix); + _backgroundLayerWidget->setPixmap(backgroundPositionFromTile(layerTiles.minTopLeft(), shift), pix); + + qDebug() << "gridSize" << gridSize; QList axis; axis.append(QLine(0, gridSize.height() / 2, gridSize.width(), gridSize.height() / 2)); // x diff --git a/src/widgets/BackgroundEditor.h b/src/widgets/BackgroundEditor.h index c095a43d..a5761c2f 100644 --- a/src/widgets/BackgroundEditor.h +++ b/src/widgets/BackgroundEditor.h @@ -57,7 +57,7 @@ private slots: void refreshList(int layer); void refreshImage(int layer, int section, ParamState paramState, const QList &effectTileIds); void refreshTexture(); - static QPoint backgroundPositionFromTile(const QPoint &cell, quint8 cellSize); + static QPoint backgroundPositionFromTile(const QPoint &tile, const QPoint &shift); static QPoint tilePositionFromCell(const QPoint &cell, quint8 cellSize, const QPoint &shift); QSplitter *_topBottomSplitter;