Skip to content

Commit

Permalink
Trying to display correctly shifted backgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re committed Jan 16, 2024
1 parent 96f1c9f commit 6eb6297
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/core/field/BackgroundTiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 7 additions & 5 deletions src/widgets/BackgroundEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<quint16> &effectTileIds)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<QLine> axis;
axis.append(QLine(0, gridSize.height() / 2, gridSize.width(), gridSize.height() / 2)); // x
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/BackgroundEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private slots:
void refreshList(int layer);
void refreshImage(int layer, int section, ParamState paramState, const QList<quint16> &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;
Expand Down

0 comments on commit 6eb6297

Please sign in to comment.