From 2fc906b5ae3996d2754f92731d84d98bfdfbbc15 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 31 Dec 2023 14:06:47 -0500 Subject: [PATCH] Fix tileset editor grid layering --- include/ui/tileseteditormetatileselector.h | 1 + src/ui/tileseteditormetatileselector.cpp | 40 ++++++++++++---------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/include/ui/tileseteditormetatileselector.h b/include/ui/tileseteditormetatileselector.h index 50de1c56..f8b6011d 100644 --- a/include/ui/tileseteditormetatileselector.h +++ b/include/ui/tileseteditormetatileselector.h @@ -42,6 +42,7 @@ private: bool shouldAcceptEvent(QGraphicsSceneMouseEvent*); int numRows(int numMetatiles); int numRows(); + void drawGrid(); void drawFilters(); void drawUnused(); void drawCounts(); diff --git a/src/ui/tileseteditormetatileselector.cpp b/src/ui/tileseteditormetatileselector.cpp index d46edcc3..92d07e3a 100644 --- a/src/ui/tileseteditormetatileselector.cpp +++ b/src/ui/tileseteditormetatileselector.cpp @@ -69,9 +69,9 @@ QImage TilesetEditorMetatileSelector::buildImage(int metatileIdStart, int numMet void TilesetEditorMetatileSelector::draw() { this->setPixmap(QPixmap::fromImage(this->buildAllMetatilesImage())); + this->drawGrid(); this->drawSelection(); - - drawFilters(); + this->drawFilters(); } bool TilesetEditorMetatileSelector::select(uint16_t metatileId) { @@ -166,23 +166,27 @@ QPoint TilesetEditorMetatileSelector::getMetatileIdCoordsOnWidget(uint16_t metat return pos; } -void TilesetEditorMetatileSelector::drawFilters() { - if (this->showGrid) { - QPixmap pixmap = this->pixmap(); - QPainter painter(&pixmap); - const int numColumns = this->numMetatilesWide; - const int numRows = this->numRows(); - for (int column = 1; column < numColumns; column++) { - int x = column * 32; - painter.drawLine(x, 0, x, numRows * 32); - } - for (int row = 1; row < numRows; row++) { - int y = row * 32; - painter.drawLine(0, y, numColumns * 32, y); - } - painter.end(); - this->setPixmap(pixmap); +void TilesetEditorMetatileSelector::drawGrid() { + if (!this->showGrid) + return; + + QPixmap pixmap = this->pixmap(); + QPainter painter(&pixmap); + const int numColumns = this->numMetatilesWide; + const int numRows = this->numRows(); + for (int column = 1; column < numColumns; column++) { + int x = column * 32; + painter.drawLine(x, 0, x, numRows * 32); } + for (int row = 1; row < numRows; row++) { + int y = row * 32; + painter.drawLine(0, y, numColumns * 32, y); + } + painter.end(); + this->setPixmap(pixmap); +} + +void TilesetEditorMetatileSelector::drawFilters() { if (selectorShowUnused) { drawUnused(); }