From d7f25f9ae5ac4db04e3275cd4a4bed2ceb3fc821 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 26 Jan 2024 15:55:29 -0500 Subject: [PATCH] More selection image fixes --- src/mainwindow.cpp | 15 ++++++++++----- src/ui/tileseteditor.cpp | 12 +++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 33f11d54..6f9e10b3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -734,10 +734,10 @@ void MainWindow::refreshMapScene() ui->graphicsView_Metatiles->setFixedSize(editor->metatile_selector_item->pixmap().width() + 2, editor->metatile_selector_item->pixmap().height() + 2); ui->graphicsView_BorderMetatile->setScene(editor->scene_selected_border_metatiles); - ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width(), editor->selected_border_metatiles_item->pixmap().height()); + ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width() + 2, editor->selected_border_metatiles_item->pixmap().height() + 2); ui->graphicsView_currentMetatileSelection->setScene(editor->scene_current_metatile_selection); - ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width(), editor->current_metatile_selection_item->pixmap().height()); + ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() + 2, editor->current_metatile_selection_item->pixmap().height() + 2); ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles); //ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect()); @@ -1371,12 +1371,16 @@ double MainWindow::getMetatilesZoomScale() { } void MainWindow::redrawMetatileSelection() { + QSize size(editor->current_metatile_selection_item->pixmap().width(), editor->current_metatile_selection_item->pixmap().height()); + ui->graphicsView_currentMetatileSelection->setSceneRect(0, 0, size.width(), size.height()); + auto scale = getMetatilesZoomScale(); QTransform transform; transform.scale(scale, scale); + size *= scale; ui->graphicsView_currentMetatileSelection->setTransform(transform); - ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() * scale, editor->current_metatile_selection_item->pixmap().height() * scale); + ui->graphicsView_currentMetatileSelection->setFixedSize(size.width() + 2, size.height() + 2); ui->scrollAreaWidgetContents_SelectedMetatiles->adjustSize(); } @@ -1394,6 +1398,7 @@ void MainWindow::scrollMetatileSelectorToSelection() { pos += QPoint(size.x() - 1, size.y() - 1) * 16 / 2; // We want to focus on the center of the whole selection pos *= getMetatilesZoomScale(); + // TODO: This snaps focus to the position if it's out of view. It should scroll slowly toward this target instead auto viewport = ui->scrollArea_MetatileSelector->viewport(); ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } @@ -2845,8 +2850,8 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) { ui->graphicsView_Metatiles->setFixedSize(size.width() + 2, size.height() + 2); ui->graphicsView_BorderMetatile->setTransform(transform); - ui->graphicsView_BorderMetatile->setFixedSize(ceil(static_cast(editor->selected_border_metatiles_item->pixmap().width()) * scale), - ceil(static_cast(editor->selected_border_metatiles_item->pixmap().height()) * scale)); + ui->graphicsView_BorderMetatile->setFixedSize(ceil(static_cast(editor->selected_border_metatiles_item->pixmap().width()) * scale) + 2, + ceil(static_cast(editor->selected_border_metatiles_item->pixmap().height()) * scale) + 2); ui->scrollAreaWidgetContents_MetatileSelector->adjustSize(); ui->scrollAreaWidgetContents_BorderMetatiles->adjustSize(); diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index ff79066b..4813790a 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -317,7 +317,6 @@ void TilesetEditor::refresh() { this->tileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); this->metatileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); this->metatileSelector->select(this->getSelectedMetatileId()); - this->drawSelectedTiles(); if (metatileSelector) { if (metatileSelector->selectorShowUnused || metatileSelector->selectorShowCounts) { @@ -333,11 +332,9 @@ void TilesetEditor::refresh() { } } - this->ui->graphicsView_Tiles->setSceneRect(0, 0, this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); - this->ui->graphicsView_Metatiles->setSceneRect(0, 0, this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); - this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); this->redrawTileSelector(); this->redrawMetatileSelector(); + this->drawSelectedTiles(); } void TilesetEditor::drawSelectedTiles() { @@ -363,7 +360,10 @@ void TilesetEditor::drawSelectedTiles() { this->selectedTilePixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(selectionImage)); this->selectedTileScene->addItem(this->selectedTilePixmapItem); - this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); + + QSize size(this->selectedTilePixmapItem->pixmap().width(), this->selectedTilePixmapItem->pixmap().height()); + this->ui->graphicsView_selectedTile->setSceneRect(0, 0, size.width(), size.height()); + this->ui->graphicsView_selectedTile->setFixedSize(size.width() + 2, size.height() + 2); } void TilesetEditor::onHoveredMetatileChanged(uint16_t metatileId) { @@ -1193,6 +1193,7 @@ void TilesetEditor::on_horizontalSlider_MetatilesZoom_valueChanged(int value) { void TilesetEditor::redrawMetatileSelector() { QSize size(this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); + this->ui->graphicsView_Metatiles->setSceneRect(0, 0, size.width(), size.height()); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorMetatilesZoom() - 30) / 30.0); QTransform transform; @@ -1217,6 +1218,7 @@ void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { void TilesetEditor::redrawTileSelector() { QSize size(this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); + this->ui->graphicsView_Tiles->setSceneRect(0, 0, size.width(), size.height()); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorTilesZoom() - 30) / 30.0); QTransform transform;