Scroll to selected tile and metatile
This commit is contained in:
parent
2d3a10fdd8
commit
c102a2b7d0
7 changed files with 47 additions and 15 deletions
|
@ -26,7 +26,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>386</width>
|
||||
<height>539</height>
|
||||
<height>538</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
|
@ -205,14 +205,14 @@
|
|||
<widget class="QGraphicsView" name="graphicsView_selectedTile">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
<width>18</width>
|
||||
<height>18</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
<width>34</width>
|
||||
<height>34</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
|
@ -252,14 +252,14 @@
|
|||
<widget class="QGraphicsView" name="graphicsView_metatileLayers">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>32</height>
|
||||
<width>66</width>
|
||||
<height>34</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>32</height>
|
||||
<width>66</width>
|
||||
<height>34</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
|
@ -307,7 +307,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>386</width>
|
||||
<height>359</height>
|
||||
<height>344</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
|
@ -388,7 +388,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>21</height>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
void setTilesets(Tileset*, Tileset*);
|
||||
QList<uint16_t>* getSelectedMetatiles();
|
||||
void setExternalSelection(int, int, QList<uint16_t>*);
|
||||
QPoint getMetatileIdCoordsOnWidget(uint16_t);
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
void setTileFlips(bool, bool);
|
||||
QList<Tile> getSelectedTiles();
|
||||
void setExternalSelection(int, int, QList<Tile>);
|
||||
QPoint getTileCoordsOnWidget(uint16_t);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
|
|
|
@ -683,6 +683,12 @@ void MainWindow::currentMetatilesSelectionChanged()
|
|||
{
|
||||
ui->graphicsView_currentMetatileSelection->setFixedSize(editor->scene_current_metatile_selection_item->pixmap().width() + 2, editor->scene_current_metatile_selection_item->pixmap().height() + 2);
|
||||
ui->graphicsView_currentMetatileSelection->setSceneRect(0, 0, editor->scene_current_metatile_selection_item->pixmap().width(), editor->scene_current_metatile_selection_item->pixmap().height());
|
||||
|
||||
QPoint size = editor->metatile_selector_item->getSelectionDimensions();
|
||||
if (size.x() == 1 && size.y() == 1) {
|
||||
QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(editor->metatile_selector_item->getSelectedMetatiles()->at(0));
|
||||
ui->scrollArea_2->ensureVisible(pos.x(), pos.y());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||
|
|
|
@ -145,3 +145,10 @@ QPoint MetatileSelector::getMetatileIdCoords(uint16_t metatileId) {
|
|||
: metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles->length();
|
||||
return QPoint(index % this->numMetatilesWide, index / this->numMetatilesWide);
|
||||
}
|
||||
|
||||
QPoint MetatileSelector::getMetatileIdCoordsOnWidget(uint16_t metatileId) {
|
||||
QPoint pos = getMetatileIdCoords(metatileId);
|
||||
pos.rx() = (pos.x() * this->cellWidth) + (this->cellWidth / 2);
|
||||
pos.ry() = (pos.y() * this->cellHeight) + (this->cellHeight / 2);
|
||||
return pos;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ void TilesetEditor::refresh() {
|
|||
this->ui->graphicsView_Tiles->setFixedSize(this->tileSelector->pixmap().width() + 2, this->tileSelector->pixmap().height() + 2);
|
||||
this->ui->graphicsView_Metatiles->setSceneRect(0, 0, this->metatileSelector->pixmap().width() + 2, this->metatileSelector->pixmap().height() + 2);
|
||||
this->ui->graphicsView_Metatiles->setFixedSize(this->metatileSelector->pixmap().width() + 2, this->metatileSelector->pixmap().height() + 2);
|
||||
this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width(), this->selectedTilePixmapItem->pixmap().height());
|
||||
this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2);
|
||||
}
|
||||
|
||||
void TilesetEditor::initMetatileSelector()
|
||||
|
@ -119,7 +119,7 @@ void TilesetEditor::initSelectedTileItem() {
|
|||
this->selectedTileScene = new QGraphicsScene;
|
||||
this->drawSelectedTiles();
|
||||
this->ui->graphicsView_selectedTile->setScene(this->selectedTileScene);
|
||||
this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width(), this->selectedTilePixmapItem->pixmap().height());
|
||||
this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2);
|
||||
}
|
||||
|
||||
void TilesetEditor::drawSelectedTiles() {
|
||||
|
@ -145,7 +145,7 @@ void TilesetEditor::drawSelectedTiles() {
|
|||
|
||||
this->selectedTilePixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(selectionImage));
|
||||
this->selectedTileScene->addItem(this->selectedTilePixmapItem);
|
||||
this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width(), this->selectedTilePixmapItem->pixmap().height());
|
||||
this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2);
|
||||
}
|
||||
|
||||
void TilesetEditor::initMetatileLayersItem() {
|
||||
|
@ -234,7 +234,17 @@ void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int
|
|||
}
|
||||
}
|
||||
}
|
||||
this->tileSelector->setExternalSelection(width, height, tiles);
|
||||
|
||||
if (width == 1 && height == 1) {
|
||||
this->tileSelector->select(static_cast<uint16_t>(tiles[0].tile));
|
||||
ui->spinBox_paletteSelector->setValue(tiles[0].palette);
|
||||
QPoint pos = tileSelector->getTileCoordsOnWidget(static_cast<uint16_t>(tiles[0].tile));
|
||||
ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y());
|
||||
}
|
||||
else {
|
||||
this->tileSelector->setExternalSelection(width, height, tiles);
|
||||
}
|
||||
|
||||
this->metatileLayersItem->clearLastModifiedCoords();
|
||||
}
|
||||
|
||||
|
|
|
@ -162,3 +162,10 @@ QPoint TilesetEditorTileSelector::getTileCoords(uint16_t tile) {
|
|||
|
||||
return QPoint(tile % this->numTilesWide, tile / this->numTilesWide);
|
||||
}
|
||||
|
||||
QPoint TilesetEditorTileSelector::getTileCoordsOnWidget(uint16_t tile) {
|
||||
QPoint pos = getTileCoords(tile);
|
||||
pos.rx() = (pos.x() * this->cellWidth) + (this->cellWidth / 2);
|
||||
pos.ry() = (pos.y() * this->cellHeight) + (this->cellHeight / 2);
|
||||
return pos;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue