From da850bc69a58c7336abcbef5704b40c230f977d4 Mon Sep 17 00:00:00 2001 From: AdrianFL Date: Sun, 2 Dec 2018 04:46:48 +0100 Subject: [PATCH 01/15] Added checkbox to Preferences menu and all the methods needed --- src/tiled/preferences.cpp | 12 ++++++++++++ src/tiled/preferences.h | 11 +++++++++++ src/tiled/preferencesdialog.cpp | 3 +++ src/tiled/preferencesdialog.ui | 8 ++++++++ 4 files changed, 34 insertions(+) diff --git a/src/tiled/preferences.cpp b/src/tiled/preferences.cpp index f2270292e3..0f02aca3a7 100644 --- a/src/tiled/preferences.cpp +++ b/src/tiled/preferences.cpp @@ -93,6 +93,7 @@ Preferences::Preferences() mLanguage = stringValue("Language"); mUseOpenGL = boolValue("OpenGL"); mWheelZoomsByDefault = boolValue("WheelZoomsByDefault"); + mInvertYAxis = boolValue("InvertYAxis"); mObjectLabelVisibility = static_cast (intValue("ObjectLabelVisibility", AllObjectLabels)); mLabelForHoveredObject = boolValue("LabelForHoveredObject", false); @@ -683,6 +684,17 @@ void Preferences::setWheelZoomsByDefault(bool mode) mSettings->setValue(QLatin1String("Interface/WheelZoomsByDefault"), mode); } +void Preferences::setInvertYAxis(bool enabled) +{ + if(mInvertYAxis == enabled) + return; + + mInvertYAxis = enabled; + mSettings->setValue(QLatin1String("Interface/InvertYAxis"), enabled); + + emit invertYAxisChanged(); +} + bool Preferences::boolValue(const char *key, bool defaultValue) const { return mSettings->value(QLatin1String(key), defaultValue).toBool(); diff --git a/src/tiled/preferences.h b/src/tiled/preferences.h index 243825cf22..abf8663773 100644 --- a/src/tiled/preferences.h +++ b/src/tiled/preferences.h @@ -167,6 +167,8 @@ class Preferences : public QObject bool wheelZoomsByDefault() const; + bool invertYAxis() const; + /** * Provides access to the QSettings instance to allow storing/retrieving * arbitrary values. The naming style for groups and keys is CamelCase. @@ -190,6 +192,7 @@ public slots: void setOpenLastFilesOnStartup(bool load); void setPluginEnabled(const QString &fileName, bool enabled); void setWheelZoomsByDefault(bool mode); + void setInvertYAxis(bool enabled); void clearRecentFiles(); @@ -229,6 +232,8 @@ public slots: void checkForUpdatesChanged(); + void invertYAxisChanged(); + private: Preferences(); ~Preferences() override; @@ -282,6 +287,7 @@ public slots: bool mIsPatron; bool mCheckForUpdates; bool mWheelZoomsByDefault; + bool mInvertYAxis; static Preferences *mInstance; }; @@ -392,6 +398,11 @@ inline bool Preferences::wheelZoomsByDefault() const return mWheelZoomsByDefault; } +inline bool Preferences::invertYAxis() const +{ + return mInvertYAxis; +} + } // namespace Internal } // namespace Tiled diff --git a/src/tiled/preferencesdialog.cpp b/src/tiled/preferencesdialog.cpp index b9d6e99318..39b0b4654b 100644 --- a/src/tiled/preferencesdialog.cpp +++ b/src/tiled/preferencesdialog.cpp @@ -111,6 +111,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) preferences, &Preferences::setUseOpenGL); connect(mUi->wheelZoomsByDefault, &QCheckBox::toggled, preferences, &Preferences::setWheelZoomsByDefault); + connect(mUi->invertYAxis, &QCheckBox::toggled, + preferences, &Preferences::setInvertYAxis); connect(mUi->styleCombo, static_cast(&QComboBox::currentIndexChanged), this, &PreferencesDialog::styleComboChanged); @@ -170,6 +172,7 @@ void PreferencesDialog::fromPreferences() if (mUi->openGL->isEnabled()) mUi->openGL->setChecked(prefs->useOpenGL()); mUi->wheelZoomsByDefault->setChecked(prefs->wheelZoomsByDefault()); + mUi->invertYAxis->setChecked(prefs->invertYAxis()); // Not found (-1) ends up at index 0, system default int languageIndex = mUi->languageCombo->findData(prefs->language()); diff --git a/src/tiled/preferencesdialog.ui b/src/tiled/preferencesdialog.ui index db8194bc02..7dddb64e7f 100644 --- a/src/tiled/preferencesdialog.ui +++ b/src/tiled/preferencesdialog.ui @@ -225,6 +225,13 @@ + + + + Invert Y axis coordinates + + + @@ -441,6 +448,7 @@ objectLineWidth openGL wheelZoomsByDefault + invertYAxis styleCombo baseColor selectionColor From f045eec602a60a600b17a015f331c47ef4187304 Mon Sep 17 00:00:00 2001 From: AdrianFL Date: Sun, 2 Dec 2018 04:47:11 +0100 Subject: [PATCH 02/15] Added helper class to flip Y axis --- src/tiled/invertyaxishelper.h | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/tiled/invertyaxishelper.h diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h new file mode 100644 index 0000000000..e50ee16a78 --- /dev/null +++ b/src/tiled/invertyaxishelper.h @@ -0,0 +1,55 @@ +/* + * invertyaxishelper.h + * Copyright 2013, Thorbjørn Lindeijer + * Copyright 2018, Adrian Frances + * + * This file is part of Tiled. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +#include "preferences.h" +#include "mapdocumentactionhandler.h" + +class InvertYAxisHelper{ + public: + InvertYAxisHelper() {} + ~InvertYAxisHelper() {} + + // Inverts Y coordinate in grid + float getY(float y) const + { + // Check if Invert Y Axis is set + if(Tiled::Internal::Preferences::instance()->invertYAxis()) + { + return Tiled::Internal::MapDocumentActionHandler::instance()->mapDocument()->map()->height() - 1 - y; + } + return y; + } + + // Inverts Y coordinate in pixels + float getPixelY(float y) const + { + // Obtain the map document + auto map = Tiled::Internal::MapDocumentActionHandler::instance()->mapDocument()->map(); + if(Tiled::Internal::Preferences::instance()->invertYAxis()) + { + return ((map->height() + 1) * map->tileHeight()) - y; + } + return y; + } + +}; \ No newline at end of file From 7064dfae9d69e61d2f67bef633ddc82b6f187867 Mon Sep 17 00:00:00 2001 From: AdrianFL Date: Sun, 2 Dec 2018 04:48:37 +0100 Subject: [PATCH 03/15] Added functionality of the Y flip to the bottom context numbers --- src/tiled/abstractobjecttool.cpp | 3 ++- src/tiled/abstracttiletool.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tiled/abstractobjecttool.cpp b/src/tiled/abstractobjecttool.cpp index 13e12985bf..3f731ae2d0 100644 --- a/src/tiled/abstractobjecttool.cpp +++ b/src/tiled/abstractobjecttool.cpp @@ -37,6 +37,7 @@ #include "tile.h" #include "tmxmapformat.h" #include "utils.h" +#include "invertyaxishelper.h" #include #include @@ -160,7 +161,7 @@ void AbstractObjectTool::mouseMoved(const QPointF &pos, const QPointF tilePosF = mapDocument()->renderer()->screenToTileCoords(offsetPos); const int x = qFloor(tilePosF.x()); const int y = qFloor(tilePosF.y()); - setStatusInfo(QString(QLatin1String("%1, %2 (%3, %4)")).arg(x).arg(y).arg(pixelPos.x()).arg(pixelPos.y())); + setStatusInfo(QString(QLatin1String("%1, %2 (%3, %4)")).arg(x).arg(InvertYAxisHelper().getY(y)).arg(pixelPos.x()).arg(InvertYAxisHelper().getPixelY(pixelPos.y()))); } void AbstractObjectTool::mousePressed(QGraphicsSceneMouseEvent *event) diff --git a/src/tiled/abstracttiletool.cpp b/src/tiled/abstracttiletool.cpp index 0bf707fc14..97c9c13bc3 100644 --- a/src/tiled/abstracttiletool.cpp +++ b/src/tiled/abstracttiletool.cpp @@ -28,6 +28,7 @@ #include "tile.h" #include "tilelayer.h" #include "tilestamp.h" +#include "invertyaxishelper.h" #include @@ -146,7 +147,7 @@ void AbstractTileTool::updateStatusInfo() setStatusInfo(QString(QLatin1String("%1, %2 [%3]")) .arg(mTilePosition.x()) - .arg(mTilePosition.y()) + .arg(InvertYAxisHelper().getY(mTilePosition.y())) .arg(tileIdString)); } else { setStatusInfo(QString()); From 59ab00b7d7afa8217f936d9698c4fd477b8dc8f0 Mon Sep 17 00:00:00 2001 From: AdrianFL Date: Sun, 2 Dec 2018 04:49:06 +0100 Subject: [PATCH 04/15] Added the Y flip functionality to the object menu and object properties --- src/tiled/mapobjectmodel.cpp | 3 ++- src/tiled/propertybrowser.cpp | 14 ++++++++++++-- src/tiled/propertybrowser.h | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tiled/mapobjectmodel.cpp b/src/tiled/mapobjectmodel.cpp index 28de43936a..e7f75fa6a1 100644 --- a/src/tiled/mapobjectmodel.cpp +++ b/src/tiled/mapobjectmodel.cpp @@ -29,6 +29,7 @@ #include "mapdocument.h" #include "objectgroup.h" #include "renamelayer.h" +#include "invertyaxishelper.h" #include #include @@ -129,7 +130,7 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const return QLatin1Char('(') + QString::number(mapObject->x()) + QLatin1String(", ") - + QString::number(mapObject->y()) + + QString::number(InvertYAxisHelper().getPixelY(mapObject->y())) + QLatin1Char(')'); } break; diff --git a/src/tiled/propertybrowser.cpp b/src/tiled/propertybrowser.cpp index 9a3af39fda..dd292e3aca 100644 --- a/src/tiled/propertybrowser.cpp +++ b/src/tiled/propertybrowser.cpp @@ -62,6 +62,7 @@ #include "variantpropertymanager.h" #include "wangcolormodel.h" #include "wangset.h" +#include "invertyaxishelper.h" #include @@ -102,6 +103,9 @@ PropertyBrowser::PropertyBrowser(QWidget *parent) connect(Preferences::instance(), &Preferences::objectTypesChanged, this, &PropertyBrowser::objectTypesChanged); + + connect(Preferences::instance(), &Preferences::invertYAxisChanged, + this, &PropertyBrowser::invertYAxisChanged); } void PropertyBrowser::setObject(Object *object) @@ -323,6 +327,12 @@ void PropertyBrowser::wangSetChanged(Tileset *tileset, int index) updateProperties(); } +void PropertyBrowser::invertYAxisChanged() +{ + if(mObject && mObject->typeId() == Object::MapObjectType) + updateProperties(); +} + static QVariant predefinedPropertyValue(Object *object, const QString &name) { QString objectType; @@ -1020,7 +1030,7 @@ QUndoCommand *PropertyBrowser::applyMapObjectValueTo(PropertyId id, const QVaria } case YProperty: { const QPointF oldPos = mapObject->position(); - const QPointF newPos(oldPos.x(), val.toReal()); + const QPointF newPos(oldPos.x(), InvertYAxisHelper().getPixelY(val.toReal())); command = new MoveMapObject(mMapDocument, mapObject, newPos, oldPos); break; } @@ -1608,7 +1618,7 @@ void PropertyBrowser::updateProperties() if (auto visibleProperty = mIdToProperty[VisibleProperty]) visibleProperty->setValue(mapObject->isVisible()); mIdToProperty[XProperty]->setValue(mapObject->x()); - mIdToProperty[YProperty]->setValue(mapObject->y()); + mIdToProperty[YProperty]->setValue(InvertYAxisHelper().getPixelY(mapObject->y())); if (flags & ObjectHasDimensions) { mIdToProperty[WidthProperty]->setValue(mapObject->width()); diff --git a/src/tiled/propertybrowser.h b/src/tiled/propertybrowser.h index fd32ae3b7c..34b15b219b 100644 --- a/src/tiled/propertybrowser.h +++ b/src/tiled/propertybrowser.h @@ -101,6 +101,7 @@ private slots: void tileTypeChanged(Tile *tile); void terrainChanged(Tileset *tileset, int index); void wangSetChanged(Tileset *tileset, int index); + void invertYAxisChanged(); void propertyAdded(Object *object, const QString &name); void propertyRemoved(Object *object, const QString &name); From 59773db7cae673a8315d7ac993eca425e988e113 Mon Sep 17 00:00:00 2001 From: AdrianFL Date: Sun, 2 Dec 2018 13:53:55 +0100 Subject: [PATCH 05/15] Small changes for coding style and other feedback provided --- src/tiled/abstractobjecttool.cpp | 5 ++- src/tiled/abstracttiletool.cpp | 2 +- src/tiled/invertyaxishelper.h | 53 +++++++++++++++++++------------- src/tiled/mapobjectmodel.cpp | 2 +- src/tiled/propertybrowser.cpp | 6 ++-- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/tiled/abstractobjecttool.cpp b/src/tiled/abstractobjecttool.cpp index 3f731ae2d0..1cee482f16 100644 --- a/src/tiled/abstractobjecttool.cpp +++ b/src/tiled/abstractobjecttool.cpp @@ -161,7 +161,10 @@ void AbstractObjectTool::mouseMoved(const QPointF &pos, const QPointF tilePosF = mapDocument()->renderer()->screenToTileCoords(offsetPos); const int x = qFloor(tilePosF.x()); const int y = qFloor(tilePosF.y()); - setStatusInfo(QString(QLatin1String("%1, %2 (%3, %4)")).arg(x).arg(InvertYAxisHelper().getY(y)).arg(pixelPos.x()).arg(InvertYAxisHelper().getPixelY(pixelPos.y()))); + setStatusInfo(QString(QLatin1String("%1, %2 (%3, %4)")).arg(x) + .arg(InvertYAxisHelper().tileY(y)) + .arg(pixelPos.x()) + .arg(InvertYAxisHelper(MapDocumentActionHandler::instance()->mapDocument()->map()).pixelY(pixelPos.y()))); } void AbstractObjectTool::mousePressed(QGraphicsSceneMouseEvent *event) diff --git a/src/tiled/abstracttiletool.cpp b/src/tiled/abstracttiletool.cpp index 97c9c13bc3..42a572c348 100644 --- a/src/tiled/abstracttiletool.cpp +++ b/src/tiled/abstracttiletool.cpp @@ -147,7 +147,7 @@ void AbstractTileTool::updateStatusInfo() setStatusInfo(QString(QLatin1String("%1, %2 [%3]")) .arg(mTilePosition.x()) - .arg(InvertYAxisHelper().getY(mTilePosition.y())) + .arg(InvertYAxisHelper().tileY(mTilePosition.y())) .arg(tileIdString)); } else { setStatusInfo(QString()); diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h index e50ee16a78..64016d1793 100644 --- a/src/tiled/invertyaxishelper.h +++ b/src/tiled/invertyaxishelper.h @@ -24,32 +24,41 @@ #include "preferences.h" #include "mapdocumentactionhandler.h" -class InvertYAxisHelper{ - public: - InvertYAxisHelper() {} - ~InvertYAxisHelper() {} - - // Inverts Y coordinate in grid - float getY(float y) const +namespace Tiled{ + namespace Internal { + + class InvertYAxisHelper { - // Check if Invert Y Axis is set - if(Tiled::Internal::Preferences::instance()->invertYAxis()) + public: + // Constructors + InvertYAxisHelper() {} + InvertYAxisHelper(Map* m) : target(m) {} + + // Inverts Y coordinate in grid + qreal tileY(qreal y) const { - return Tiled::Internal::MapDocumentActionHandler::instance()->mapDocument()->map()->height() - 1 - y; + // Check if Invert Y Axis is set + if(Preferences::instance()->invertYAxis()) + { + return MapDocumentActionHandler::instance()->mapDocument()->map()->height() - 1 - y; + } + return y; } - return y; - } - // Inverts Y coordinate in pixels - float getPixelY(float y) const - { - // Obtain the map document - auto map = Tiled::Internal::MapDocumentActionHandler::instance()->mapDocument()->map(); - if(Tiled::Internal::Preferences::instance()->invertYAxis()) + // Inverts Y coordinate in pixels + qreal pixelY(qreal y) const { - return ((map->height() + 1) * map->tileHeight()) - y; + // Obtain the map document + if(Preferences::instance()->invertYAxis()) + { + return ((target->height() + 1) * target->tileHeight()) - y; + } + return y; } - return y; - } -}; \ No newline at end of file + private: + Map* target; + }; + + } // Namespace Internal +} // Namespace Tiled \ No newline at end of file diff --git a/src/tiled/mapobjectmodel.cpp b/src/tiled/mapobjectmodel.cpp index e7f75fa6a1..9883d327cb 100644 --- a/src/tiled/mapobjectmodel.cpp +++ b/src/tiled/mapobjectmodel.cpp @@ -130,7 +130,7 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const return QLatin1Char('(') + QString::number(mapObject->x()) + QLatin1String(", ") - + QString::number(InvertYAxisHelper().getPixelY(mapObject->y())) + + QString::number(InvertYAxisHelper().tileY(mapObject->y())) + QLatin1Char(')'); } break; diff --git a/src/tiled/propertybrowser.cpp b/src/tiled/propertybrowser.cpp index dd292e3aca..085b6aac20 100644 --- a/src/tiled/propertybrowser.cpp +++ b/src/tiled/propertybrowser.cpp @@ -329,7 +329,7 @@ void PropertyBrowser::wangSetChanged(Tileset *tileset, int index) void PropertyBrowser::invertYAxisChanged() { - if(mObject && mObject->typeId() == Object::MapObjectType) + if (mObject && mObject->typeId() == Object::MapObjectType) updateProperties(); } @@ -1030,7 +1030,7 @@ QUndoCommand *PropertyBrowser::applyMapObjectValueTo(PropertyId id, const QVaria } case YProperty: { const QPointF oldPos = mapObject->position(); - const QPointF newPos(oldPos.x(), InvertYAxisHelper().getPixelY(val.toReal())); + const QPointF newPos(oldPos.x(), InvertYAxisHelper(mMapDocument->map()).pixelY(val.toReal())); command = new MoveMapObject(mMapDocument, mapObject, newPos, oldPos); break; } @@ -1618,7 +1618,7 @@ void PropertyBrowser::updateProperties() if (auto visibleProperty = mIdToProperty[VisibleProperty]) visibleProperty->setValue(mapObject->isVisible()); mIdToProperty[XProperty]->setValue(mapObject->x()); - mIdToProperty[YProperty]->setValue(InvertYAxisHelper().getPixelY(mapObject->y())); + mIdToProperty[YProperty]->setValue(InvertYAxisHelper(MapDocumentActionHandler::instance()->mapDocument()->map()).pixelY(mapObject->y())); if (flags & ObjectHasDimensions) { mIdToProperty[WidthProperty]->setValue(mapObject->width()); From 09a183b22858e86730c5516bdedbf818ded70240 Mon Sep 17 00:00:00 2001 From: AdrianFL Date: Mon, 3 Dec 2018 22:52:41 +0100 Subject: [PATCH 06/15] Changed InvertYAxisHelper to use MapRenderer and other coding style fix --- src/tiled/abstractobjecttool.cpp | 4 +-- src/tiled/abstracttiletool.cpp | 2 +- src/tiled/invertyaxishelper.h | 62 ++++++++++++++++---------------- src/tiled/mapobjectmodel.cpp | 2 +- src/tiled/propertybrowser.cpp | 4 +-- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/tiled/abstractobjecttool.cpp b/src/tiled/abstractobjecttool.cpp index 1cee482f16..3fa4bbd35a 100644 --- a/src/tiled/abstractobjecttool.cpp +++ b/src/tiled/abstractobjecttool.cpp @@ -162,9 +162,9 @@ void AbstractObjectTool::mouseMoved(const QPointF &pos, const int x = qFloor(tilePosF.x()); const int y = qFloor(tilePosF.y()); setStatusInfo(QString(QLatin1String("%1, %2 (%3, %4)")).arg(x) - .arg(InvertYAxisHelper().tileY(y)) + .arg(InvertYAxisHelper(mapDocument()).tileY(y)) .arg(pixelPos.x()) - .arg(InvertYAxisHelper(MapDocumentActionHandler::instance()->mapDocument()->map()).pixelY(pixelPos.y()))); + .arg(InvertYAxisHelper(MapDocumentActionHandler::instance()->mapDocument()).pixelY(pixelPos.y()))); } void AbstractObjectTool::mousePressed(QGraphicsSceneMouseEvent *event) diff --git a/src/tiled/abstracttiletool.cpp b/src/tiled/abstracttiletool.cpp index 42a572c348..e80871e94d 100644 --- a/src/tiled/abstracttiletool.cpp +++ b/src/tiled/abstracttiletool.cpp @@ -147,7 +147,7 @@ void AbstractTileTool::updateStatusInfo() setStatusInfo(QString(QLatin1String("%1, %2 [%3]")) .arg(mTilePosition.x()) - .arg(InvertYAxisHelper().tileY(mTilePosition.y())) + .arg(InvertYAxisHelper(mapDocument()).tileY(mTilePosition.y())) .arg(tileIdString)); } else { setStatusInfo(QString()); diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h index 64016d1793..9ea438449b 100644 --- a/src/tiled/invertyaxishelper.h +++ b/src/tiled/invertyaxishelper.h @@ -23,42 +23,42 @@ #include "preferences.h" #include "mapdocumentactionhandler.h" +#include "maprenderer.h" -namespace Tiled{ - namespace Internal { +namespace Tiled { +namespace Internal { - class InvertYAxisHelper - { - public: - // Constructors - InvertYAxisHelper() {} - InvertYAxisHelper(Map* m) : target(m) {} + class InvertYAxisHelper + { + public: + // Constructors + InvertYAxisHelper(MapDocument *m) : mTarget(m) {} - // Inverts Y coordinate in grid - qreal tileY(qreal y) const - { - // Check if Invert Y Axis is set - if(Preferences::instance()->invertYAxis()) - { - return MapDocumentActionHandler::instance()->mapDocument()->map()->height() - 1 - y; - } - return y; + // Inverts Y coordinate in grid + int tileY(int y) const + { + // Check if Invert Y Axis is set + if (Preferences::instance()->invertYAxis()) { + const MapRenderer *renderer = mTarget->renderer(); + return renderer->map()->height() - 1 - y; } + return y; + } - // Inverts Y coordinate in pixels - qreal pixelY(qreal y) const - { - // Obtain the map document - if(Preferences::instance()->invertYAxis()) - { - return ((target->height() + 1) * target->tileHeight()) - y; - } - return y; + // Inverts Y coordinate in pixels + qreal pixelY(qreal y) const + { + // Obtain the map document + if (Preferences::instance()->invertYAxis()) { + const MapRenderer *renderer = mTarget->renderer(); + return (renderer->map()->height() * renderer->map()->tileHeight())- y; } + return y; + } - private: - Map* target; - }; + private: + MapDocument *mTarget; + }; - } // Namespace Internal -} // Namespace Tiled \ No newline at end of file +} // Namespace Internal +} // Namespace Tiled diff --git a/src/tiled/mapobjectmodel.cpp b/src/tiled/mapobjectmodel.cpp index 9883d327cb..5611caa02d 100644 --- a/src/tiled/mapobjectmodel.cpp +++ b/src/tiled/mapobjectmodel.cpp @@ -130,7 +130,7 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const return QLatin1Char('(') + QString::number(mapObject->x()) + QLatin1String(", ") - + QString::number(InvertYAxisHelper().tileY(mapObject->y())) + + QString::number(InvertYAxisHelper(mapDocument()).tileY(mapObject->y())) + QLatin1Char(')'); } break; diff --git a/src/tiled/propertybrowser.cpp b/src/tiled/propertybrowser.cpp index 085b6aac20..e6fc4e159f 100644 --- a/src/tiled/propertybrowser.cpp +++ b/src/tiled/propertybrowser.cpp @@ -1030,7 +1030,7 @@ QUndoCommand *PropertyBrowser::applyMapObjectValueTo(PropertyId id, const QVaria } case YProperty: { const QPointF oldPos = mapObject->position(); - const QPointF newPos(oldPos.x(), InvertYAxisHelper(mMapDocument->map()).pixelY(val.toReal())); + const QPointF newPos(oldPos.x(), InvertYAxisHelper(mMapDocument).pixelY(val.toReal())); command = new MoveMapObject(mMapDocument, mapObject, newPos, oldPos); break; } @@ -1618,7 +1618,7 @@ void PropertyBrowser::updateProperties() if (auto visibleProperty = mIdToProperty[VisibleProperty]) visibleProperty->setValue(mapObject->isVisible()); mIdToProperty[XProperty]->setValue(mapObject->x()); - mIdToProperty[YProperty]->setValue(InvertYAxisHelper(MapDocumentActionHandler::instance()->mapDocument()->map()).pixelY(mapObject->y())); + mIdToProperty[YProperty]->setValue(InvertYAxisHelper(mMapDocument).pixelY(mapObject->y())); if (flags & ObjectHasDimensions) { mIdToProperty[WidthProperty]->setValue(mapObject->width()); From 7d8d924cd43363ee04cb9388e99baaaa85ddfab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 3 Dec 2018 23:23:52 +0100 Subject: [PATCH 07/15] Update src/tiled/abstractobjecttool.cpp Co-Authored-By: AdrianFL --- src/tiled/abstractobjecttool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiled/abstractobjecttool.cpp b/src/tiled/abstractobjecttool.cpp index 3fa4bbd35a..1f88186b30 100644 --- a/src/tiled/abstractobjecttool.cpp +++ b/src/tiled/abstractobjecttool.cpp @@ -164,7 +164,7 @@ void AbstractObjectTool::mouseMoved(const QPointF &pos, setStatusInfo(QString(QLatin1String("%1, %2 (%3, %4)")).arg(x) .arg(InvertYAxisHelper(mapDocument()).tileY(y)) .arg(pixelPos.x()) - .arg(InvertYAxisHelper(MapDocumentActionHandler::instance()->mapDocument()).pixelY(pixelPos.y()))); + .arg(InvertYAxisHelper(mapDocument()).pixelY(pixelPos.y()))); } void AbstractObjectTool::mousePressed(QGraphicsSceneMouseEvent *event) From 8cd919f0b42d50f929089078fd559e48ac6081f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 3 Dec 2018 23:24:51 +0100 Subject: [PATCH 08/15] Update src/tiled/invertyaxishelper.h Co-Authored-By: AdrianFL --- src/tiled/invertyaxishelper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h index 9ea438449b..b38f30f6b7 100644 --- a/src/tiled/invertyaxishelper.h +++ b/src/tiled/invertyaxishelper.h @@ -40,7 +40,7 @@ namespace Internal { // Check if Invert Y Axis is set if (Preferences::instance()->invertYAxis()) { const MapRenderer *renderer = mTarget->renderer(); - return renderer->map()->height() - 1 - y; + return mTarget->map()->height() - 1 - y; } return y; } From 7f1dbecb9f7c23e9cd634c387f514c58b4cd8a81 Mon Sep 17 00:00:00 2001 From: AdrianFL Date: Tue, 4 Dec 2018 00:03:56 +0100 Subject: [PATCH 09/15] Using MapRenderer to obtain size --- src/tiled/invertyaxishelper.h | 51 +++++++++++++++++------------------ src/tiled/preferences.cpp | 2 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h index b38f30f6b7..c28d37ec63 100644 --- a/src/tiled/invertyaxishelper.h +++ b/src/tiled/invertyaxishelper.h @@ -28,37 +28,36 @@ namespace Tiled { namespace Internal { - class InvertYAxisHelper - { - public: - // Constructors - InvertYAxisHelper(MapDocument *m) : mTarget(m) {} +class InvertYAxisHelper +{ +public: + InvertYAxisHelper(MapDocument *m) : mTarget(m) {} - // Inverts Y coordinate in grid - int tileY(int y) const - { - // Check if Invert Y Axis is set - if (Preferences::instance()->invertYAxis()) { - const MapRenderer *renderer = mTarget->renderer(); - return mTarget->map()->height() - 1 - y; - } - return y; + // Inverts Y coordinate in grid + int tileY(int y) const + { + // Check if Invert Y Axis is set + if (Preferences::instance()->invertYAxis()) { + return mTarget->map()->height() - 1 - y; } + return y; + } - // Inverts Y coordinate in pixels - qreal pixelY(qreal y) const - { - // Obtain the map document - if (Preferences::instance()->invertYAxis()) { - const MapRenderer *renderer = mTarget->renderer(); - return (renderer->map()->height() * renderer->map()->tileHeight())- y; - } - return y; + // Inverts Y coordinate in pixels + qreal pixelY(qreal y) const + { + // Obtain the map document + if (Preferences::instance()->invertYAxis()) { + const MapRenderer *renderer = mTarget->renderer(); + QRect boundingRect = renderer->boundingRect(QRect(QPoint(), mTarget->map()->size())); + return boundingRect.height() - y; } + return y; + } - private: - MapDocument *mTarget; - }; +private: + MapDocument *mTarget; +}; } // Namespace Internal } // Namespace Tiled diff --git a/src/tiled/preferences.cpp b/src/tiled/preferences.cpp index 0f02aca3a7..e1d5e81758 100644 --- a/src/tiled/preferences.cpp +++ b/src/tiled/preferences.cpp @@ -686,7 +686,7 @@ void Preferences::setWheelZoomsByDefault(bool mode) void Preferences::setInvertYAxis(bool enabled) { - if(mInvertYAxis == enabled) + if (mInvertYAxis == enabled) return; mInvertYAxis = enabled; From 02849580c9270aab72dde28f51549e3da5c4a5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 27 Dec 2018 23:16:20 +0100 Subject: [PATCH 10/15] Some formatting adjustments Mostly just personal preference. --- src/tiled/invertyaxishelper.h | 58 ++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h index c28d37ec63..c8a8002469 100644 --- a/src/tiled/invertyaxishelper.h +++ b/src/tiled/invertyaxishelper.h @@ -21,9 +21,9 @@ #pragma once -#include "preferences.h" -#include "mapdocumentactionhandler.h" +#include "mapdocument.h" #include "maprenderer.h" +#include "preferences.h" namespace Tiled { namespace Internal { @@ -31,33 +31,41 @@ namespace Internal { class InvertYAxisHelper { public: - InvertYAxisHelper(MapDocument *m) : mTarget(m) {} + InvertYAxisHelper(MapDocument *mapDocument) + : mMapDocument(mapDocument) + {} - // Inverts Y coordinate in grid - int tileY(int y) const - { - // Check if Invert Y Axis is set - if (Preferences::instance()->invertYAxis()) { - return mTarget->map()->height() - 1 - y; - } - return y; - } - - // Inverts Y coordinate in pixels - qreal pixelY(qreal y) const - { - // Obtain the map document - if (Preferences::instance()->invertYAxis()) { - const MapRenderer *renderer = mTarget->renderer(); - QRect boundingRect = renderer->boundingRect(QRect(QPoint(), mTarget->map()->size())); - return boundingRect.height() - y; - } - return y; - } + int tileY(int y) const; + qreal pixelY(qreal y) const; private: - MapDocument *mTarget; + MapDocument *mMapDocument; }; +/** + * Inverts Y coordinate in tiles when applicable. + */ +inline int InvertYAxisHelper::tileY(int y) const +{ + // Check if Invert Y Axis is set + if (Preferences::instance()->invertYAxis()) + return mMapDocument->map()->height() - 1 - y; + return y; +} + +/** + * Inverts Y coordinate in pixels when applicable. + */ +inline qreal InvertYAxisHelper::pixelY(qreal y) const +{ + // Obtain the map document + if (Preferences::instance()->invertYAxis()) { + const MapRenderer *renderer = mMapDocument->renderer(); + QRect boundingRect = renderer->boundingRect(QRect(QPoint(), mMapDocument->map()->size())); + return boundingRect.height() - y; + } + return y; +} + } // Namespace Internal } // Namespace Tiled From ca94a395d198204673dc35b8a882b85dedb2e7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 27 Dec 2018 23:18:10 +0100 Subject: [PATCH 11/15] Removed "Internal" namespace No longer using this namespace (71c1de5dc2c6f98c8d54105492dad0a32b73f811). --- src/tiled/invertyaxishelper.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h index c8a8002469..4fd5fab58b 100644 --- a/src/tiled/invertyaxishelper.h +++ b/src/tiled/invertyaxishelper.h @@ -26,7 +26,6 @@ #include "preferences.h" namespace Tiled { -namespace Internal { class InvertYAxisHelper { @@ -67,5 +66,4 @@ inline qreal InvertYAxisHelper::pixelY(qreal y) const return y; } -} // Namespace Internal } // Namespace Tiled From f557fed9e9f2d7edf7a5394c855330ad887b89d4 Mon Sep 17 00:00:00 2001 From: Jonathan <1808569+jonatino@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:31:36 -0500 Subject: [PATCH 12/15] Update propertybrowser.cpp --- src/tiled/propertybrowser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tiled/propertybrowser.cpp b/src/tiled/propertybrowser.cpp index 17a53126fb..511a33eee1 100644 --- a/src/tiled/propertybrowser.cpp +++ b/src/tiled/propertybrowser.cpp @@ -57,7 +57,6 @@ #include "wangcolormodel.h" #include "wangoverlay.h" #include "wangset.h" -#include "invertyaxishelper.h" #include @@ -1898,7 +1897,7 @@ void PropertyBrowser::updateProperties() if (auto visibleProperty = mIdToProperty[VisibleProperty]) visibleProperty->setValue(mapObject->isVisible()); mIdToProperty[XProperty]->setValue(mapObject->x()); - mIdToProperty[YProperty]->setValue(InvertYAxisHelper(mMapDocument).pixelY(mapObject->y())); + mIdToProperty[YProperty]->setValue(mapObject->y()); if (flags & ObjectHasDimensions) { mIdToProperty[WidthProperty]->setValue(mapObject->width()); From c23c1d22a5e8ca4a70f265908a390012928d0be3 Mon Sep 17 00:00:00 2001 From: Jonathan <1808569+jonatino@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:32:19 -0500 Subject: [PATCH 13/15] Update preferences.h --- src/tiled/preferences.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/tiled/preferences.h b/src/tiled/preferences.h index 189dea5255..d28950d804 100644 --- a/src/tiled/preferences.h +++ b/src/tiled/preferences.h @@ -207,7 +207,6 @@ public slots: void setRestoreSessionOnStartup(bool enabled); void setPluginEnabled(const QString &fileName, bool enabled); void setWheelZoomsByDefault(bool mode); - void setInvertYAxis(bool enabled); void clearRecentFiles(); void clearRecentProjects(); @@ -254,8 +253,6 @@ public slots: void aboutToSwitchSession(); - void invertYAxisChanged(); - private: void addToRecentFileList(const QString &fileName, QStringList &files); @@ -301,11 +298,6 @@ void Preference::set(const T &value) Preferences::instance()->setValue(QLatin1String(mKey), value); } -inline bool Preferences::invertYAxis() const -{ - return mInvertYAxis; -} - } // namespace Tiled Q_DECLARE_OPERATORS_FOR_FLAGS(Tiled::Preferences::ExportOptions) From 5a425457639fd542eeb4116806b8959ca40ffafe Mon Sep 17 00:00:00 2001 From: Jonathan <1808569+jonatino@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:32:47 -0500 Subject: [PATCH 14/15] Update mapobjectmodel.cpp --- src/tiled/mapobjectmodel.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tiled/mapobjectmodel.cpp b/src/tiled/mapobjectmodel.cpp index 75ab6d8697..26a644d403 100644 --- a/src/tiled/mapobjectmodel.cpp +++ b/src/tiled/mapobjectmodel.cpp @@ -30,7 +30,6 @@ #include "map.h" #include "mapdocument.h" #include "objectgroup.h" -#include "invertyaxishelper.h" #include #include @@ -173,7 +172,7 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const return QLatin1Char('(') + QString::number(mapObject->x()) + QLatin1String(", ") - + QString::number(InvertYAxisHelper(mapDocument()).tileY(mapObject->y())) + + QString::number(mapObject->y()) + QLatin1Char(')'); } break; From 0344536313f6868d5aa258a1ca7493c44d7bce0c Mon Sep 17 00:00:00 2001 From: Jonathan <1808569+jonatino@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:33:45 -0500 Subject: [PATCH 15/15] Always invert status bar --- src/tiled/invertyaxishelper.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tiled/invertyaxishelper.h b/src/tiled/invertyaxishelper.h index 4fd5fab58b..cc2baae868 100644 --- a/src/tiled/invertyaxishelper.h +++ b/src/tiled/invertyaxishelper.h @@ -23,7 +23,6 @@ #include "mapdocument.h" #include "maprenderer.h" -#include "preferences.h" namespace Tiled { @@ -47,7 +46,7 @@ class InvertYAxisHelper inline int InvertYAxisHelper::tileY(int y) const { // Check if Invert Y Axis is set - if (Preferences::instance()->invertYAxis()) + if (true) return mMapDocument->map()->height() - 1 - y; return y; } @@ -58,7 +57,7 @@ inline int InvertYAxisHelper::tileY(int y) const inline qreal InvertYAxisHelper::pixelY(qreal y) const { // Obtain the map document - if (Preferences::instance()->invertYAxis()) { + if (true) { const MapRenderer *renderer = mMapDocument->renderer(); QRect boundingRect = renderer->boundingRect(QRect(QPoint(), mMapDocument->map()->size())); return boundingRect.height() - y;