Simplify TilesetEditorMetatileSelector::buildImage

This commit is contained in:
GriffinR 2022-10-05 10:53:22 -04:00 committed by Marcus Huderle
parent 56e24bba18
commit 564d24c4f3
2 changed files with 8 additions and 10 deletions

View file

@ -43,7 +43,7 @@ private:
void drawUnused();
void drawCounts();
QImage buildAllMetatilesImage();
QImage buildImage(int metatileIdStart, int metatileIdEnd);
QImage buildImage(int metatileIdStart, int numMetatiles);
signals:
void hoveredMetatileChanged(uint16_t);

View file

@ -13,29 +13,27 @@ TilesetEditorMetatileSelector::TilesetEditorMetatileSelector(Tileset *primaryTil
}
QImage TilesetEditorMetatileSelector::buildAllMetatilesImage() {
return this->buildImage(0, Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles.length() - 1);
return this->buildImage(0, Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles.length());
}
QImage TilesetEditorMetatileSelector::buildPrimaryMetatilesImage() {
return this->buildImage(0, this->primaryTileset->metatiles.length() - 1);
return this->buildImage(0, this->primaryTileset->metatiles.length());
}
QImage TilesetEditorMetatileSelector::buildSecondaryMetatilesImage() {
int numPrimary = Project::getNumMetatilesPrimary();
return this->buildImage(numPrimary, numPrimary + this->secondaryTileset->metatiles.length() - 1);
return this->buildImage(Project::getNumMetatilesPrimary(), this->secondaryTileset->metatiles.length());
}
QImage TilesetEditorMetatileSelector::buildImage(int metatileIdStart, int metatileIdEnd) {
int totalMetatiles = metatileIdEnd - metatileIdStart + 1;
int numMetatilesHigh = totalMetatiles / this->numMetatilesWide;
if (totalMetatiles % this->numMetatilesWide != 0) {
QImage TilesetEditorMetatileSelector::buildImage(int metatileIdStart, int numMetatiles) {
int numMetatilesHigh = numMetatiles / this->numMetatilesWide;
if (numMetatiles % this->numMetatilesWide != 0) {
// Round up height for incomplete last row
numMetatilesHigh++;
}
QImage image(this->numMetatilesWide * 32, numMetatilesHigh * 32, QImage::Format_RGBA8888);
image.fill(Qt::magenta);
QPainter painter(&image);
for (int i = 0; i < totalMetatiles; i++) {
for (int i = 0; i < numMetatiles; i++) {
QImage metatile_image = getMetatileImage(
i + metatileIdStart,
this->primaryTileset,