Skip to content

Commit

Permalink
Fixed map positioning issues in the World Tool
Browse files Browse the repository at this point in the history
* Fixed an off-by-one error when adding the current map to a loaded world.
  The map was placed one pixel too much to the right.

* Fixed grid snapping when dragging a map to snap the target position
  rather than the offset. Also added handling of Control modifier to
  disable the grid snapping.

Closes #2970

(cherry picked from commit 8693dce)
  • Loading branch information
bjorn committed Jan 13, 2021
1 parent 70d5b3e commit 59ba1ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/tiled/abstractworldtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void AbstractWorldTool::addToWorld(const World *world)
// Position the map alongside the last map by default
if (!world->maps.isEmpty()) {
const QRect &lastWorldRect = world->maps.last().rect;
rect.moveTo(lastWorldRect.topRight());
rect.moveTo(lastWorldRect.right() + 1, lastWorldRect.top());
}

QUndoStack *undoStack = DocumentManager::instance()->ensureWorldDocument(world->fileName)->undoStack();
Expand Down
13 changes: 8 additions & 5 deletions src/tiled/worldmovemaptool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,19 @@ void WorldMoveMapTool::mouseMoved(const QPointF &pos,
}

// calculate new drag offset
const MapRenderer *renderer = mDraggingMap->renderer();
const QPoint newOffset = renderer->screenToPixelCoords(pos - mDragStartScenePos).toPoint();
mDragOffset = renderer->pixelToScreenCoords(snapPoint(newOffset, mDraggingMap)).toPoint();
const QRect currentMapRect = mapRect(mDraggingMap);
const QPoint offset = (pos - mDragStartScenePos).toPoint();

QPoint newPos = currentMapRect.topLeft() + offset;
if (!(modifiers & Qt::ControlModifier))
newPos = snapPoint(newPos, mDraggingMap);

mDragOffset = newPos - currentMapRect.topLeft();

// update preview
mDraggingMapItem->setPos(mDraggedMapStartPos + mDragOffset);
updateSelectionRectangle();

auto newPos = mapRect(mDraggingMap).topLeft() + mDragOffset;

setStatusInfo(tr("Move map to %1, %2 (offset: %3, %4)")
.arg(newPos.x())
.arg(newPos.y())
Expand Down

0 comments on commit 59ba1ba

Please sign in to comment.