From c0a2370c7771157a20571f8d6b4b9328b728c483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sun, 14 May 2023 20:44:13 +0200 Subject: [PATCH] Fix paste previews being positioned incorrectly Recent changes made to multiple instances of paste placement code caused inconsistencies between what paste previews suggested would happen and what actually happened during pasting. Relevant code factored out. --- src/gui/game/GameView.cpp | 11 +++++++---- src/gui/game/GameView.h | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index cf6792aec..189d322a1 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1179,6 +1179,11 @@ void GameView::OnMouseDown(int x, int y, unsigned button) } } +Vec2 GameView::PlaceSavePos() const +{ + return c->NormaliseBlockCoord(selectPoint2 + placeSaveOffset * CELL + Vec2(1, 1) * CELL / 2).Clamp(RectBetween(Vec2::Zero, RES - placeSaveThumb->Size())); +} + void GameView::OnMouseUp(int x, int y, unsigned button) { currentMouse = ui::Point(x, y); @@ -1199,7 +1204,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button) { if (placeSaveThumb && y <= WINDOWH-BARSIZE) { - c->PlaceSave((selectPoint2 / CELL + placeSaveOffset).Clamp((CELLS - placeSaveThumb->Size() / CELL).OriginRect())); + c->PlaceSave(PlaceSavePos() / CELL); } } else @@ -2172,9 +2177,7 @@ void GameView::OnDraw() { if(placeSaveThumb && selectPoint2.X!=-1) { - auto thumb = selectPoint2 + placeSaveOffset * CELL + Vec2(1, 1) * CELL / 2; - thumb = c->NormaliseBlockCoord(thumb).Clamp(RectBetween(Vec2::Zero, RES - placeSaveThumb->Size())); - auto rect = RectSized(thumb, placeSaveThumb->Size()); + auto rect = RectSized(PlaceSavePos(), placeSaveThumb->Size()); ren->BlendImage(placeSaveThumb->Data(), 0x80, rect); ren->XorDottedRect(rect); } diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 311a2cff1..c928b4f00 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -139,6 +139,9 @@ private: void disableAltBehaviour(); void UpdateDrawMode(); void UpdateToolStrength(); + + Vec2 PlaceSavePos() const; + public: GameView(); virtual ~GameView();