fix map zoom bug, move scale to project
This commit is contained in:
parent
dfce28d5ff
commit
d7641b4e9f
5 changed files with 43 additions and 13 deletions
|
@ -19,7 +19,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QScroller>
|
#include <QScroller>
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
@ -168,6 +168,7 @@ void MainWindow::setMap(QString map_name) {
|
||||||
}
|
}
|
||||||
editor->setMap(map_name);
|
editor->setMap(map_name);
|
||||||
redrawMapScene();
|
redrawMapScene();
|
||||||
|
scaleMapView(0);
|
||||||
displayMapProperties();
|
displayMapProperties();
|
||||||
|
|
||||||
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - porymap");
|
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - porymap");
|
||||||
|
@ -655,19 +656,46 @@ void MainWindow::on_actionMap_Shift_triggered()
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::scaleMapView(int s) {
|
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);
|
double sfactor = pow(base,s);
|
||||||
|
|
||||||
ui->graphicsView_Map->scale(sfactor,sfactor);
|
ui->graphicsView_Map->scale(sfactor,sfactor);
|
||||||
ui->graphicsView_Objects_Map->scale(sfactor,sfactor);
|
ui->graphicsView_Objects_Map->scale(sfactor,sfactor);
|
||||||
|
|
||||||
int width = static_cast<int>((editor->scene->width() + 2) * pow(base,exp));
|
auto newWidth = floor((editor->scene->width() + 8) * pow(base,exp) + 2);
|
||||||
int height = static_cast<int>((editor->scene->height() + 2) * pow(base,exp));
|
auto newHeight = floor((editor->scene->height() + 8) * pow(base,exp) + 2);
|
||||||
ui->graphicsView_Map->setFixedSize(width, height);
|
|
||||||
ui->graphicsView_Objects_Map->setFixedSize(width, height);
|
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)
|
void MainWindow::addNewEvent(QString event_type)
|
||||||
|
|
|
@ -145,6 +145,7 @@ private:
|
||||||
void checkToolButtons();
|
void checkToolButtons();
|
||||||
|
|
||||||
void scaleMapView(int);
|
void scaleMapView(int);
|
||||||
|
void resetMapScale(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MapListUserRoles {
|
enum MapListUserRoles {
|
||||||
|
|
5
map.cpp
5
map.cpp
|
@ -524,11 +524,10 @@ bool Map::hasUnsavedChanges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::hoveredTileChanged(int x, int y, int block) {
|
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(x)
|
||||||
.arg(y)
|
.arg(y)
|
||||||
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())
|
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
|
||||||
.arg(QString::number(pow(this->scale_base,this->scale_exp))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::clearHoveredTile() {
|
void Map::clearHoveredTile() {
|
||||||
|
|
2
map.h
2
map.h
|
@ -141,8 +141,6 @@ public:
|
||||||
QString show_location;
|
QString show_location;
|
||||||
QString battle_scene;
|
QString battle_scene;
|
||||||
MapLayout *layout;
|
MapLayout *layout;
|
||||||
int scale_exp = 0;
|
|
||||||
double scale_base = sqrt(2); // adjust scale factor with this
|
|
||||||
|
|
||||||
bool isPersistedToFile = true;
|
bool isPersistedToFile = true;
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,10 @@ public:
|
||||||
QStringList readCArray(QString text, QString label);
|
QStringList readCArray(QString text, QString label);
|
||||||
QString readCIncbin(QString text, QString label);
|
QString readCIncbin(QString text, QString label);
|
||||||
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
||||||
|
|
||||||
|
int scale_exp = 0;
|
||||||
|
double scale_base = sqrt(2); // adjust scale factor with this
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getMapLayoutsTableFilepath();
|
QString getMapLayoutsTableFilepath();
|
||||||
QString getMapLayoutFilepath(QString);
|
QString getMapLayoutFilepath(QString);
|
||||||
|
|
Loading…
Reference in a new issue