Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with latest #4127

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/tiled/abstractobjecttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "tile.h"
#include "tmxmapformat.h"
#include "utils.h"
#include "invertyaxishelper.h"

#include <QFileDialog>
#include <QGraphicsView>
Expand Down Expand Up @@ -186,7 +187,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(QStringLiteral("%1, %2 (%3, %4)").arg(x).arg(y).arg(pixelPos.x()).arg(pixelPos.y()));
setStatusInfo(QStringLiteral("%1, %2 (%3, %4)").arg(x)
.arg(InvertYAxisHelper(mapDocument()).tileY(y))
.arg(pixelPos.x())
.arg(InvertYAxisHelper(mapDocument()).pixelY(pixelPos.y())));
}

void AbstractObjectTool::mousePressed(QGraphicsSceneMouseEvent *event)
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/abstracttiletool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mapscene.h"
#include "tilelayer.h"
#include "tilestamp.h"
#include "invertyaxishelper.h"

#include <QKeyEvent>
#include <QtMath>
Expand Down Expand Up @@ -196,7 +197,7 @@ void AbstractTileTool::updateStatusInfo()

setStatusInfo(QStringLiteral("%1, %2 [%3]")
.arg(mTilePosition.x())
.arg(mTilePosition.y())
.arg(InvertYAxisHelper(mapDocument()).tileY(mTilePosition.y()))
.arg(tileIdString));
} else {
setStatusInfo(QString());
Expand Down
68 changes: 68 additions & 0 deletions src/tiled/invertyaxishelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* invertyaxishelper.h
* Copyright 2013, Thorbjørn Lindeijer <[email protected]>
* Copyright 2018, Adrian Frances <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "mapdocument.h"
#include "maprenderer.h"

namespace Tiled {

class InvertYAxisHelper
{
public:
InvertYAxisHelper(MapDocument *mapDocument)
: mMapDocument(mapDocument)
{}

int tileY(int y) const;
qreal pixelY(qreal y) const;

private:
MapDocument *mMapDocument;
};

/**
* Inverts Y coordinate in tiles when applicable.
*/
inline int InvertYAxisHelper::tileY(int y) const
{
// Check if Invert Y Axis is set
if (true)
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 (true) {
const MapRenderer *renderer = mMapDocument->renderer();
QRect boundingRect = renderer->boundingRect(QRect(QPoint(), mMapDocument->map()->size()));
return boundingRect.height() - y;
}
return y;
}

} // Namespace Tiled
Loading