fix map zoom bug, move scale to project

This commit is contained in:
garak 2018-09-19 23:05:07 -04:00
parent dfce28d5ff
commit d7641b4e9f
5 changed files with 43 additions and 13 deletions

View file

@ -19,7 +19,7 @@
#include <QMessageBox>
#include <QDialogButtonBox>
#include <QScroller>
#include <math.h>
#include <cmath>
#include <QProcess>
#include <QSysInfo>
#include <QDesktopServices>
@ -168,6 +168,7 @@ void MainWindow::setMap(QString map_name) {
}
editor->setMap(map_name);
redrawMapScene();
scaleMapView(0);
displayMapProperties();
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - porymap");
@ -655,19 +656,46 @@ void MainWindow::on_actionMap_Shift_triggered()
}
void MainWindow::scaleMapView(int s) {
editor->map->scale_exp += s;
if (s == 0) { // reset to default scale then scale again
int scaleTo = editor->project->scale_exp;
if (scaleTo != 0) {
resetMapScale(scaleTo);
scaleMapView(scaleTo);
}
return;
}
editor->project->scale_exp += s;
double base = editor->project->scale_base;
double exp = editor->project->scale_exp;
double base = editor->map->scale_base;
double exp = editor->map->scale_exp;
double sfactor = pow(base,s);
ui->graphicsView_Map->scale(sfactor,sfactor);
ui->graphicsView_Objects_Map->scale(sfactor,sfactor);
int width = static_cast<int>((editor->scene->width() + 2) * pow(base,exp));
int height = static_cast<int>((editor->scene->height() + 2) * pow(base,exp));
ui->graphicsView_Map->setFixedSize(width, height);
ui->graphicsView_Objects_Map->setFixedSize(width, height);
auto newWidth = floor((editor->scene->width() + 8) * pow(base,exp) + 2);
auto newHeight = floor((editor->scene->height() + 8) * pow(base,exp) + 2);
ui->graphicsView_Map->setFixedSize(newWidth, newHeight);
ui->graphicsView_Objects_Map->setFixedSize(newWidth, newHeight);
}
void MainWindow::resetMapScale(int mag)
{
// safest way to un-scale map
if (mag > 0) {
for (int i = 0; i < mag; i++) {
scaleMapView(-1);
}
}
else {
mag = -mag;
for (int i = 0; i < mag; i++) {
scaleMapView(1);
}
}
}
void MainWindow::addNewEvent(QString event_type)

View file

@ -145,6 +145,7 @@ private:
void checkToolButtons();
void scaleMapView(int);
void resetMapScale(int);
};
enum MapListUserRoles {

View file

@ -524,11 +524,10 @@ bool Map::hasUnsavedChanges() {
}
void Map::hoveredTileChanged(int x, int y, int block) {
emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3, Scale = %4x")
emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3")
.arg(x)
.arg(y)
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())
.arg(QString::number(pow(this->scale_base,this->scale_exp))));
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
}
void Map::clearHoveredTile() {

2
map.h
View file

@ -141,8 +141,6 @@ public:
QString show_location;
QString battle_scene;
MapLayout *layout;
int scale_exp = 0;
double scale_base = sqrt(2); // adjust scale factor with this
bool isPersistedToFile = true;

View file

@ -114,6 +114,10 @@ public:
QStringList readCArray(QString text, QString label);
QString readCIncbin(QString text, QString label);
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
int scale_exp = 0;
double scale_base = sqrt(2); // adjust scale factor with this
private:
QString getMapLayoutsTableFilepath();
QString getMapLayoutFilepath(QString);