Use more sensible zoom levels, which eliminates zoom rendering artifacts

This commit is contained in:
Marcus Huderle 2021-02-09 17:28:02 -06:00 committed by huderlem
parent a7f12f1993
commit b35e1d9af9
2 changed files with 33 additions and 14 deletions

View file

@ -135,8 +135,7 @@ public:
QString map_edit_mode = "paint"; QString map_edit_mode = "paint";
QString obj_edit_mode = "select"; QString obj_edit_mode = "select";
int scale_exp = 0; int scaleIndex = 2;
double scale_base = sqrt(2); // adjust scale factor with this
qreal collisionOpacity = 0.5; qreal collisionOpacity = 0.5;
void objectsView_onMousePress(QMouseEvent *event); void objectsView_onMousePress(QMouseEvent *event);

View file

@ -940,17 +940,37 @@ void Editor::onWheelZoom(int s) {
} }
} }
void Editor::scaleMapView(int s) { const QList<double> zoomLevels = QList<double>
if ((scale_exp + s) <= 5 && (scale_exp + s) >= -2) // sane limits {
{ 0.5,
if (s == 0) 0.75,
s = -scale_exp; 1.0,
scale_exp += s; 1.5,
2.0,
3.0,
4.0,
6.0,
};
double sfactor = pow(scale_base, s); void Editor::scaleMapView(int s) {
ui->graphicsView_Map->scale(sfactor, sfactor); // Clamp the scale index to a valid value.
ui->graphicsView_Connections->scale(sfactor, sfactor); int nextScaleIndex = this->scaleIndex + s;
} if (nextScaleIndex < 0)
nextScaleIndex = 0;
if (nextScaleIndex >= zoomLevels.size())
nextScaleIndex = zoomLevels.size() - 1;
// Early exit if the scale index hasn't changed.
if (nextScaleIndex == this->scaleIndex)
return;
// Set the graphics views' scale transformation based
// on the new scale amount.
this->scaleIndex = nextScaleIndex;
double scaleFactor = zoomLevels[nextScaleIndex];
QTransform transform = QTransform::fromScale(scaleFactor, scaleFactor);
ui->graphicsView_Map->setTransform(transform);
ui->graphicsView_Connections->setTransform(transform);
} }
void Editor::onHoveredMapMetatileChanged(const QPoint &pos) { void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
@ -964,13 +984,13 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
.arg(pos.x()) .arg(pos.x())
.arg(pos.y()) .arg(pos.y())
.arg(getMetatileDisplayMessage(metatileId)) .arg(getMetatileDisplayMessage(metatileId))
.arg(QString::number(pow(scale_base, scale_exp), 'g', 2))); .arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
} else if (map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects } else if (map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects
&& pos.x() >= 0 && pos.x() < map->getWidth() && pos.y() >= 0 && pos.y() < map->getHeight()) { && pos.x() >= 0 && pos.x() < map->getWidth() && pos.y() >= 0 && pos.y() < map->getHeight()) {
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Scale = %3x") this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Scale = %3x")
.arg(pos.x()) .arg(pos.x())
.arg(pos.y()) .arg(pos.y())
.arg(QString::number(pow(scale_base, scale_exp), 'g', 2))); .arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
} }
} }