Scroll to selected tile and metatile

This commit is contained in:
Diegoisawesome 2018-10-08 14:42:51 -05:00
parent 2d3a10fdd8
commit c102a2b7d0
7 changed files with 47 additions and 15 deletions

View file

@ -26,7 +26,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>386</width> <width>386</width>
<height>539</height> <height>538</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
@ -205,14 +205,14 @@
<widget class="QGraphicsView" name="graphicsView_selectedTile"> <widget class="QGraphicsView" name="graphicsView_selectedTile">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>16</width> <width>18</width>
<height>16</height> <height>18</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>32</width> <width>34</width>
<height>32</height> <height>34</height>
</size> </size>
</property> </property>
<property name="frameShape"> <property name="frameShape">
@ -252,14 +252,14 @@
<widget class="QGraphicsView" name="graphicsView_metatileLayers"> <widget class="QGraphicsView" name="graphicsView_metatileLayers">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>64</width> <width>66</width>
<height>32</height> <height>34</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>64</width> <width>66</width>
<height>32</height> <height>34</height>
</size> </size>
</property> </property>
<property name="verticalScrollBarPolicy"> <property name="verticalScrollBarPolicy">
@ -307,7 +307,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>386</width> <width>386</width>
<height>359</height> <height>344</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
@ -388,7 +388,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>21</height> <height>20</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">

View file

@ -22,6 +22,7 @@ public:
void setTilesets(Tileset*, Tileset*); void setTilesets(Tileset*, Tileset*);
QList<uint16_t>* getSelectedMetatiles(); QList<uint16_t>* getSelectedMetatiles();
void setExternalSelection(int, int, QList<uint16_t>*); void setExternalSelection(int, int, QList<uint16_t>*);
QPoint getMetatileIdCoordsOnWidget(uint16_t);
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent*); void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*); void mouseMoveEvent(QGraphicsSceneMouseEvent*);

View file

@ -24,6 +24,7 @@ public:
void setTileFlips(bool, bool); void setTileFlips(bool, bool);
QList<Tile> getSelectedTiles(); QList<Tile> getSelectedTiles();
void setExternalSelection(int, int, QList<Tile>); void setExternalSelection(int, int, QList<Tile>);
QPoint getTileCoordsOnWidget(uint16_t);
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent*); void mousePressEvent(QGraphicsSceneMouseEvent*);

View file

@ -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->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()); 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) void MainWindow::on_mapList_activated(const QModelIndex &index)

View file

@ -145,3 +145,10 @@ QPoint MetatileSelector::getMetatileIdCoords(uint16_t metatileId) {
: metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles->length(); : metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles->length();
return QPoint(index % this->numMetatilesWide, index / this->numMetatilesWide); 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;
}

View file

@ -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_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->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_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() void TilesetEditor::initMetatileSelector()
@ -119,7 +119,7 @@ void TilesetEditor::initSelectedTileItem() {
this->selectedTileScene = new QGraphicsScene; this->selectedTileScene = new QGraphicsScene;
this->drawSelectedTiles(); this->drawSelectedTiles();
this->ui->graphicsView_selectedTile->setScene(this->selectedTileScene); 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() { void TilesetEditor::drawSelectedTiles() {
@ -145,7 +145,7 @@ void TilesetEditor::drawSelectedTiles() {
this->selectedTilePixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(selectionImage)); this->selectedTilePixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(selectionImage));
this->selectedTileScene->addItem(this->selectedTilePixmapItem); 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() { 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(); this->metatileLayersItem->clearLastModifiedCoords();
} }

View file

@ -162,3 +162,10 @@ QPoint TilesetEditorTileSelector::getTileCoords(uint16_t tile) {
return QPoint(tile % this->numTilesWide, tile / this->numTilesWide); 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;
}