From eea0c54a362c07339384eb607f54a7784349ec61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 8 Jun 2023 12:21:23 +0200 Subject: [PATCH] Fix pastes not being centred on the cursor This commit hopefully concludes hammering at old pasting code. --- src/gui/game/GameView.cpp | 26 +++++++++++++------------- src/gui/game/GameView.h | 3 --- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index d4f732578..7b28ec375 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -214,9 +214,7 @@ GameView::GameView(): selectPoint1(0, 0), selectPoint2(0, 0), currentMouse(0, 0), - mousePosition(0, 0), - placeSaveThumb(nullptr), - placeSaveOffset(0, 0) + mousePosition(0, 0) { int currentX = 1; @@ -1181,7 +1179,16 @@ void GameView::OnMouseDown(int x, int y, unsigned button) Vec2 GameView::PlaceSavePos() const { - return c->NormaliseBlockCoord(selectPoint2 + placeSaveOffset * CELL + Vec2(1, 1) * CELL / 2); + auto [ trQuoX, trRemX ] = floorDiv(placeSaveTranslate.X, CELL); + auto [ trQuoY, trRemY ] = floorDiv(placeSaveTranslate.Y, CELL); + auto usefulSize = placeSaveThumb->Size(); + if (trRemX) usefulSize.X -= CELL; + if (trRemY) usefulSize.Y -= CELL; + auto cursorCell = (usefulSize - Vec2{ CELL, CELL }) / 2 - Vec2{ trQuoX, trQuoY } * CELL; // stamp coordinates + auto unaligned = selectPoint2 - cursorCell; + auto quoX = floorDiv(unaligned.X, CELL).first; + auto quoY = floorDiv(unaligned.Y, CELL).first; + return { quoX, quoY }; } void GameView::OnMouseUp(int x, int y, unsigned button) @@ -1204,7 +1211,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button) { if (placeSaveThumb && y <= WINDOWH-BARSIZE) { - c->PlaceSave(PlaceSavePos() / CELL); + c->PlaceSave(PlaceSavePos()); } } else @@ -1942,13 +1949,6 @@ void GameView::NotifyTransformedPlaceSaveChanged(GameModel *sender) if (sender->GetTransformedPlaceSave()) { placeSaveThumb = SaveRenderer::Ref().Render(sender->GetTransformedPlaceSave(), true, true, sender->GetRenderer()); - auto [ quoX, remX ] = floorDiv(placeSaveTranslate.X, CELL); - auto [ quoY, remY ] = floorDiv(placeSaveTranslate.Y, CELL); - placeSaveOffset = Vec2{ quoX, quoY }; - auto usefulSize = placeSaveThumb->Size() / CELL; - if (remX) usefulSize.X -= 1; - if (remY) usefulSize.Y -= 1; - placeSaveOffset -= usefulSize / 2; selectMode = PlaceSave; selectPoint2 = mousePosition; } @@ -2164,7 +2164,7 @@ void GameView::OnDraw() { if(placeSaveThumb && selectPoint2.X!=-1) { - auto rect = RectSized(PlaceSavePos(), placeSaveThumb->Size()); + auto rect = RectSized(PlaceSavePos() * CELL, 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 c928b4f00..cfe6462ff 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -118,7 +118,6 @@ private: ui::Point mousePosition; std::unique_ptr placeSaveThumb; - ui::Point placeSaveOffset; Mat2 placeSaveTransform = Mat2::Identity; Vec2 placeSaveTranslate = Vec2::Zero; void TranslateSave(Vec2 addToTranslate); @@ -163,8 +162,6 @@ public: bool AltBehaviour(){ return altBehaviour; } SelectMode GetSelectMode() { return selectMode; } void BeginStampSelection(); - ui::Point GetPlaceSaveOffset() { return placeSaveOffset; } - void SetPlaceSaveOffset(ui::Point offset) { placeSaveOffset = offset; } ByteString TakeScreenshot(int captureUI, int fileType); int Record(bool record);