Center selection when zooming
This commit is contained in:
parent
4cb7e8a9aa
commit
895c9466d7
5 changed files with 45 additions and 22 deletions
|
@ -390,7 +390,9 @@ private:
|
||||||
void openProjectSettingsEditor(int tab);
|
void openProjectSettingsEditor(int tab);
|
||||||
bool isProjectOpen();
|
bool isProjectOpen();
|
||||||
void showExportMapImageWindow(ImageExporterMode mode);
|
void showExportMapImageWindow(ImageExporterMode mode);
|
||||||
|
double getMetatilesZoomScale();
|
||||||
void redrawMetatileSelection();
|
void redrawMetatileSelection();
|
||||||
|
void scrollMetatileSelectorToSelection();
|
||||||
|
|
||||||
QObjectList shortcutableObjects() const;
|
QObjectList shortcutableObjects() const;
|
||||||
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
|
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
|
||||||
|
|
|
@ -45,13 +45,14 @@ public:
|
||||||
QPoint getSelectionDimensions();
|
QPoint getSelectionDimensions();
|
||||||
void draw();
|
void draw();
|
||||||
bool select(uint16_t metatile);
|
bool select(uint16_t metatile);
|
||||||
bool selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation);
|
void selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation);
|
||||||
void setTilesets(Tileset*, Tileset*);
|
void setTilesets(Tileset*, Tileset*);
|
||||||
MetatileSelection getMetatileSelection();
|
MetatileSelection getMetatileSelection();
|
||||||
void setPrefabSelection(MetatileSelection selection);
|
void setPrefabSelection(MetatileSelection selection);
|
||||||
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
|
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
|
||||||
QPoint getMetatileIdCoordsOnWidget(uint16_t);
|
QPoint getMetatileIdCoordsOnWidget(uint16_t);
|
||||||
void setMap(Map*);
|
void setMap(Map*);
|
||||||
|
bool isInternalSelection() const { return (!this->externalSelection && !this->prefabSelection); }
|
||||||
Tileset *primaryTileset;
|
Tileset *primaryTileset;
|
||||||
Tileset *secondaryTileset;
|
Tileset *secondaryTileset;
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1366,32 +1366,48 @@ void MainWindow::updateTilesetEditor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::redrawMetatileSelection()
|
double MainWindow::getMetatilesZoomScale() {
|
||||||
{
|
return pow(3.0, static_cast<double>(porymapConfig.getMetatilesZoom() - 30) / 30.0);
|
||||||
double scale = pow(3.0, static_cast<double>(porymapConfig.getMetatilesZoom() - 30) / 30.0);
|
}
|
||||||
|
|
||||||
|
void MainWindow::redrawMetatileSelection() {
|
||||||
|
auto scale = getMetatilesZoomScale();
|
||||||
QTransform transform;
|
QTransform transform;
|
||||||
transform.scale(scale, scale);
|
transform.scale(scale, scale);
|
||||||
|
|
||||||
ui->graphicsView_currentMetatileSelection->setTransform(transform);
|
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(editor->current_metatile_selection_item->pixmap().width() * scale, editor->current_metatile_selection_item->pixmap().height() * scale);
|
||||||
ui->scrollAreaWidgetContents_SelectedMetatiles->adjustSize();
|
ui->scrollAreaWidgetContents_SelectedMetatiles->adjustSize();
|
||||||
|
|
||||||
QPoint size = editor->metatile_selector_item->getSelectionDimensions();
|
|
||||||
if (size.x() == 1 && size.y() == 1) {
|
|
||||||
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
|
|
||||||
QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId);
|
|
||||||
pos *= scale;
|
|
||||||
ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::currentMetatilesSelectionChanged()
|
void MainWindow::scrollMetatileSelectorToSelection() {
|
||||||
{
|
// Internal selections or 1x1 external selections can be scrolled to
|
||||||
|
if (!editor->metatile_selector_item->isInternalSelection() && editor->metatile_selector_item->getSelectionDimensions() != QPoint(1, 1))
|
||||||
|
return;
|
||||||
|
|
||||||
|
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
|
||||||
|
if (selection.metatileItems.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId);
|
||||||
|
QPoint size = editor->metatile_selector_item->getSelectionDimensions();
|
||||||
|
pos += QPoint(size.x() - 1, size.y() - 1) * 16 / 2; // We want to focus on the center of the whole selection
|
||||||
|
pos *= getMetatilesZoomScale();
|
||||||
|
|
||||||
|
auto viewport = ui->scrollArea_MetatileSelector->viewport();
|
||||||
|
ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::currentMetatilesSelectionChanged() {
|
||||||
redrawMetatileSelection();
|
redrawMetatileSelection();
|
||||||
if (this->tilesetEditor) {
|
if (this->tilesetEditor) {
|
||||||
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
|
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
|
||||||
this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId);
|
this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't scroll to internal selections here, it will disrupt the user while they make their selection.
|
||||||
|
if (!editor->metatile_selector_item->isInternalSelection())
|
||||||
|
scrollMetatileSelectorToSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||||
|
@ -2836,6 +2852,7 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) {
|
||||||
ui->scrollAreaWidgetContents_BorderMetatiles->adjustSize();
|
ui->scrollAreaWidgetContents_BorderMetatiles->adjustSize();
|
||||||
|
|
||||||
redrawMetatileSelection();
|
redrawMetatileSelection();
|
||||||
|
scrollMetatileSelectorToSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) {
|
void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) {
|
||||||
|
|
|
@ -59,12 +59,9 @@ bool MetatileSelector::select(uint16_t metatileId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) {
|
void MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) {
|
||||||
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
|
QPair<uint16_t, uint16_t> movePermissions(collision, elevation);
|
||||||
this->select(metatileId);
|
this->setExternalSelection(1, 1, {metatileId}, {movePermissions});
|
||||||
this->selection.collisionItems.append(CollisionSelectionItem{true, collision, elevation});
|
|
||||||
this->selection.hasCollision = true;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatileSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
void MetatileSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
|
@ -100,6 +97,10 @@ void MetatileSelector::setExternalSelection(int width, int height, QList<uint16_
|
||||||
metatileId = 0;
|
metatileId = 0;
|
||||||
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
|
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
|
||||||
}
|
}
|
||||||
|
if (this->selection.metatileItems.length() == 1) {
|
||||||
|
QPoint coords = this->getMetatileIdCoords(this->selection.metatileItems.first().metatileId);
|
||||||
|
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
this->draw();
|
this->draw();
|
||||||
emit selectedMetatilesChanged();
|
emit selectedMetatilesChanged();
|
||||||
|
|
|
@ -1206,7 +1206,8 @@ void TilesetEditor::redrawMetatileSelector() {
|
||||||
pos *= scale;
|
pos *= scale;
|
||||||
|
|
||||||
this->ui->scrollAreaWidgetContents_Metatiles->adjustSize();
|
this->ui->scrollAreaWidgetContents_Metatiles->adjustSize();
|
||||||
this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale);
|
auto viewport = this->ui->scrollArea_Metatiles->viewport();
|
||||||
|
this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) {
|
void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) {
|
||||||
|
@ -1231,6 +1232,7 @@ void TilesetEditor::redrawTileSelector() {
|
||||||
if (!tiles.isEmpty()) {
|
if (!tiles.isEmpty()) {
|
||||||
QPoint pos = this->tileSelector->getTileCoordsOnWidget(tiles[0].tileId);
|
QPoint pos = this->tileSelector->getTileCoordsOnWidget(tiles[0].tileId);
|
||||||
pos *= scale;
|
pos *= scale;
|
||||||
this->ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale);
|
auto viewport = this->ui->scrollArea_Tiles->viewport();
|
||||||
|
this->ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue